diff --git a/components/bootloader_support/test/CMakeLists.txt b/components/bootloader_support/test/CMakeLists.txt deleted file mode 100644 index 16963ea6bb..0000000000 --- a/components/bootloader_support/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRC_DIRS "." - PRIV_INCLUDE_DIRS "." - PRIV_REQUIRES cmock bootloader_support app_update) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/bootloader_support/test_apps/bootloader_support/CMakeLists.txt b/components/bootloader_support/test_apps/bootloader_support/CMakeLists.txt new file mode 100644 index 0000000000..07ef465a67 --- /dev/null +++ b/components/bootloader_support/test_apps/bootloader_support/CMakeLists.txt @@ -0,0 +1,6 @@ +# 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) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(test_bootloader_support) diff --git a/components/bootloader_support/test_apps/bootloader_support/README.md b/components/bootloader_support/test_apps/bootloader_support/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/bootloader_support/test_apps/bootloader_support/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/bootloader_support/test_apps/bootloader_support/main/CMakeLists.txt b/components/bootloader_support/test_apps/bootloader_support/main/CMakeLists.txt new file mode 100644 index 0000000000..1d67beb656 --- /dev/null +++ b/components/bootloader_support/test_apps/bootloader_support/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "test_app_main.c" "test_verify_image.c" + INCLUDE_DIRS "." + WHOLE_ARCHIVE) diff --git a/components/bootloader_support/test_apps/bootloader_support/main/test_app_main.c b/components/bootloader_support/test_apps/bootloader_support/main/test_app_main.c new file mode 100644 index 0000000000..52a9e14b82 --- /dev/null +++ b/components/bootloader_support/test_apps/bootloader_support/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 bootloader support code, the threshold is left for that case +#define TEST_MEMORY_LEAK_THRESHOLD (-550) + +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 bootloader support component tests\n"); + unity_run_menu(); +} diff --git a/components/bootloader_support/test/test_verify_image.c b/components/bootloader_support/test_apps/bootloader_support/main/test_verify_image.c similarity index 97% rename from components/bootloader_support/test/test_verify_image.c rename to components/bootloader_support/test_apps/bootloader_support/main/test_verify_image.c index a73a8d10f1..1313c03e6e 100644 --- a/components/bootloader_support/test/test_verify_image.c +++ b/components/bootloader_support/test_apps/bootloader_support/main/test_verify_image.c @@ -37,8 +37,6 @@ TEST_CASE("Verify bootloader image in flash", "[bootloader_support]") TEST_ASSERT_EQUAL(data.image_len, bootloader_length); } -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5145 TEST_CASE("Verify unit test app image", "[bootloader_support]") { esp_image_metadata_t data = { 0 }; @@ -53,7 +51,6 @@ TEST_CASE("Verify unit test app image", "[bootloader_support]") TEST_ASSERT_NOT_EQUAL(0, data.image_len); TEST_ASSERT_TRUE(data.image_len <= running->size); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) void check_label_search (int num_test, const char *list, const char *t_label, bool result) { diff --git a/components/bootloader_support/test_apps/bootloader_support/pytest_bootloader_support.py b/components/bootloader_support/test_apps/bootloader_support/pytest_bootloader_support.py new file mode 100644 index 0000000000..ab6afdc475 --- /dev/null +++ b/components/bootloader_support/test_apps/bootloader_support/pytest_bootloader_support.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.generic +@pytest.mark.supported_targets +def test_bootloader_support(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=300) diff --git a/tools/unit-test-app/configs/default_2_c2 b/tools/unit-test-app/configs/default_2_c2 index a327c05f6d..ebb6bdf144 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 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 mbedtls 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_rom esp_wifi espcoredump hal lwip mbedtls 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 47d36b7bfa..da4a7937bb 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 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 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 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