diff --git a/components/driver/test/CMakeLists.txt b/components/driver/test/CMakeLists.txt index 03120a8e9c..913dca86a1 100644 --- a/components/driver/test/CMakeLists.txt +++ b/components/driver/test/CMakeLists.txt @@ -1,7 +1,8 @@ -idf_component_register(SRC_DIRS . param_test - PRIV_INCLUDE_DIRS include param_test/include - PRIV_REQUIRES cmock test_utils driver nvs_flash - esp_timer esp_adc esp_event esp_wifi spi_flash) +idf_component_register( + SRC_DIRS . + PRIV_INCLUDE_DIRS include + PRIV_REQUIRES cmock test_utils test_driver_utils driver nvs_flash spi_flash esp_timer esp_adc esp_event esp_wifi +) target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") # A local copy of idf-extra-components esp_serial_slave_link, for stabilities of the SDIO test diff --git a/components/driver/test_apps/components/test_driver_utils/CMakeLists.txt b/components/driver/test_apps/components/test_driver_utils/CMakeLists.txt new file mode 100644 index 0000000000..8d35576ec5 --- /dev/null +++ b/components/driver/test_apps/components/test_driver_utils/CMakeLists.txt @@ -0,0 +1,5 @@ +idf_component_register( + SRCS test_spi_utils.c param_test.c + INCLUDE_DIRS include + REQUIRES driver unity + ) diff --git a/components/driver/test/param_test/include/param_test.h b/components/driver/test_apps/components/test_driver_utils/include/param_test.h similarity index 98% rename from components/driver/test/param_test/include/param_test.h rename to components/driver/test_apps/components/test_driver_utils/include/param_test.h index 932a359563..e1dfcf9186 100644 --- a/components/driver/test/param_test/include/param_test.h +++ b/components/driver/test_apps/components/test_driver_utils/include/param_test.h @@ -1,8 +1,9 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ + /* * Parameterized Test Framework * diff --git a/components/driver/test/include/test/test_common_spi.h b/components/driver/test_apps/components/test_driver_utils/include/test_spi_utils.h similarity index 98% rename from components/driver/test/include/test/test_common_spi.h rename to components/driver/test_apps/components/test_driver_utils/include/test_spi_utils.h index db333c4c07..27b743bee9 100644 --- a/components/driver/test/include/test/test_common_spi.h +++ b/components/driver/test_apps/components/test_driver_utils/include/test_spi_utils.h @@ -7,17 +7,21 @@ #define _TEST_COMMON_SPI_H_ #include -#include "driver/spi_master.h" +#include +#include +#include +#include #include "freertos/FreeRTOS.h" #include "freertos/ringbuf.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" #include "freertos/task.h" #include "unity.h" -#include "test_utils.h" -#include #include "param_test.h" #include "soc/io_mux_reg.h" #include "sdkconfig.h" #include "soc/spi_periph.h" +#include "driver/spi_master.h" // All the tests using the header should use this definition as much as possible, // so that the working host can be changed easily in the future. @@ -249,7 +253,7 @@ typedef struct { void spitest_def_param(void* arg); // functions for slave task -esp_err_t init_slave_context(spi_slave_task_context_t *context); +esp_err_t init_slave_context(spi_slave_task_context_t *context, spi_host_device_t host); void deinit_slave_context(spi_slave_task_context_t *context); void spitest_slave_task(void* arg); diff --git a/components/driver/test/param_test/param_test.c b/components/driver/test_apps/components/test_driver_utils/param_test.c similarity index 86% rename from components/driver/test/param_test/param_test.c rename to components/driver/test_apps/components/test_driver_utils/param_test.c index 5880dc106d..d5f80cdeed 100644 --- a/components/driver/test/param_test/param_test.c +++ b/components/driver/test_apps/components/test_driver_utils/param_test.c @@ -1,12 +1,12 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include "param_test.h" + #include "esp_log.h" +#include "unity.h" +#include "param_test.h" void test_serializer(const param_group_t *param_group, const ptest_func_t* test_func) { diff --git a/components/driver/test/test_common_spi.c b/components/driver/test_apps/components/test_driver_utils/test_spi_utils.c similarity index 96% rename from components/driver/test/test_common_spi.c rename to components/driver/test_apps/components/test_driver_utils/test_spi_utils.c index 69ebc733c8..56d0362252 100644 --- a/components/driver/test/test_common_spi.c +++ b/components/driver/test_apps/components/test_driver_utils/test_spi_utils.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "test/test_common_spi.h" +#include "test_spi_utils.h" #include "driver/spi_slave.h" #include "esp_log.h" #include "driver/gpio.h" @@ -44,7 +44,7 @@ void spitest_def_param(void* arg) /********************************************************************************** * functions for slave task *********************************************************************************/ -esp_err_t init_slave_context(spi_slave_task_context_t *context) +esp_err_t init_slave_context(spi_slave_task_context_t *context, spi_host_device_t host) { context->data_to_send = xQueueCreate( 16, sizeof( slave_txdata_t )); if ( context->data_to_send == NULL ) { @@ -54,7 +54,7 @@ esp_err_t init_slave_context(spi_slave_task_context_t *context) if ( context->data_received == NULL ) { return ESP_ERR_NO_MEM; } - context->spi=TEST_SLAVE_HOST; + context->spi=host; return ESP_OK; } @@ -96,7 +96,7 @@ void spitest_slave_task(void* arg) } while ( t.trans_len <= 2 ); memcpy(recvbuf, &t.trans_len, sizeof(uint32_t)); *(uint8_t**)(recvbuf+4) = (uint8_t*)txdata.start; - ESP_LOGD( SLAVE_TAG, "received: %d", t.trans_len ); + ESP_LOGD( SLAVE_TAG, "received: %" PRIu32, (uint32_t)t.trans_len ); xRingbufferSend( ringbuf, recvbuf, 8+(t.trans_len+7)/8, portMAX_DELAY ); } } @@ -163,7 +163,7 @@ void spitest_master_print_data(spi_transaction_t *t, int rxlength) void spitest_slave_print_data(slave_rxdata_t *t, bool print_rxdata) { int rcv_len = (t->len+7)/8; - ESP_LOGI(SLAVE_TAG, "trans_len: %d", t->len); + ESP_LOGI(SLAVE_TAG, "trans_len: %" PRIu32, t->len); ESP_LOG_BUFFER_HEX("slave tx", t->tx_start, rcv_len); if (print_rxdata) ESP_LOG_BUFFER_HEX("slave rx", t->data, rcv_len); } @@ -188,7 +188,7 @@ esp_err_t spitest_check_data(int len, spi_transaction_t *master_t, slave_rxdata_ ret = ESP_FAIL; } if (ret != ESP_OK) { - ESP_LOGI(SLAVE_TAG, "slave_recv_len: %d", rcv_len); + ESP_LOGI(SLAVE_TAG, "slave_recv_len: %" PRIu32, rcv_len); spitest_master_print_data(master_t, len); spitest_slave_print_data(slave_t, true); //already failed, try to use the TEST_ASSERT to output the reason... @@ -250,4 +250,5 @@ void get_tx_buffer(uint32_t seed, uint8_t *master_send_buf, uint8_t *slave_send_ master_send_buf[i] = rand() % 256; } } + #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6) diff --git a/tools/unit-test-app/CMakeLists.txt b/tools/unit-test-app/CMakeLists.txt index 9cab0436bc..b29033ec3a 100644 --- a/tools/unit-test-app/CMakeLists.txt +++ b/tools/unit-test-app/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16) list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/cxx/experimental/experimental_cpp_component/") +list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/components/driver/test_apps/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(unit-test-app)