diff --git a/components/esp_app_format/test/CMakeLists.txt b/components/esp_app_format/test/CMakeLists.txt deleted file mode 100644 index 5f8813fa5c..0000000000 --- a/components/esp_app_format/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRC_DIRS "." - PRIV_INCLUDE_DIRS "." - PRIV_REQUIRES cmock test_utils app_update bootloader_support nvs_flash driver - ) diff --git a/components/esp_app_format/test_apps/CMakeLists.txt b/components/esp_app_format/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..3ec91ae10d --- /dev/null +++ b/components/esp_app_format/test_apps/CMakeLists.txt @@ -0,0 +1,8 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +# "Trim" the build. Include the minimal set of components, main, and anything it depends on. +set(COMPONENTS main) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(esp_app_format_test) diff --git a/components/esp_app_format/test_apps/README.md b/components/esp_app_format/test_apps/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/esp_app_format/test_apps/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp_app_format/test_apps/main/CMakeLists.txt b/components/esp_app_format/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000000..9c31d04cdf --- /dev/null +++ b/components/esp_app_format/test_apps/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "test_app_desc.c" + PRIV_INCLUDE_DIRS . + PRIV_REQUIRES esp_app_format unity) diff --git a/components/esp_app_format/test/test_app_desc.c b/components/esp_app_format/test_apps/main/test_app_desc.c similarity index 72% rename from components/esp_app_format/test/test_app_desc.c rename to components/esp_app_format/test_apps/main/test_app_desc.c index af87a9b97f..99992702f0 100644 --- a/components/esp_app_format/test/test_app_desc.c +++ b/components/esp_app_format/test_apps/main/test_app_desc.c @@ -3,11 +3,24 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include #include + #include "esp_app_desc.h" #include "unity.h" +#include "unity_fixture.h" -TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]") +TEST_GROUP(esp_app_format); + +TEST_SETUP(esp_app_format) +{ +} + +TEST_TEAR_DOWN(esp_app_format) +{ +} + +TEST(esp_app_format, esp_app_get_elf_sha256_test) { const int sha256_hex_len = CONFIG_APP_RETRIEVE_LEN_ELF_SHA; char dst[sha256_hex_len + 2]; @@ -16,17 +29,17 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]") size_t len; char ref_sha256[sha256_hex_len + 1]; - const esp_app_desc_t* desc = esp_get_app_description(); + const esp_app_desc_t* desc = esp_app_get_description(); for (int i = 0; i < sizeof(ref_sha256) / 2; ++i) { snprintf(ref_sha256 + 2*i, 3, "%02x", desc->app_elf_sha256[i]); } ref_sha256[sha256_hex_len] = 0; - printf("Ref: %s\n", ref_sha256); + printf("\nRef: %s\n", ref_sha256); memset(dst, fill, sizeof(dst)); len = sizeof(dst); - res = esp_get_app_elf_sha256(dst, len); + res = esp_app_get_elf_sha256(dst, len); printf("%d: %s (%d)\n", len, dst, res); TEST_ASSERT_EQUAL(sha256_hex_len + 1, res); TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1)); @@ -35,7 +48,7 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]") memset(dst, fill, sizeof(dst)); len = 9; - res = esp_get_app_elf_sha256(dst, len); + res = esp_app_get_elf_sha256(dst, len); printf("%d: %s (%d)\n", len, dst, res); TEST_ASSERT_EQUAL(9, res); TEST_ASSERT_EQUAL(0, memcmp(dst, ref_sha256, res - 1)); @@ -44,7 +57,7 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]") memset(dst, fill, sizeof(dst)); len = 8; - res = esp_get_app_elf_sha256(dst, len); + res = esp_app_get_elf_sha256(dst, len); printf("%d: %s (%d)\n", len, dst, res); // should output even number of characters plus '\0' TEST_ASSERT_EQUAL(7, res); @@ -53,3 +66,13 @@ TEST_CASE("esp_get_app_elf_sha256 test", "[esp_app_desc]") TEST_ASSERT_EQUAL_HEX(fill, dst[7]); TEST_ASSERT_EQUAL_HEX(fill, dst[8]); } + +TEST_GROUP_RUNNER(esp_app_format) +{ + RUN_TEST_CASE(esp_app_format, esp_app_get_elf_sha256_test) +} + +void app_main(void) +{ + UNITY_MAIN(esp_app_format); +} diff --git a/components/esp_app_format/test_apps/pytest_esp_app_format.py b/components/esp_app_format/test_apps/pytest_esp_app_format.py new file mode 100644 index 0000000000..6c10ccd929 --- /dev/null +++ b/components/esp_app_format/test_apps/pytest_esp_app_format.py @@ -0,0 +1,11 @@ +# 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_esp_app_format(dut: Dut) -> None: + dut.expect_unity_test_output() diff --git a/components/esp_app_format/test_apps/sdkconfig.defaults b/components/esp_app_format/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..a3253f171f --- /dev/null +++ b/components/esp_app_format/test_apps/sdkconfig.defaults @@ -0,0 +1,11 @@ +# 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 + +# Enable Unity fixture support +CONFIG_UNITY_ENABLE_FIXTURE=y +CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n