diff --git a/components/esp_rom/.build-test-rules.yml b/components/esp_rom/.build-test-rules.yml index 1ed5faae8e..8a19709b18 100644 --- a/components/esp_rom/.build-test-rules.yml +++ b/components/esp_rom/.build-test-rules.yml @@ -4,3 +4,9 @@ components/esp_rom/host_test/rom_test: enable: - if: IDF_TARGET == "linux" reason: only test on linux + +components/esp_rom/test_apps: + disable_test: + - if: IDF_TARGET in ["esp32", "esp32c2"] + temporary: false + reason: lack of memory for testing miniz compressing diff --git a/components/esp_rom/test/CMakeLists.txt b/components/esp_rom/test/CMakeLists.txt deleted file mode 100644 index 0edd942c0f..0000000000 --- a/components/esp_rom/test/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -idf_component_register(SRC_DIRS . - PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR} - PRIV_REQUIRES cmock test_utils) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") - -add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - COMMAND xxd -i "logo.jpg" "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - WORKING_DIRECTORY ${COMPONENT_DIR} - DEPENDS "${CMAKE_CURRENT_LIST_DIR}/logo.jpg") -add_custom_target(test_logo DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h") -add_dependencies(${COMPONENT_LIB} test_logo) diff --git a/components/esp_rom/test/logo.jpg b/components/esp_rom/test/logo.jpg deleted file mode 100644 index 2bd9e775ea..0000000000 Binary files a/components/esp_rom/test/logo.jpg and /dev/null differ diff --git a/components/esp_rom/test_apps/CMakeLists.txt b/components/esp_rom/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..5df555b801 --- /dev/null +++ b/components/esp_rom/test_apps/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_rom_test) diff --git a/components/esp_rom/test_apps/README.md b/components/esp_rom/test_apps/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/esp_rom/test_apps/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp_rom/test_apps/main/CMakeLists.txt b/components/esp_rom/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000000..1a8ffc6092 --- /dev/null +++ b/components/esp_rom/test_apps/main/CMakeLists.txt @@ -0,0 +1,8 @@ +set(srcs "test_app_main.c" + "test_libgcc.c" + "test_miniz.c") + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE +idf_component_register(SRCS ${srcs} + WHOLE_ARCHIVE) diff --git a/components/esp_rom/test_apps/main/test_app_main.c b/components/esp_rom/test_apps/main/test_app_main.c new file mode 100644 index 0000000000..f739ea079f --- /dev/null +++ b/components/esp_rom/test_apps/main/test_app_main.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +#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) +{ + unity_run_menu(); +} diff --git a/components/esp_rom/test/test_libgcc.c b/components/esp_rom/test_apps/main/test_libgcc.c similarity index 98% rename from components/esp_rom/test/test_libgcc.c rename to components/esp_rom/test_apps/main/test_libgcc.c index 143b06a1aa..d3b84a876f 100644 --- a/components/esp_rom/test/test_libgcc.c +++ b/components/esp_rom/test_apps/main/test_libgcc.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include "unity.h" diff --git a/components/esp_rom/test/test_miniz.c b/components/esp_rom/test_apps/main/test_miniz.c similarity index 86% rename from components/esp_rom/test/test_miniz.c rename to components/esp_rom/test_apps/main/test_miniz.c index 4744aba6a9..e5c34e6911 100644 --- a/components/esp_rom/test/test_miniz.c +++ b/components/esp_rom/test_apps/main/test_miniz.c @@ -1,27 +1,17 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include #include #include #include "sdkconfig.h" #include "unity.h" +#include "rom/miniz.h" -// compression/decompression will take off a bunch of memory -// test it only with PSRAM enabled -#ifdef CONFIG_SPIRAM - -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) -// miniz unit test can't pass on ESP32 non-ECO3 version IDF-1807 - -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/miniz.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/miniz.h" -#else -#error "unsupported target" -#endif - - -#define DATASIZE (1024 * 64) +#define DATASIZE (1024 * 32) TEST_CASE("Test miniz compression/decompression", "[rom][miniz]") { @@ -101,6 +91,3 @@ TEST_CASE("Test miniz compression/decompression", "[rom][miniz]") free(outbuf); free(decomp); } - -#endif //#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) -#endif // CONFIG_SPIRAM diff --git a/components/esp_rom/test_apps/pytest_esp_rom.py b/components/esp_rom/test_apps/pytest_esp_rom.py new file mode 100644 index 0000000000..9ddf838c2b --- /dev/null +++ b/components/esp_rom/test_apps/pytest_esp_rom.py @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32c3 +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.generic +@pytest.mark.nightly_run +def test_esp_rom(dut: Dut) -> None: + dut.expect('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output() diff --git a/components/esp_rom/test_apps/sdkconfig.defaults b/components/esp_rom/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/esp_rom/test_apps/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 72a2c93879..1bc68a1ce6 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 mdns mqtt newlib nvs_flash partition_table sdmmc spiffs +TEST_COMPONENTS=app_trace console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf 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 d516eea21d..475aaf583a 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 mdns mqtt newlib nvs_flash partition_table sdmmc spiffs freertos esp_hw_support esp_ipc esp_system esp_timer driver heap soc spi_flash vfs +TEST_EXCLUDE_COMPONENTS=app_trace console efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf 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 soc spi_flash vfs