Skip to content

Commit

Permalink
Merge branch 'refactor/esp_ringbuf_linux' into 'master'
Browse files Browse the repository at this point in the history
refactor(esp_ringbuf): Adjusted unit tests so some of them run on Linux

Closes IDF-9369

See merge request espressif/esp-idf!32683
  • Loading branch information
0xjakob committed Aug 15, 2024
2 parents 73ac0bc + dfbed83 commit deb18eb
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 231 deletions.
6 changes: 1 addition & 5 deletions components/esp_ringbuf/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

components/esp_ringbuf/test_apps:
enable:
- if: IDF_TARGET in ["esp32", "esp32c3", "esp32s2"]
- if: IDF_TARGET in ["esp32", "esp32c3", "esp32s2", "linux"]
reason: covers all target types
disable_test:
- if: IDF_TARGET in ["esp32s2"]
temporary: true
reason: the other targets are not tested yet
depends_components:
- freertos
- esp_ringbuf
4 changes: 2 additions & 2 deletions components/esp_ringbuf/test_apps/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 |
| ----------------- | ----- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 | Linux |
| ----------------- | ----- | -------- | -------- | ----- |

13 changes: 11 additions & 2 deletions components/esp_ringbuf/test_apps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
idf_build_get_property(target IDF_TARGET)

set(srcs "test_ringbuf_main.c"
"test_ringbuf.c")
"test_ringbuf_common.c")

set(priv_requires esp_ringbuf spi_flash unity)

if(NOT ${target} STREQUAL "linux")
list(APPEND srcs "test_ringbuf_target.c")
list(APPEND priv_requires esp_driver_gptimer)
endif()

idf_component_register(SRCS ${srcs}
PRIV_REQUIRES esp_ringbuf esp_driver_gptimer spi_flash unity
PRIV_REQUIRES ${priv_requires}
WHOLE_ARCHIVE)
53 changes: 53 additions & 0 deletions components/esp_ringbuf/test_apps/main/test_functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "freertos/ringbuf.h"

//Definitions used in multiple test cases
#define NO_OF_RB_TYPES 3
#define SMALL_ITEM_SIZE 8
#define ITEM_HDR_SIZE (sizeof(size_t) + sizeof(UBaseType_t))
#define MEDIUM_ITEM_SIZE ((3 * SMALL_ITEM_SIZE) >> 1) //12 bytes
#define BUFFER_SIZE 4 * (ITEM_HDR_SIZE + MEDIUM_ITEM_SIZE) //4Byte aligned size

#define CONT_DATA_LEN continuous_test_string_len()
//32-bit aligned size that guarantees a wrap around at some point
#define CONT_DATA_TEST_BUFF_LEN (((CONT_DATA_LEN/2) + 0x03) & ~0x3)

typedef struct {
RingbufHandle_t buffer;
RingbufferType_t type;
} task_args_t;

extern const uint8_t small_item[SMALL_ITEM_SIZE];
extern RingbufHandle_t buffer_handles[NO_OF_RB_TYPES];
extern SemaphoreHandle_t done_sem;

extern SemaphoreHandle_t tasks_done;
extern SemaphoreHandle_t tx_done;
extern SemaphoreHandle_t rx_done;

void setup(void);

void cleanup(void);

void read_from_buffer(RingbufHandle_t buffer, RingbufferType_t buf_type, size_t max_rec_size);

void send_to_buffer(RingbufHandle_t buffer, size_t max_item_size);

void send_item_and_check(RingbufHandle_t handle, const uint8_t *item, size_t item_size, TickType_t ticks_to_wait, bool in_isr);

void receive_check_and_return_item_no_split(RingbufHandle_t handle, const uint8_t *expected_data, size_t expected_size, TickType_t ticks_to_wait, bool in_isr);

void receive_check_and_return_item_allow_split(RingbufHandle_t handle, const uint8_t *expected_data, size_t expected_size, TickType_t ticks_to_wait, bool in_isr);

void receive_check_and_return_item_byte_buffer(RingbufHandle_t handle, const uint8_t *expected_data, size_t expected_size, TickType_t ticks_to_wait, bool in_isr);

void send_task(void *args);

void rec_task(void *args);

size_t continuous_test_string_len(void);
Loading

0 comments on commit deb18eb

Please sign in to comment.