diff --git a/components/esp_common/test/CMakeLists.txt b/components/esp_common/test/CMakeLists.txt deleted file mode 100644 index fda9761c14..0000000000 --- a/components/esp_common/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRC_DIRS . - PRIV_REQUIRES cmock test_utils spi_flash esp_psram - ) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/esp_common/test_apps/esp_common/CMakeLists.txt b/components/esp_common/test_apps/esp_common/CMakeLists.txt new file mode 100644 index 0000000000..e8324aa92e --- /dev/null +++ b/components/esp_common/test_apps/esp_common/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +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(test_esp_common) diff --git a/components/esp_common/test_apps/esp_common/README.md b/components/esp_common/test_apps/esp_common/README.md new file mode 100644 index 0000000000..7e7523ec85 --- /dev/null +++ b/components/esp_common/test_apps/esp_common/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/esp_common/test_apps/esp_common/main/CMakeLists.txt b/components/esp_common/test_apps/esp_common/main/CMakeLists.txt new file mode 100644 index 0000000000..165974c96e --- /dev/null +++ b/components/esp_common/test_apps/esp_common/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "test_app_main.c" "test_attr.c" + INCLUDE_DIRS "." + PRIV_REQUIRES test_utils esp_psram + WHOLE_ARCHIVE) diff --git a/components/esp_common/test_apps/esp_common/main/test_app_main.c b/components/esp_common/test_apps/esp_common/main/test_app_main.c new file mode 100644 index 0000000000..a86b72b68b --- /dev/null +++ b/components/esp_common/test_apps/esp_common/main/test_app_main.c @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + + +// Some resources are lazy allocated (newlib locks) in the esp_common code, the threshold is left for that case +#define TEST_MEMORY_LEAK_THRESHOLD (-100) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + + + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + printf("Running esp_common support component tests\n"); + unity_run_menu(); +} diff --git a/components/esp_common/test/test_attr.c b/components/esp_common/test_apps/esp_common/main/test_attr.c similarity index 97% rename from components/esp_common/test/test_attr.c rename to components/esp_common/test_apps/esp_common/main/test_attr.c index 23e7603145..b2c37d2d2c 100644 --- a/components/esp_common/test/test_attr.c +++ b/components/esp_common/test_apps/esp_common/main/test_attr.c @@ -31,15 +31,15 @@ extern int _ext_ram_bss_start; extern int _ext_ram_bss_end; -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5045 //Variables for test: Attributes place variables into correct sections static __NOINIT_ATTR uint32_t s_noinit; +#if SOC_RTC_MEM_SUPPORTED static RTC_NOINIT_ATTR uint32_t s_rtc_noinit; static RTC_DATA_ATTR uint32_t s_rtc_data; static RTC_RODATA_ATTR uint32_t s_rtc_rodata; static RTC_FAST_ATTR uint32_t s_rtc_force_fast; static RTC_SLOW_ATTR uint32_t s_rtc_force_slow; +#endif // SOC_RTC_MEM_SUPPORTED #if CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY static EXT_RAM_NOINIT_ATTR uint32_t s_noinit_ext; #endif @@ -53,6 +53,8 @@ static bool data_in_segment(void *ptr, int *seg_start, int *seg_end) TEST_CASE("Attributes place variables into correct sections", "[ld]") { TEST_ASSERT(data_in_segment(&s_noinit, &_noinit_start, &_noinit_end)); + +#if SOC_RTC_MEM_SUPPORTED TEST_ASSERT(data_in_segment(&s_rtc_noinit, &_rtc_noinit_start, &_rtc_noinit_end)); TEST_ASSERT(data_in_segment(&s_rtc_data, &_rtc_data_start, &_rtc_data_end)); TEST_ASSERT(data_in_segment(&s_rtc_rodata, &_rtc_data_start, &_rtc_data_end)); @@ -73,14 +75,13 @@ TEST_CASE("Attributes place variables into correct sections", "[ld]") TEST_ASSERT(data_in_segment(&s_rtc_force_fast, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH)); TEST_ASSERT(data_in_segment(&s_rtc_force_slow, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH)); +#endif // SOC_RTC_MEM_SUPPORTED #if CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY TEST_ASSERT(data_in_segment(&s_noinit_ext, &_ext_ram_noinit_start, &_ext_ram_noinit_end)); #endif } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) - #if CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY #define TEST_BUFFER_SIZE (16*1024/4) diff --git a/components/esp_common/test_apps/esp_common/pytest_esp_common.py b/components/esp_common/test_apps/esp_common/pytest_esp_common.py new file mode 100644 index 0000000000..2aebfe99df --- /dev/null +++ b/components/esp_common/test_apps/esp_common/pytest_esp_common.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import re + +import pytest +from pytest_embedded import Dut + +DEFAULT_TIMEOUT = 20 +TEST_SUBMENU_PATTERN_PYTEST = re.compile(rb'\s+\((\d+)\)\s+"([^"]+)"\r?\n') + + +@pytest.mark.generic +@pytest.mark.supported_targets +@pytest.mark.parametrize( + 'config', + [ + 'default' + ] +) +def test_esp_common(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=300) + + +def run_multiple_stages(dut: Dut, test_case_num: int, stages: int) -> None: + for stage in range(1, stages + 1): + dut.write(str(test_case_num)) + dut.expect(TEST_SUBMENU_PATTERN_PYTEST, timeout=DEFAULT_TIMEOUT) + dut.write(str(stage)) + if stage != stages: + dut.expect_exact('Press ENTER to see the list of tests.') + + +@pytest.mark.generic +@pytest.mark.esp32 +@pytest.mark.parametrize( + 'config', + [ + 'esp32_psram' + ] +) +def test_esp_common_psram_esp32(dut: Dut) -> None: + extra_data = dut.parse_test_menu() + for test_case in extra_data: + if test_case.type != 'multi_stage': + dut.write(str(test_case.index)) + else: + run_multiple_stages(dut, test_case.index, len(test_case.subcases)) + dut.expect_unity_test_output(timeout=90) + dut.expect_exact("Enter next test, or 'enter' to see menu") + + +@pytest.mark.generic +@pytest.mark.esp32s2 +@pytest.mark.parametrize( + 'config', + [ + 'esp32s2_psram' + ] +) +def test_esp_common_psram_esp32s2(dut: Dut) -> None: + extra_data = dut.parse_test_menu() + for test_case in extra_data: + if test_case.type != 'multi_stage': + dut.write(str(test_case.index)) + else: + run_multiple_stages(dut, test_case.index, len(test_case.subcases)) + dut.expect_unity_test_output(timeout=90) + dut.expect_exact("Enter next test, or 'enter' to see menu") diff --git a/components/esp_common/test_apps/esp_common/sdkconfig.ci.default b/components/esp_common/test_apps/esp_common/sdkconfig.ci.default new file mode 100644 index 0000000000..d306fa0e42 --- /dev/null +++ b/components/esp_common/test_apps/esp_common/sdkconfig.ci.default @@ -0,0 +1 @@ +# Default configuration diff --git a/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32_psram b/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32_psram new file mode 100644 index 0000000000..1a7b7d83b7 --- /dev/null +++ b/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32_psram @@ -0,0 +1,6 @@ +CONFIG_IDF_TARGET="esp32" +CONFIG_SPIRAM=y +CONFIG_SPIRAM_OCCUPY_NO_HOST=y +CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n +CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y diff --git a/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32s2_psram b/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32s2_psram new file mode 100644 index 0000000000..e1ab7ac9e7 --- /dev/null +++ b/components/esp_common/test_apps/esp_common/sdkconfig.ci.esp32s2_psram @@ -0,0 +1,5 @@ +CONFIG_IDF_TARGET="esp32s2" +CONFIG_SPIRAM=y +CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y +CONFIG_SPIRAM_RODATA=y +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y diff --git a/components/esp_common/test_apps/esp_common/sdkconfig.defaults b/components/esp_common/test_apps/esp_common/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/esp_common/test_apps/esp_common/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n diff --git a/tools/unit-test-app/configs/default_2_c2 b/tools/unit-test-app/configs/default_2_c2 index d022d6ceb9..e38531dcaf 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 esp_common esp_eth esp_hid esp_netif esp_phy esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc +TEST_COMPONENTS=app_trace esp_eth esp_hid esp_netif esp_phy esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc diff --git a/tools/unit-test-app/configs/default_3_c2 b/tools/unit-test-app/configs/default_3_c2 index 25f479e775..9c551d5ca7 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 esp_common esp_eth esp_hid esp_netif esp_phy esp_ringbuf esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc esp_hw_support esp_ipc esp_system driver soc spi_flash vfs +TEST_EXCLUDE_COMPONENTS=app_trace esp_eth esp_hid esp_netif esp_phy esp_ringbuf esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc esp_hw_support esp_ipc esp_system driver soc spi_flash vfs diff --git a/tools/unit-test-app/configs/psram_s2_advanced b/tools/unit-test-app/configs/psram_s2_advanced index 6114f3cac0..b9315bfa9b 100644 --- a/tools/unit-test-app/configs/psram_s2_advanced +++ b/tools/unit-test-app/configs/psram_s2_advanced @@ -1,5 +1,5 @@ CONFIG_IDF_TARGET="esp32s2" -TEST_COMPONENTS=esp_hw_support esp_common +TEST_COMPONENTS=esp_hw_support CONFIG_SPIRAM=y CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y CONFIG_SPIRAM_RODATA=y