From 146f1012896b0a1191697984e0db343a56988ee4 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Wed, 7 Sep 2022 16:23:54 +0530 Subject: [PATCH 1/4] ci: Migrate mbedtls unit tests from unit-test-app to component-test-app --- components/mbedtls/test_apps/CMakeLists.txt | 7 ++ components/mbedtls/test_apps/README.md | 2 + .../{test => test_apps/main}/CMakeLists.txt | 5 +- components/mbedtls/test_apps/main/app_main.c | 19 ++++++ .../main}/crts/bad_md_crt.pem | 0 .../main}/crts/correct_sig_crt_esp32_com.pem | 0 .../{test => test_apps/main}/crts/prvtkey.pem | 0 .../main}/crts/server_cert_bundle | Bin .../main}/crts/server_cert_chain.pem | 0 .../main}/crts/server_root.pem | 0 .../main}/crts/wrong_sig_crt_esp32_com.pem | 0 .../{test => test_apps/main}/test_aes.c | 5 ++ .../{test => test_apps/main}/test_aes_gcm.c | 0 .../{test => test_apps/main}/test_aes_perf.c | 5 ++ .../main}/test_aes_sha_parallel.c | 0 .../main}/test_aes_sha_rsa.c | 0 .../main}/test_apb_dport_access.c | 5 ++ .../main}/test_apb_dport_access.h | 5 ++ .../{test => test_apps/main}/test_ecp.c | 0 .../main}/test_esp_crt_bundle.c | 0 .../{test => test_apps/main}/test_mbedtls.c | 5 ++ .../main}/test_mbedtls_mpi.c | 0 .../main}/test_mbedtls_sha.c | 0 .../main}/test_mbedtls_utils.c | 0 .../main}/test_mbedtls_utils.h | 0 .../{test => test_apps/main}/test_rsa.c | 28 ++++---- .../{test => test_apps/main}/test_sha.c | 0 .../{test => test_apps/main}/test_sha_perf.c | 0 .../mbedtls/test_apps/pytest_mbedtls_ut.py | 64 ++++++++++++++++++ .../mbedtls/test_apps/sdkconfig.ci.aes_no_hw | 2 + .../mbedtls/test_apps/sdkconfig.ci.default | 0 .../mbedtls/test_apps/sdkconfig.ci.psram | 1 + .../test_apps/sdkconfig.ci.psram_all_ext | 4 ++ .../test_apps/sdkconfig.ci.psram_esp32 | 3 + .../mbedtls/test_apps/sdkconfig.defaults | 9 +++ .../test_apps/sdkconfig.defaults.esp32 | 3 + .../test_apps/sdkconfig.defaults.esp32c2 | 2 + .../test_apps/sdkconfig.defaults.esp32c3 | 1 + .../test_apps/sdkconfig.defaults.esp32s2 | 2 + .../test_apps/sdkconfig.defaults.esp32s3 | 2 + tools/unit-test-app/configs/aes_no_hw | 5 -- tools/unit-test-app/configs/aes_no_hw_c3 | 5 -- tools/unit-test-app/configs/aes_no_hw_s2 | 5 -- tools/unit-test-app/configs/aes_no_hw_s3 | 5 -- tools/unit-test-app/configs/default_2_c2 | 2 +- tools/unit-test-app/configs/default_3_c2 | 2 +- tools/unit-test-app/configs/psram | 2 +- tools/unit-test-app/configs/psram_2 | 2 +- tools/unit-test-app/configs/psram_all_ext_2 | 2 +- tools/unit-test-app/configs/psram_s2_base | 2 +- tools/unit-test-app/configs/psram_s3_base | 2 +- 51 files changed, 171 insertions(+), 42 deletions(-) create mode 100644 components/mbedtls/test_apps/CMakeLists.txt create mode 100644 components/mbedtls/test_apps/README.md rename components/mbedtls/{test => test_apps/main}/CMakeLists.txt (89%) create mode 100644 components/mbedtls/test_apps/main/app_main.c rename components/mbedtls/{test => test_apps/main}/crts/bad_md_crt.pem (100%) rename components/mbedtls/{test => test_apps/main}/crts/correct_sig_crt_esp32_com.pem (100%) rename components/mbedtls/{test => test_apps/main}/crts/prvtkey.pem (100%) rename components/mbedtls/{test => test_apps/main}/crts/server_cert_bundle (100%) rename components/mbedtls/{test => test_apps/main}/crts/server_cert_chain.pem (100%) rename components/mbedtls/{test => test_apps/main}/crts/server_root.pem (100%) rename components/mbedtls/{test => test_apps/main}/crts/wrong_sig_crt_esp32_com.pem (100%) rename components/mbedtls/{test => test_apps/main}/test_aes.c (99%) rename components/mbedtls/{test => test_apps/main}/test_aes_gcm.c (100%) rename components/mbedtls/{test => test_apps/main}/test_aes_perf.c (94%) rename components/mbedtls/{test => test_apps/main}/test_aes_sha_parallel.c (100%) rename components/mbedtls/{test => test_apps/main}/test_aes_sha_rsa.c (100%) rename components/mbedtls/{test => test_apps/main}/test_apb_dport_access.c (90%) rename components/mbedtls/{test => test_apps/main}/test_apb_dport_access.h (82%) rename components/mbedtls/{test => test_apps/main}/test_ecp.c (100%) rename components/mbedtls/{test => test_apps/main}/test_esp_crt_bundle.c (100%) rename components/mbedtls/{test => test_apps/main}/test_mbedtls.c (90%) rename components/mbedtls/{test => test_apps/main}/test_mbedtls_mpi.c (100%) rename components/mbedtls/{test => test_apps/main}/test_mbedtls_sha.c (100%) rename components/mbedtls/{test => test_apps/main}/test_mbedtls_utils.c (100%) rename components/mbedtls/{test => test_apps/main}/test_mbedtls_utils.h (100%) rename components/mbedtls/{test => test_apps/main}/test_rsa.c (97%) rename components/mbedtls/{test => test_apps/main}/test_sha.c (100%) rename components/mbedtls/{test => test_apps/main}/test_sha_perf.c (100%) create mode 100644 components/mbedtls/test_apps/pytest_mbedtls_ut.py create mode 100644 components/mbedtls/test_apps/sdkconfig.ci.aes_no_hw create mode 100644 components/mbedtls/test_apps/sdkconfig.ci.default create mode 100644 components/mbedtls/test_apps/sdkconfig.ci.psram create mode 100644 components/mbedtls/test_apps/sdkconfig.ci.psram_all_ext create mode 100644 components/mbedtls/test_apps/sdkconfig.ci.psram_esp32 create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults.esp32 create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults.esp32c2 create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults.esp32c3 create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults.esp32s2 create mode 100644 components/mbedtls/test_apps/sdkconfig.defaults.esp32s3 delete mode 100644 tools/unit-test-app/configs/aes_no_hw delete mode 100644 tools/unit-test-app/configs/aes_no_hw_c3 delete mode 100644 tools/unit-test-app/configs/aes_no_hw_s2 delete mode 100644 tools/unit-test-app/configs/aes_no_hw_s3 diff --git a/components/mbedtls/test_apps/CMakeLists.txt b/components/mbedtls/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..16481610bb --- /dev/null +++ b/components/mbedtls/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(mbedtls_test) diff --git a/components/mbedtls/test_apps/README.md b/components/mbedtls/test_apps/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/mbedtls/test_apps/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/mbedtls/test/CMakeLists.txt b/components/mbedtls/test_apps/main/CMakeLists.txt similarity index 89% rename from components/mbedtls/test/CMakeLists.txt rename to components/mbedtls/test_apps/main/CMakeLists.txt index d51cbed59a..533724e2a6 100644 --- a/components/mbedtls/test/CMakeLists.txt +++ b/components/mbedtls/test_apps/main/CMakeLists.txt @@ -7,8 +7,9 @@ set(TEST_CRTS "crts/server_cert_chain.pem" idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." - PRIV_REQUIRES cmock test_utils mbedtls esp_timer - EMBED_TXTFILES ${TEST_CRTS}) + PRIV_REQUIRES cmock test_utils mbedtls esp_timer unity + EMBED_TXTFILES ${TEST_CRTS} + WHOLE_ARCHIVE) target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") idf_component_get_property(mbedtls mbedtls COMPONENT_LIB) diff --git a/components/mbedtls/test_apps/main/app_main.c b/components/mbedtls/test_apps/main/app_main.c new file mode 100644 index 0000000000..317c70567e --- /dev/null +++ b/components/mbedtls/test_apps/main/app_main.c @@ -0,0 +1,19 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "test_utils.h" + +static void test_task(void *pvParameters) +{ + vTaskDelay(2); /* Delay a bit to let the main task be deleted */ + unity_run_menu(); +} + +void app_main(void) +{ + xTaskCreatePinnedToCore(test_task, "testTask", UNITY_FREERTOS_STACK_SIZE, NULL, UNITY_FREERTOS_PRIORITY, NULL, UNITY_FREERTOS_CPU); +} diff --git a/components/mbedtls/test/crts/bad_md_crt.pem b/components/mbedtls/test_apps/main/crts/bad_md_crt.pem similarity index 100% rename from components/mbedtls/test/crts/bad_md_crt.pem rename to components/mbedtls/test_apps/main/crts/bad_md_crt.pem diff --git a/components/mbedtls/test/crts/correct_sig_crt_esp32_com.pem b/components/mbedtls/test_apps/main/crts/correct_sig_crt_esp32_com.pem similarity index 100% rename from components/mbedtls/test/crts/correct_sig_crt_esp32_com.pem rename to components/mbedtls/test_apps/main/crts/correct_sig_crt_esp32_com.pem diff --git a/components/mbedtls/test/crts/prvtkey.pem b/components/mbedtls/test_apps/main/crts/prvtkey.pem similarity index 100% rename from components/mbedtls/test/crts/prvtkey.pem rename to components/mbedtls/test_apps/main/crts/prvtkey.pem diff --git a/components/mbedtls/test/crts/server_cert_bundle b/components/mbedtls/test_apps/main/crts/server_cert_bundle similarity index 100% rename from components/mbedtls/test/crts/server_cert_bundle rename to components/mbedtls/test_apps/main/crts/server_cert_bundle diff --git a/components/mbedtls/test/crts/server_cert_chain.pem b/components/mbedtls/test_apps/main/crts/server_cert_chain.pem similarity index 100% rename from components/mbedtls/test/crts/server_cert_chain.pem rename to components/mbedtls/test_apps/main/crts/server_cert_chain.pem diff --git a/components/mbedtls/test/crts/server_root.pem b/components/mbedtls/test_apps/main/crts/server_root.pem similarity index 100% rename from components/mbedtls/test/crts/server_root.pem rename to components/mbedtls/test_apps/main/crts/server_root.pem diff --git a/components/mbedtls/test/crts/wrong_sig_crt_esp32_com.pem b/components/mbedtls/test_apps/main/crts/wrong_sig_crt_esp32_com.pem similarity index 100% rename from components/mbedtls/test/crts/wrong_sig_crt_esp32_com.pem rename to components/mbedtls/test_apps/main/crts/wrong_sig_crt_esp32_com.pem diff --git a/components/mbedtls/test/test_aes.c b/components/mbedtls/test_apps/main/test_aes.c similarity index 99% rename from components/mbedtls/test/test_aes.c rename to components/mbedtls/test_apps/main/test_aes.c index 4d5e4872d9..925e4a82f2 100644 --- a/components/mbedtls/test/test_aes.c +++ b/components/mbedtls/test_apps/main/test_aes.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* mbedTLS AES test */ #include diff --git a/components/mbedtls/test/test_aes_gcm.c b/components/mbedtls/test_apps/main/test_aes_gcm.c similarity index 100% rename from components/mbedtls/test/test_aes_gcm.c rename to components/mbedtls/test_apps/main/test_aes_gcm.c diff --git a/components/mbedtls/test/test_aes_perf.c b/components/mbedtls/test_apps/main/test_aes_perf.c similarity index 94% rename from components/mbedtls/test/test_aes_perf.c rename to components/mbedtls/test_apps/main/test_aes_perf.c index 00a6247bf4..6ba8f15c10 100644 --- a/components/mbedtls/test/test_aes_perf.c +++ b/components/mbedtls/test_apps/main/test_aes_perf.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* mbedTLS AES performance test */ #include diff --git a/components/mbedtls/test/test_aes_sha_parallel.c b/components/mbedtls/test_apps/main/test_aes_sha_parallel.c similarity index 100% rename from components/mbedtls/test/test_aes_sha_parallel.c rename to components/mbedtls/test_apps/main/test_aes_sha_parallel.c diff --git a/components/mbedtls/test/test_aes_sha_rsa.c b/components/mbedtls/test_apps/main/test_aes_sha_rsa.c similarity index 100% rename from components/mbedtls/test/test_aes_sha_rsa.c rename to components/mbedtls/test_apps/main/test_aes_sha_rsa.c diff --git a/components/mbedtls/test/test_apb_dport_access.c b/components/mbedtls/test_apps/main/test_apb_dport_access.c similarity index 90% rename from components/mbedtls/test/test_apb_dport_access.c rename to components/mbedtls/test_apps/main/test_apb_dport_access.c index 07203ac1ea..34cb956872 100644 --- a/components/mbedtls/test/test_apb_dport_access.c +++ b/components/mbedtls/test_apps/main/test_apb_dport_access.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* Implementation of utility functions to verify unit tests aren't performing SMP-unsafe DPORT reads. */ diff --git a/components/mbedtls/test/test_apb_dport_access.h b/components/mbedtls/test_apps/main/test_apb_dport_access.h similarity index 82% rename from components/mbedtls/test/test_apb_dport_access.h rename to components/mbedtls/test_apps/main/test_apb_dport_access.h index 8f30e0465a..3231d745e2 100644 --- a/components/mbedtls/test/test_apb_dport_access.h +++ b/components/mbedtls/test_apps/main/test_apb_dport_access.h @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* Utility functions to test that APB access is still safe while the other CPU performs some set of DPORT accesses diff --git a/components/mbedtls/test/test_ecp.c b/components/mbedtls/test_apps/main/test_ecp.c similarity index 100% rename from components/mbedtls/test/test_ecp.c rename to components/mbedtls/test_apps/main/test_ecp.c diff --git a/components/mbedtls/test/test_esp_crt_bundle.c b/components/mbedtls/test_apps/main/test_esp_crt_bundle.c similarity index 100% rename from components/mbedtls/test/test_esp_crt_bundle.c rename to components/mbedtls/test_apps/main/test_esp_crt_bundle.c diff --git a/components/mbedtls/test/test_mbedtls.c b/components/mbedtls/test_apps/main/test_mbedtls.c similarity index 90% rename from components/mbedtls/test/test_mbedtls.c rename to components/mbedtls/test_apps/main/test_mbedtls.c index 70eeac5b6b..a35ba2140b 100644 --- a/components/mbedtls/test/test_mbedtls.c +++ b/components/mbedtls/test_apps/main/test_mbedtls.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* mbedTLS self-tests as unit tests Focus on testing functionality where we use ESP32 hardware diff --git a/components/mbedtls/test/test_mbedtls_mpi.c b/components/mbedtls/test_apps/main/test_mbedtls_mpi.c similarity index 100% rename from components/mbedtls/test/test_mbedtls_mpi.c rename to components/mbedtls/test_apps/main/test_mbedtls_mpi.c diff --git a/components/mbedtls/test/test_mbedtls_sha.c b/components/mbedtls/test_apps/main/test_mbedtls_sha.c similarity index 100% rename from components/mbedtls/test/test_mbedtls_sha.c rename to components/mbedtls/test_apps/main/test_mbedtls_sha.c diff --git a/components/mbedtls/test/test_mbedtls_utils.c b/components/mbedtls/test_apps/main/test_mbedtls_utils.c similarity index 100% rename from components/mbedtls/test/test_mbedtls_utils.c rename to components/mbedtls/test_apps/main/test_mbedtls_utils.c diff --git a/components/mbedtls/test/test_mbedtls_utils.h b/components/mbedtls/test_apps/main/test_mbedtls_utils.h similarity index 100% rename from components/mbedtls/test/test_mbedtls_utils.h rename to components/mbedtls/test_apps/main/test_mbedtls_utils.h diff --git a/components/mbedtls/test/test_rsa.c b/components/mbedtls/test_apps/main/test_rsa.c similarity index 97% rename from components/mbedtls/test/test_rsa.c rename to components/mbedtls/test_apps/main/test_rsa.c index d6337dba5c..f69a0238f8 100644 --- a/components/mbedtls/test/test_rsa.c +++ b/components/mbedtls/test_apps/main/test_rsa.c @@ -20,6 +20,7 @@ #include "freertos/FreeRTOS.h" #include "unity.h" #include "test_utils.h" +#include "memory_checks.h" #include "ccomp_timer.h" #define PRINT_DEBUG_INFO @@ -423,23 +424,24 @@ static void print_rsa_details(mbedtls_rsa_context *rsa) } #endif -/** NOTE: -* For ESP32-S3, CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is enabled -* by default; allocating a lock of 92 bytes, which is never freed. -* -* MR !18574 adds the MPI crypto lock for S3 increasing the leakage by -* 92 bytes. This caused the RSA UT to fail with a leakage more than -* 1024 bytes. -* -* The allocations made by ESP32-S2 (944 bytes) and ESP32-S3 are the same, -* except for the JTAG lock (92 + 944 > 1024). -*/ #if CONFIG_FREERTOS_SMP // IDF-5260 -TEST_CASE("test performance RSA key operations", "[bignum][leaks=1088][timeout=60]") +TEST_CASE("test performance RSA key operations", "[bignum][timeout=60]") #else -TEST_CASE("test performance RSA key operations", "[bignum][leaks=1088]") +TEST_CASE("test performance RSA key operations", "[bignum]") #endif { + /** NOTE: + * For ESP32-S3, CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is enabled + * by default; allocating a lock of 92 bytes, which is never freed. + * + * MR !18574 adds the MPI crypto lock for S3 increasing the leakage by + * 92 bytes. This caused the RSA UT to fail with a leakage more than + * 1024 bytes. + * + * The allocations made by ESP32-S2 (944 bytes) and ESP32-S3 are the same, + * except for the JTAG lock (92 + 944 > 1024). + */ + TEST_ESP_OK(test_utils_set_leak_level(1088, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); for (int keysize = 2048; keysize <= SOC_RSA_MAX_BIT_LEN; keysize += 1024) { rsa_key_operations(keysize, true, false); } diff --git a/components/mbedtls/test/test_sha.c b/components/mbedtls/test_apps/main/test_sha.c similarity index 100% rename from components/mbedtls/test/test_sha.c rename to components/mbedtls/test_apps/main/test_sha.c diff --git a/components/mbedtls/test/test_sha_perf.c b/components/mbedtls/test_apps/main/test_sha_perf.c similarity index 100% rename from components/mbedtls/test/test_sha_perf.c rename to components/mbedtls/test_apps/main/test_sha_perf.c diff --git a/components/mbedtls/test_apps/pytest_mbedtls_ut.py b/components/mbedtls/test_apps/pytest_mbedtls_ut.py new file mode 100644 index 0000000000..43dd24d909 --- /dev/null +++ b/components/mbedtls/test_apps/pytest_mbedtls_ut.py @@ -0,0 +1,64 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_mbedtls(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.esp32c3 +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'aes_no_hw', + ], + indirect=True, +) +def test_mbedtls_aes_no_hw(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'psram', + ], + indirect=True, +) +def test_mbedtls_psram(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) + + +@pytest.mark.esp32 +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'psram_esp32', + 'psram_all_ext', + ], + indirect=True, +) +def test_mbedtls_psram_esp32(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) diff --git a/components/mbedtls/test_apps/sdkconfig.ci.aes_no_hw b/components/mbedtls/test_apps/sdkconfig.ci.aes_no_hw new file mode 100644 index 0000000000..aadb89a893 --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.ci.aes_no_hw @@ -0,0 +1,2 @@ +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_MPI_USE_INTERRUPT=n diff --git a/components/mbedtls/test_apps/sdkconfig.ci.default b/components/mbedtls/test_apps/sdkconfig.ci.default new file mode 100644 index 0000000000..e69de29bb2 diff --git a/components/mbedtls/test_apps/sdkconfig.ci.psram b/components/mbedtls/test_apps/sdkconfig.ci.psram new file mode 100644 index 0000000000..cc641ea603 --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.ci.psram @@ -0,0 +1 @@ +CONFIG_SPIRAM=y diff --git a/components/mbedtls/test_apps/sdkconfig.ci.psram_all_ext b/components/mbedtls/test_apps/sdkconfig.ci.psram_all_ext new file mode 100644 index 0000000000..ad3452cf7b --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.ci.psram_all_ext @@ -0,0 +1,4 @@ +CONFIG_SPIRAM=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 diff --git a/components/mbedtls/test_apps/sdkconfig.ci.psram_esp32 b/components/mbedtls/test_apps/sdkconfig.ci.psram_esp32 new file mode 100644 index 0000000000..5acbcfd7fc --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.ci.psram_esp32 @@ -0,0 +1,3 @@ +CONFIG_SPIRAM=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y diff --git a/components/mbedtls/test_apps/sdkconfig.defaults b/components/mbedtls/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..ec826a5a16 --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults @@ -0,0 +1,9 @@ +# 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 diff --git a/components/mbedtls/test_apps/sdkconfig.defaults.esp32 b/components/mbedtls/test_apps/sdkconfig.defaults.esp32 new file mode 100644 index 0000000000..59093635f0 --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults.esp32 @@ -0,0 +1,3 @@ +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_XTAL_FREQ_AUTO=y +CONFIG_SPI_FLASH_SHARE_SPI1_BUS=y diff --git a/components/mbedtls/test_apps/sdkconfig.defaults.esp32c2 b/components/mbedtls/test_apps/sdkconfig.defaults.esp32c2 new file mode 100644 index 0000000000..bb33cff20a --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults.esp32c2 @@ -0,0 +1,2 @@ +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n +CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y diff --git a/components/mbedtls/test_apps/sdkconfig.defaults.esp32c3 b/components/mbedtls/test_apps/sdkconfig.defaults.esp32c3 new file mode 100644 index 0000000000..d0ea27a6c6 --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults.esp32c3 @@ -0,0 +1 @@ +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n diff --git a/components/mbedtls/test_apps/sdkconfig.defaults.esp32s2 b/components/mbedtls/test_apps/sdkconfig.defaults.esp32s2 new file mode 100644 index 0000000000..da22be442b --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults.esp32s2 @@ -0,0 +1,2 @@ +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n diff --git a/components/mbedtls/test_apps/sdkconfig.defaults.esp32s3 b/components/mbedtls/test_apps/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000000..da22be442b --- /dev/null +++ b/components/mbedtls/test_apps/sdkconfig.defaults.esp32s3 @@ -0,0 +1,2 @@ +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n diff --git a/tools/unit-test-app/configs/aes_no_hw b/tools/unit-test-app/configs/aes_no_hw deleted file mode 100644 index 43b13b84a0..0000000000 --- a/tools/unit-test-app/configs/aes_no_hw +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update test_utils -TEST_COMPONENTS=mbedtls -CONFIG_MBEDTLS_HARDWARE_AES=n -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=n diff --git a/tools/unit-test-app/configs/aes_no_hw_c3 b/tools/unit-test-app/configs/aes_no_hw_c3 deleted file mode 100644 index 0c4c811177..0000000000 --- a/tools/unit-test-app/configs/aes_no_hw_c3 +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_IDF_TARGET="esp32c3" -TEST_EXCLUDE_COMPONENTS=bt app_update test_utils -TEST_COMPONENTS=mbedtls -CONFIG_MBEDTLS_HARDWARE_AES=n -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=n diff --git a/tools/unit-test-app/configs/aes_no_hw_s2 b/tools/unit-test-app/configs/aes_no_hw_s2 deleted file mode 100644 index d180c5169d..0000000000 --- a/tools/unit-test-app/configs/aes_no_hw_s2 +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt app_update test_utils -TEST_COMPONENTS=mbedtls -CONFIG_MBEDTLS_HARDWARE_AES=n -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=n diff --git a/tools/unit-test-app/configs/aes_no_hw_s3 b/tools/unit-test-app/configs/aes_no_hw_s3 deleted file mode 100644 index a33e4669aa..0000000000 --- a/tools/unit-test-app/configs/aes_no_hw_s3 +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_IDF_TARGET="esp32s3" -TEST_EXCLUDE_COMPONENTS=bt app_update test_utils -TEST_COMPONENTS=mbedtls -CONFIG_MBEDTLS_HARDWARE_AES=n -CONFIG_MBEDTLS_MPI_USE_INTERRUPT=n diff --git a/tools/unit-test-app/configs/default_2_c2 b/tools/unit-test-app/configs/default_2_c2 index ebb6bdf144..56520c011b 100644 --- a/tools/unit-test-app/configs/default_2_c2 +++ b/tools/unit-test-app/configs/default_2_c2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be included CONFIG_IDF_TARGET="esp32c2" -TEST_COMPONENTS=app_trace console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf esp_rom esp_wifi espcoredump hal lwip mbedtls mdns mqtt newlib nvs_flash partition_table sdmmc spiffs +TEST_COMPONENTS=app_trace bootloader_support console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf esp_rom esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc spiffs diff --git a/tools/unit-test-app/configs/default_3_c2 b/tools/unit-test-app/configs/default_3_c2 index da4a7937bb..3e5ad002b1 100644 --- a/tools/unit-test-app/configs/default_3_c2 +++ b/tools/unit-test-app/configs/default_3_c2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be included CONFIG_IDF_TARGET="esp32c2" -TEST_EXCLUDE_COMPONENTS=app_trace console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf esp_rom esp_wifi espcoredump hal lwip mbedtls mdns mqtt newlib nvs_flash partition_table sdmmc spiffs freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs +TEST_EXCLUDE_COMPONENTS=app_trace bootloader_support console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf esp_rom esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc spiffs freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs diff --git a/tools/unit-test-app/configs/psram b/tools/unit-test-app/configs/psram index fe89f7ceb9..7f7b946125 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 freertos sdmmc +TEST_EXCLUDE_COMPONENTS=bt app_update driver esp_hw_support esp_ipc esp_pm esp_system esp_timer spi_flash test_utils heap pthread soc experimental_cpp_component esp-tls 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/psram_2 b/tools/unit-test-app/configs/psram_2 index 401588ab20..a00291e6ca 100644 --- a/tools/unit-test-app/configs/psram_2 +++ b/tools/unit-test-app/configs/psram_2 @@ -1,5 +1,5 @@ CONFIG_IDF_TARGET="esp32" -TEST_COMPONENTS=esp_hw_support esp_ipc esp_system esp_timer mbedtls spi_flash heap pthread soc +TEST_COMPONENTS=esp_hw_support esp_ipc esp_system esp_timer spi_flash heap pthread soc CONFIG_SPIRAM=y CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 CONFIG_SPIRAM_OCCUPY_NO_HOST=y diff --git a/tools/unit-test-app/configs/psram_all_ext_2 b/tools/unit-test-app/configs/psram_all_ext_2 index f1d455e5a3..dd3db07122 100644 --- a/tools/unit-test-app/configs/psram_all_ext_2 +++ b/tools/unit-test-app/configs/psram_all_ext_2 @@ -1,5 +1,5 @@ CONFIG_IDF_TARGET="esp32" -TEST_COMPONENTS=heap mbedtls soc spi_flash +TEST_COMPONENTS=heap soc spi_flash CONFIG_SPIRAM=y CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 CONFIG_SPIRAM_OCCUPY_NO_HOST=y diff --git a/tools/unit-test-app/configs/psram_s2_base b/tools/unit-test-app/configs/psram_s2_base index c40a661415..b9faef087c 100644 --- a/tools/unit-test-app/configs/psram_s2_base +++ b/tools/unit-test-app/configs/psram_s2_base @@ -1,3 +1,3 @@ CONFIG_IDF_TARGET="esp32s2" -TEST_COMPONENTS=esp_hw_support mbedtls esp_system +TEST_COMPONENTS=esp_hw_support esp_system CONFIG_SPIRAM=y diff --git a/tools/unit-test-app/configs/psram_s3_base b/tools/unit-test-app/configs/psram_s3_base index bf9a2e9dba..898ea06ce5 100644 --- a/tools/unit-test-app/configs/psram_s3_base +++ b/tools/unit-test-app/configs/psram_s3_base @@ -1,3 +1,3 @@ CONFIG_IDF_TARGET="esp32s3" -TEST_COMPONENTS=esp_hw_support mbedtls esp_system +TEST_COMPONENTS=esp_hw_support esp_system CONFIG_SPIRAM=y From 317eeddce47fc122075f8c1c44896abf04b67882 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Fri, 9 Sep 2022 14:53:55 +0530 Subject: [PATCH 2/4] fix: memory leaks check added --- components/mbedtls/test_apps/main/app_main.c | 31 +++++++++++++++++-- .../components/test_utils/memory_checks.c | 5 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/components/mbedtls/test_apps/main/app_main.c b/components/mbedtls/test_apps/main/app_main.c index 317c70567e..0716defabf 100644 --- a/components/mbedtls/test_apps/main/app_main.c +++ b/components/mbedtls/test_apps/main/app_main.c @@ -5,7 +5,34 @@ */ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "test_utils.h" +#include "unity.h" +#include "memory_checks.h" + +/* setUp runs before every test */ +void setUp(void) +{ + test_utils_record_free_mem(); + test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL); + test_utils_set_leak_level(CONFIG_UNITY_WARN_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL); + test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_LWIP); +} + +/* 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)); + +} static void test_task(void *pvParameters) { @@ -15,5 +42,5 @@ static void test_task(void *pvParameters) void app_main(void) { - xTaskCreatePinnedToCore(test_task, "testTask", UNITY_FREERTOS_STACK_SIZE, NULL, UNITY_FREERTOS_PRIORITY, NULL, UNITY_FREERTOS_CPU); + xTaskCreatePinnedToCore(test_task, "testTask", CONFIG_UNITY_FREERTOS_STACK_SIZE, NULL, CONFIG_UNITY_FREERTOS_PRIORITY, NULL, CONFIG_UNITY_FREERTOS_CPU); } diff --git a/tools/unit-test-app/components/test_utils/memory_checks.c b/tools/unit-test-app/components/test_utils/memory_checks.c index f845eab5ca..170f4ca926 100644 --- a/tools/unit-test-app/components/test_utils/memory_checks.c +++ b/tools/unit-test-app/components/test_utils/memory_checks.c @@ -82,6 +82,11 @@ static void check_leak(size_t before_free, if (leaked <= warn_threshold) { return; } + else { + printf("The test leaked more memory than warn threshold: Leaked: %d Warn threshold: -%u \n", + leaked, + warn_threshold); + } printf("MALLOC_CAP_%s %s leak: Before %u bytes free, After %u bytes free (delta %u)\n", type, From 68a7da3f0be8b74a9e4eba450ba45a92e6b18dff Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Wed, 14 Sep 2022 15:06:50 +0530 Subject: [PATCH 3/4] test_utils: reset critical lwip leap level Test cases calling test_case_uses_tcpip() set critical lwip leak level to 4095, but do not reset it to default. Hence, 4095 used to get added while calculating the critical threshold for the testcases following them. --- tools/unit-test-app/components/test_utils/test_runner.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/unit-test-app/components/test_utils/test_runner.c b/tools/unit-test-app/components/test_utils/test_runner.c index f9e1422361..79e918544e 100644 --- a/tools/unit-test-app/components/test_utils/test_runner.c +++ b/tools/unit-test-app/components/test_utils/test_runner.c @@ -58,6 +58,7 @@ void setUp(void) test_utils_record_free_mem(); test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL); test_utils_set_leak_level(CONFIG_UNITY_WARN_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL); + test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_LWIP); } typedef enum { From 83504f96d4c550a84e35180390ae19cbda543bd7 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Wed, 14 Sep 2022 15:53:50 +0530 Subject: [PATCH 4/4] ci: UT job parallel decreased --- .gitlab/ci/target-test.yml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 5cd24ddd22..875bf5199d 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -871,7 +871,7 @@ test_app_test_esp32_generic: UT_001: extends: .unit_test_esp32_template - parallel: 50 + parallel: 44 tags: - ESP32_IDF - UT_T1_1 @@ -880,7 +880,7 @@ UT_001: UT_002: extends: .unit_test_esp32_template - parallel: 21 + parallel: 16 tags: - ESP32_IDF - UT_T1_1 @@ -915,18 +915,10 @@ UT_006: UT_007: extends: .unit_test_esp32_template - parallel: 2 tags: - ESP32_IDF - UT_T1_1 -UT_008: - extends: .unit_test_esp32_template - tags: - - ESP32_IDF - - UT_T1_GPIO - - psram - UT_014: extends: .unit_test_esp32_template tags: @@ -978,14 +970,13 @@ UT_033: UT_034: extends: .unit_test_esp32_template - parallel: 2 tags: - ESP32_IDF - UT_T1_ESP_FLASH UT_035: extends: .unit_test_esp32s2_template - parallel: 50 + parallel: 44 tags: - ESP32S2_IDF - UT_T1_1 @@ -999,7 +990,6 @@ UT_036: UT_038: extends: .unit_test_esp32s2_template - parallel: 2 tags: - ESP32S2_IDF - UT_T1_ESP_FLASH @@ -1087,7 +1077,7 @@ UT_S2_SDSPI: UT_C2: extends: .unit_test_esp32c2_template - parallel: 22 + parallel: 19 tags: - ESP32C2_IDF - UT_T1_1 @@ -1119,14 +1109,13 @@ UT_C2_FLASH: UT_C3: extends: .unit_test_esp32c3_template - parallel: 31 + parallel: 27 tags: - ESP32C3_IDF - UT_T1_1 UT_C3_FLASH: extends: .unit_test_esp32c3_template - parallel: 2 tags: - ESP32C3_IDF - UT_T1_ESP_FLASH @@ -1157,14 +1146,14 @@ UT_C3_SDSPI: UT_S3: extends: .unit_test_esp32s3_template - parallel: 29 + parallel: 25 tags: - ESP32S3_IDF - UT_T1_1 UT_S3_QUAD_PSRAM: extends: .unit_test_esp32s3_template - parallel: 4 + parallel: 2 tags: - ESP32S3_IDF - UT_T1_1