diff --git a/components/esp-tls/test/CMakeLists.txt b/components/esp-tls/test/CMakeLists.txt deleted file mode 100644 index 049495b636..0000000000 --- a/components/esp-tls/test/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(SRC_DIRS "." - PRIV_REQUIRES test_utils esp-tls) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp-tls/test_apps/CMakeLists.txt b/components/esp-tls/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..086455137b --- /dev/null +++ b/components/esp-tls/test_apps/CMakeLists.txt @@ -0,0 +1,7 @@ +#This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp-tls_test) diff --git a/components/esp-tls/test_apps/README.md b/components/esp-tls/test_apps/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/esp-tls/test_apps/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp-tls/test_apps/main/CMakeLists.txt b/components/esp-tls/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000000..d57cfd5249 --- /dev/null +++ b/components/esp-tls/test_apps/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRC_DIRS "." + PRIV_REQUIRES test_utils esp-tls unity + WHOLE_ARCHIVE) diff --git a/components/esp-tls/test_apps/main/app_main.c b/components/esp-tls/test_apps/main/app_main.c new file mode 100644 index 0000000000..050d90b205 --- /dev/null +++ b/components/esp-tls/test_apps/main/app_main.c @@ -0,0 +1,60 @@ +/* + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "unity.h" +#include "memory_checks.h" +#include "soc/soc_caps.h" +#if SOC_SHA_SUPPORT_PARALLEL_ENG +#include "sha/sha_parallel_engine.h" +#elif SOC_SHA_SUPPORT_DMA +#include "sha/sha_dma.h" +#else +#include "sha/sha_block.h" +#endif + +#if SOC_SHA_SUPPORT_SHA512 +#define SHA_TYPE SHA2_512 +#else +#define SHA_TYPE SHA2_256 +#endif //SOC_SHA_SUPPORT_SHA512 + +/* setUp runs before every test */ +void setUp(void) +{ + // Execute esp_sha operation to allocate internal SHA semaphore memory + // which is considered as leaked otherwise + const uint8_t input_buffer[64] = {0}; + uint8_t output_buffer[64]; + esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer); + test_utils_record_free_mem(); + TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); + TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL)); + +} + +/* tearDown runs after every test */ +void tearDown(void) +{ + /* some FreeRTOS stuff is cleaned up by idle task */ + vTaskDelay(5); + + /* clean up some of the newlib's lazy allocations */ + esp_reent_cleanup(); + + /* check if unit test has caused heap corruption in any heap */ + TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap"); + + test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL), + test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL)); + +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/esp-tls/test/test_esp_tls.c b/components/esp-tls/test_apps/main/test_esp_tls.c similarity index 82% rename from components/esp-tls/test/test_esp_tls.c rename to components/esp-tls/test_apps/main/test_esp_tls.c index a2cf344463..e245fc7e8b 100644 --- a/components/esp-tls/test/test_esp_tls.c +++ b/components/esp-tls/test_apps/main/test_esp_tls.c @@ -11,14 +11,6 @@ #include "esp_log.h" #include "esp_mac.h" #include "sys/socket.h" -#if SOC_SHA_SUPPORT_PARALLEL_ENG -#include "sha/sha_parallel_engine.h" -#elif SOC_SHA_SUPPORT_DMA -#include "sha/sha_dma.h" -#else -#include "sha/sha_block.h" -#endif -#include "test_utils.h" const char *test_cert_pem = "-----BEGIN CERTIFICATE-----\n"\ "MIICrDCCAZQCCQD88gCs5AFs/jANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1F\n"\ @@ -67,40 +59,16 @@ const char *test_key_pem = "-----BEGIN PRIVATE KEY-----\n"\ "Aogx44Fozd1t2hYcozPuZD4s\n"\ "-----END PRIVATE KEY-----\n"; -#if SOC_SHA_SUPPORT_SHA512 -#define SHA_TYPE SHA2_512 -#else -#define SHA_TYPE SHA2_256 -#endif //SOC_SHA_SUPPORT_SHA512 - -static void test_leak_setup(const char *file, long line) +TEST_CASE("esp-tls init deinit", "[esp-tls]") { - uint8_t mac[6]; - struct timeval te; - gettimeofday(&te, NULL); // get current time - esp_read_mac(mac, ESP_MAC_WIFI_STA); - printf("%s:%ld: time=%jd.%lds, mac:" MACSTR "\n", file, line, (intmax_t)te.tv_sec, te.tv_usec, MAC2STR(mac)); - // Execute esp_sha operation to allocate internal SHA semaphore memory - // which is considered as leaked otherwise - const uint8_t input_buffer[64]; - uint8_t output_buffer[64]; - esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer); - test_utils_record_free_mem(); -} - - -TEST_CASE("esp-tls init deinit", "[esp-tls][leaks=0]") -{ - test_leak_setup(__FILE__, __LINE__); struct esp_tls *tls = esp_tls_init(); TEST_ASSERT_NOT_NULL(tls); int ret = esp_tls_conn_destroy(tls); TEST_ASSERT_EQUAL(0, ret); } -TEST_CASE("esp-tls global_ca_store set free", "[esp-tls][leaks=0]") +TEST_CASE("esp-tls global_ca_store set free", "[esp-tls]") { - test_leak_setup(__FILE__, __LINE__); esp_err_t ret = esp_tls_init_global_ca_store(); TEST_ASSERT_EQUAL(ESP_OK, ret); ret = esp_tls_set_global_ca_store((const unsigned char *)test_cert_pem, strlen(test_cert_pem) + 1); @@ -109,9 +77,8 @@ TEST_CASE("esp-tls global_ca_store set free", "[esp-tls][leaks=0]") } #ifdef CONFIG_ESP_TLS_SERVER -TEST_CASE("esp_tls_server session create delete", "[esp-tls][leaks=0]") +TEST_CASE("esp_tls_server session create delete", "[esp-tls]") { - test_leak_setup(__FILE__, __LINE__); struct esp_tls *tls = esp_tls_init(); TEST_ASSERT_NOT_NULL(tls); esp_tls_cfg_server_t cfg = { @@ -126,5 +93,6 @@ TEST_CASE("esp_tls_server session create delete", "[esp-tls][leaks=0]") TEST_ASSERT_LESS_THAN_INT(0, ret); // free the allocated memory. esp_tls_server_session_delete(tls); + } #endif diff --git a/components/esp-tls/test_apps/pytest_esp-tls.py b/components/esp-tls/test_apps/pytest_esp-tls.py new file mode 100644 index 0000000000..d1ea54c669 --- /dev/null +++ b/components/esp-tls/test_apps/pytest_esp-tls.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_esp_tls(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output() diff --git a/components/esp-tls/test_apps/sdkconfig.defaults b/components/esp-tls/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..c1398bba5f --- /dev/null +++ b/components/esp-tls/test_apps/sdkconfig.defaults @@ -0,0 +1,10 @@ +# General options for additional checks +CONFIG_HEAP_POISONING_COMPREHENSIVE=y +CONFIG_COMPILER_WARN_WRITE_STRINGS=y +CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y +CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y +CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y +CONFIG_COMPILER_STACK_CHECK=y + +CONFIG_ESP_TASK_WDT=n +CONFIG_ESP_TLS_SERVER=y diff --git a/tools/unit-test-app/configs/default_2 b/tools/unit-test-app/configs/default_2 index 95651230a2..6dce46209c 100644 --- a/tools/unit-test-app/configs/default_2 +++ b/tools/unit-test-app/configs/default_2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls +TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component diff --git a/tools/unit-test-app/configs/default_2_c3 b/tools/unit-test-app/configs/default_2_c3 index 3bffa218fe..c298798436 100644 --- a/tools/unit-test-app/configs/default_2_c3 +++ b/tools/unit-test-app/configs/default_2_c3 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded CONFIG_IDF_TARGET="esp32c3" -TEST_EXCLUDE_COMPONENTS=bt app_update esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon esp-tls test_utils +TEST_EXCLUDE_COMPONENTS=bt app_update esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon test_utils diff --git a/tools/unit-test-app/configs/default_2_s2 b/tools/unit-test-app/configs/default_2_s2 index fd7703e798..2094ab1dd5 100644 --- a/tools/unit-test-app/configs/default_2_s2 +++ b/tools/unit-test-app/configs/default_2_s2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component esp-tls +TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component diff --git a/tools/unit-test-app/configs/default_2_s3 b/tools/unit-test-app/configs/default_2_s3 index 9c6dc06a2c..2a8cd2d170 100644 --- a/tools/unit-test-app/configs/default_2_s3 +++ b/tools/unit-test-app/configs/default_2_s3 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s3" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component esp-tls test_utils +TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component test_utils diff --git a/tools/unit-test-app/configs/esp_tls b/tools/unit-test-app/configs/esp_tls deleted file mode 100644 index 39a2f95ef6..0000000000 --- a/tools/unit-test-app/configs/esp_tls +++ /dev/null @@ -1,5 +0,0 @@ -# As this is protocol specific, only test for one target. -CONFIG_IDF_TARGET="esp32" -TEST_COMPONENTS=esp-tls -TEST_EXCLUDE_COMPONENTS=bt -CONFIG_ESP_TLS_SERVER=y diff --git a/tools/unit-test-app/configs/psram b/tools/unit-test-app/configs/psram index af93785ac8..fe89f7ceb9 100644 --- a/tools/unit-test-app/configs/psram +++ b/tools/unit-test-app/configs/psram @@ -1,5 +1,5 @@ CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update driver esp_hw_support esp_ipc esp_pm esp_system esp_timer mbedtls spi_flash test_utils heap pthread soc experimental_cpp_component esp-tls freertos sdmmc +TEST_EXCLUDE_COMPONENTS=bt app_update driver esp_hw_support esp_ipc esp_pm esp_system esp_timer mbedtls spi_flash test_utils heap pthread soc experimental_cpp_component freertos sdmmc CONFIG_SPIRAM=y CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 CONFIG_SPIRAM_OCCUPY_NO_HOST=y diff --git a/tools/unit-test-app/configs/release_2 b/tools/unit-test-app/configs/release_2 index dc94dfb218..ff6954dd54 100644 --- a/tools/unit-test-app/configs/release_2 +++ b/tools/unit-test-app/configs/release_2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be included (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls +TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/tools/unit-test-app/configs/single_core_2 b/tools/unit-test-app/configs/single_core_2 index de47f6c720..01fe4ee3bb 100644 --- a/tools/unit-test-app/configs/single_core_2 +++ b/tools/unit-test-app/configs/single_core_2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls +TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component CONFIG_MEMMAP_SMP=n CONFIG_FREERTOS_UNICORE=y CONFIG_ESP32_RTCDATA_IN_FAST_MEM=y