From 9f6e433bb5b9c0dfb21993b5a65b9d232b8c25a2 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Mon, 17 Oct 2022 10:40:46 +0530 Subject: [PATCH] ci: Migrate app_update unit tests from unit-test-app to component-test-app --- .gitlab/ci/target-test.yml | 12 +- .../app_update/test_apps/CMakeLists.txt | 7 ++ components/app_update/test_apps/README.md | 3 + .../{test => test_apps/main}/CMakeLists.txt | 2 +- .../app_update/test_apps/main/app_main.c | 16 +++ .../{test => test_apps/main}/test_ota_ops.c | 0 .../main}/test_switch_ota.c | 109 ++++++++++-------- .../partition_table_unit_test_two_ota.csv | 11 ++ .../partition_table_unit_test_two_ota_2m.csv | 11 ++ .../test_apps/pytest_app_update_ut.py | 31 +++++ .../app_update/test_apps/sdkconfig.defaults | 18 +++ .../test_apps/sdkconfig.defaults.esp32 | 7 ++ .../test_apps/sdkconfig.defaults.esp32c2 | 5 + .../test_apps/sdkconfig.defaults.esp32c3 | 2 + .../test_apps/sdkconfig.defaults.esp32s2 | 2 + tools/unit-test-app/configs/app_update | 15 --- tools/unit-test-app/configs/app_update_c2 | 15 --- tools/unit-test-app/configs/app_update_c3 | 15 --- tools/unit-test-app/configs/app_update_s2 | 15 --- tools/unit-test-app/configs/bt | 1 - tools/unit-test-app/configs/default_2 | 2 +- tools/unit-test-app/configs/default_2_c3 | 2 +- tools/unit-test-app/configs/default_2_s2 | 2 +- tools/unit-test-app/configs/default_2_s3 | 2 +- tools/unit-test-app/configs/psram | 2 +- tools/unit-test-app/configs/release_2 | 2 +- tools/unit-test-app/configs/release_2_s2 | 2 +- tools/unit-test-app/configs/single_core_2 | 2 +- tools/unit-test-app/configs/single_core_2_s2 | 2 +- 29 files changed, 187 insertions(+), 128 deletions(-) create mode 100644 components/app_update/test_apps/CMakeLists.txt create mode 100644 components/app_update/test_apps/README.md rename components/app_update/{test => test_apps/main}/CMakeLists.txt (86%) create mode 100644 components/app_update/test_apps/main/app_main.c rename components/app_update/{test => test_apps/main}/test_ota_ops.c (100%) rename components/app_update/{test => test_apps/main}/test_switch_ota.c (93%) create mode 100644 components/app_update/test_apps/partition_table_unit_test_two_ota.csv create mode 100644 components/app_update/test_apps/partition_table_unit_test_two_ota_2m.csv create mode 100644 components/app_update/test_apps/pytest_app_update_ut.py create mode 100644 components/app_update/test_apps/sdkconfig.defaults create mode 100644 components/app_update/test_apps/sdkconfig.defaults.esp32 create mode 100644 components/app_update/test_apps/sdkconfig.defaults.esp32c2 create mode 100644 components/app_update/test_apps/sdkconfig.defaults.esp32c3 create mode 100644 components/app_update/test_apps/sdkconfig.defaults.esp32s2 delete mode 100644 tools/unit-test-app/configs/app_update delete mode 100644 tools/unit-test-app/configs/app_update_c2 delete mode 100644 tools/unit-test-app/configs/app_update_c3 delete mode 100644 tools/unit-test-app/configs/app_update_s2 diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 7c88ecdd3b..0c033bf0cb 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -901,7 +901,7 @@ test_app_test_eth: UT_001: extends: .unit_test_esp32_template - parallel: 42 + parallel: 40 tags: - ESP32_IDF - UT_T1_1 @@ -910,7 +910,7 @@ UT_001: UT_002: extends: .unit_test_esp32_template - parallel: 15 + parallel: 14 tags: - ESP32_IDF - UT_T1_1 @@ -1000,7 +1000,7 @@ UT_034: UT_035: extends: .unit_test_esp32s2_template - parallel: 43 + parallel: 41 tags: - ESP32S2_IDF - UT_T1_1 @@ -1088,7 +1088,7 @@ UT_S2_SDSPI: UT_C2: extends: .unit_test_esp32c2_template - parallel: 19 + parallel: 17 tags: - ESP32C2_IDF - UT_T1_1 @@ -1120,7 +1120,7 @@ UT_C2_FLASH: UT_C3: extends: .unit_test_esp32c3_template - parallel: 26 + parallel: 24 tags: - ESP32C3_IDF - UT_T1_1 @@ -1157,7 +1157,7 @@ UT_C3_SDSPI: UT_S3: extends: .unit_test_esp32s3_template - parallel: 24 + parallel: 22 tags: - ESP32S3_IDF - UT_T1_1 diff --git a/components/app_update/test_apps/CMakeLists.txt b/components/app_update/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..3253e2231a --- /dev/null +++ b/components/app_update/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(app_update_test) diff --git a/components/app_update/test_apps/README.md b/components/app_update/test_apps/README.md new file mode 100644 index 0000000000..27995c13b2 --- /dev/null +++ b/components/app_update/test_apps/README.md @@ -0,0 +1,3 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | + diff --git a/components/app_update/test/CMakeLists.txt b/components/app_update/test_apps/main/CMakeLists.txt similarity index 86% rename from components/app_update/test/CMakeLists.txt rename to components/app_update/test_apps/main/CMakeLists.txt index 7afb247dc9..45e4edf674 100644 --- a/components/app_update/test/CMakeLists.txt +++ b/components/app_update/test_apps/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." PRIV_REQUIRES cmock test_utils app_update bootloader_support nvs_flash driver - ) + WHOLE_ARCHIVE) target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/app_update/test_apps/main/app_main.c b/components/app_update/test_apps/main/app_main.c new file mode 100644 index 0000000000..8b86afaf47 --- /dev/null +++ b/components/app_update/test_apps/main/app_main.c @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include "unity.h" +#include "nvs_flash.h" +#include "nvs.h" +#include "esp_err.h" + +void app_main(void) +{ + ESP_ERROR_CHECK(nvs_flash_init()); + unity_run_menu(); + ESP_ERROR_CHECK(nvs_flash_deinit()); +} diff --git a/components/app_update/test/test_ota_ops.c b/components/app_update/test_apps/main/test_ota_ops.c similarity index 100% rename from components/app_update/test/test_ota_ops.c rename to components/app_update/test_apps/main/test_ota_ops.c diff --git a/components/app_update/test/test_switch_ota.c b/components/app_update/test_apps/main/test_switch_ota.c similarity index 93% rename from components/app_update/test/test_switch_ota.c rename to components/app_update/test_apps/main/test_switch_ota.c index 9689ef5469..f65ee568a6 100644 --- a/components/app_update/test/test_switch_ota.c +++ b/components/app_update/test_apps/main/test_switch_ota.c @@ -23,6 +23,7 @@ #include "bootloader_common.h" #include "../bootloader_flash/include/bootloader_flash_priv.h" +#include "esp_err.h" #include "esp_log.h" #include "esp_ota_ops.h" #include "esp_partition.h" @@ -34,13 +35,32 @@ #include "esp_sleep.h" #include "test_utils.h" - -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5131 -RTC_DATA_ATTR static int boot_count = 0; +#define BOOT_COUNT_NAMESPACE "boot_count" static const char *TAG = "ota_test"; +static void set_boot_count_in_nvs(uint8_t boot_count) +{ + nvs_handle_t boot_count_handle; + TEST_ESP_OK(nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle)); + TEST_ESP_OK(nvs_set_u8(boot_count_handle, "boot_count", boot_count)); + TEST_ESP_OK(nvs_commit(boot_count_handle)); + nvs_close(boot_count_handle); +} + +static uint8_t get_boot_count_from_nvs(void) +{ + nvs_handle_t boot_count_handle; + esp_err_t err = nvs_open(BOOT_COUNT_NAMESPACE, NVS_READONLY, &boot_count_handle); + if (err == ESP_ERR_NVS_NOT_FOUND) { + set_boot_count_in_nvs(0); + } + uint8_t boot_count; + TEST_ESP_OK(nvs_get_u8(boot_count_handle, "boot_count", &boot_count)); + nvs_close(boot_count_handle); + return boot_count; +} + /* @brief Copies a current app to next partition using handle. * * @param[in] update_handle - Handle of API ota. @@ -313,7 +333,7 @@ static void mark_app_valid(void) static void start_test(void) { ESP_LOGI(TAG, "boot count 1 - reset"); - boot_count = 1; + set_boot_count_in_nvs(1); erase_ota_data(); ESP_LOGI(TAG, "ota_data erased"); reboot_as_deep_sleep(); @@ -321,7 +341,9 @@ static void start_test(void) static void test_flow1(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { @@ -364,7 +386,9 @@ TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, OTA1, OTA0", "[app_u static void test_flow2(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { @@ -401,7 +425,9 @@ TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, corrupt ota_sec1, fa static void test_flow3(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { @@ -441,64 +467,36 @@ static void test_flow3(void) // 3 Stage: run OTA0 -> check it -> copy OTA0 to OTA1 -> reboot --//-- // 3 Stage: run OTA1 -> check it -> corrupt ota sector2 -> reboot --//-- // 4 Stage: run OTA0 -> check it -> erase OTA_DATA for next tests -> PASS -TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, OTA1, currupt ota_sec2, OTA0", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow3, test_flow3, test_flow3, test_flow3); +TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, OTA1, corrupt ota_sec2, OTA0", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow3, test_flow3, test_flow3, test_flow3); #ifdef CONFIG_BOOTLOADER_FACTORY_RESET -#define STORAGE_NAMESPACE "update_ota" - static void test_flow4(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); - nvs_handle_t handle = 0; - int32_t boot_count_nvs = 0; switch (boot_count) { case 2: ESP_LOGI(TAG, "Factory"); TEST_ASSERT_EQUAL(ESP_PARTITION_SUBTYPE_APP_FACTORY, cur_app->subtype); - - TEST_ESP_OK(nvs_flash_erase()); - TEST_ESP_OK(nvs_flash_init()); - TEST_ESP_OK(nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &handle)); - TEST_ESP_OK(nvs_set_i32(handle, "boot_count", boot_count)); - TEST_ESP_OK(nvs_commit(handle)); - nvs_close(handle); - nvs_flash_deinit(); - copy_current_app_to_next_part_and_reboot(); break; case 3: ESP_LOGI(TAG, "OTA0"); TEST_ASSERT_EQUAL(ESP_PARTITION_SUBTYPE_APP_OTA_0, cur_app->subtype); mark_app_valid(); - TEST_ESP_OK(nvs_flash_init()); - TEST_ESP_OK(nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &handle)); - TEST_ESP_OK(nvs_get_i32(handle, "boot_count", &boot_count_nvs)); - TEST_ASSERT_EQUAL(boot_count_nvs + 1, boot_count); - nvs_close(handle); - nvs_flash_deinit(); - set_output_pin(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET); - - reboot_as_deep_sleep(); + esp_restart(); break; case 4: reset_output_pin(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET); ESP_LOGI(TAG, "Factory"); TEST_ASSERT_EQUAL(ESP_PARTITION_SUBTYPE_APP_FACTORY, cur_app->subtype); - - int32_t boot_count_nvs; - TEST_ESP_OK(nvs_flash_init()); - TEST_ESP_OK(nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &handle)); - TEST_ESP_ERR(ESP_ERR_NVS_NOT_FOUND, nvs_get_i32(handle, "boot_count", &boot_count_nvs)); - nvs_close(handle); - nvs_flash_deinit(); - erase_ota_data(); break; default: - reset_output_pin(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET); erase_ota_data(); TEST_FAIL_MESSAGE("Unexpected stage"); break; @@ -506,33 +504,32 @@ static void test_flow4(void) } // 1 Stage: After POWER_RESET erase OTA_DATA for this test -> reboot through deep sleep. // 2 Stage: run factory -> check it -> copy factory to OTA0 -> reboot --//-- -// 3 Stage: run OTA0 -> check it -> set_pin_factory_reset -> reboot --//-- +// 3 Stage: run OTA0 -> check it -> set_pin_factory_reset -> reboot // 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS -TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4); +TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, SW_CPU_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4); #endif #ifdef CONFIG_BOOTLOADER_APP_TEST static void test_flow5(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { case 2: ESP_LOGI(TAG, "Factory"); TEST_ASSERT_EQUAL(ESP_PARTITION_SUBTYPE_APP_FACTORY, cur_app->subtype); - set_output_pin(CONFIG_BOOTLOADER_NUM_PIN_APP_TEST); - copy_partition(esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_TEST, NULL), cur_app); - esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); - reboot_as_deep_sleep(); + esp_restart(); break; case 3: reset_output_pin(CONFIG_BOOTLOADER_NUM_PIN_APP_TEST); ESP_LOGI(TAG, "Test"); TEST_ASSERT_EQUAL(ESP_PARTITION_SUBTYPE_APP_TEST, cur_app->subtype); - reboot_as_deep_sleep(); + esp_restart(); break; case 4: ESP_LOGI(TAG, "Factory"); @@ -548,10 +545,10 @@ static void test_flow5(void) } // 1 Stage: After POWER_RESET erase OTA_DATA for this test -> reboot through deep sleep. -// 2 Stage: run factory -> check it -> copy factory to Test and set pin_test_app -> reboot --//-- -// 3 Stage: run test -> check it -> reset pin_test_app -> reboot --//-- +// 2 Stage: run factory -> check it -> copy factory to Test and set pin_test_app -> reboot +// 3 Stage: run test -> check it -> reset pin_test_app -> reboot // 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS -TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5); +TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][reset=SW_CPU_RESET, SW_CPU_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5); #endif static const esp_partition_t* app_update(void) @@ -570,7 +567,9 @@ static const esp_partition_t* app_update(void) static void test_rollback1(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); esp_ota_img_states_t ota_state = 0x5555AAAA; @@ -621,8 +620,9 @@ static void test_rollback1(void) static void test_rollback1_1(void) { - boot_count = 5; + set_boot_count_in_nvs(5); esp_ota_img_states_t ota_state = 0x5555AAAA; + uint8_t boot_count = get_boot_count_from_nvs(); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); ESP_LOGI(TAG, "Factory"); @@ -649,7 +649,9 @@ TEST_CASE_MULTIPLE_STAGES("Test rollback. factory, OTA0, OTA0, rollback -> facto static void test_rollback2(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); esp_ota_img_states_t ota_state = 0x5555AAAA; @@ -714,7 +716,8 @@ static void test_rollback2(void) static void test_rollback2_1(void) { - boot_count = 5; + set_boot_count_in_nvs(5); + uint8_t boot_count = get_boot_count_from_nvs(); esp_ota_img_states_t ota_state = 0x5555AAAA; ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); @@ -747,7 +750,9 @@ TEST_CASE_MULTIPLE_STAGES("Test rollback. factory, OTA0, OTA1, rollback -> OTA0" static void test_erase_last_app_flow(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { @@ -780,7 +785,8 @@ static void test_erase_last_app_flow(void) static void test_erase_last_app_rollback(void) { - boot_count = 5; + set_boot_count_in_nvs(5); + uint8_t boot_count = get_boot_count_from_nvs(); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); ESP_LOGI(TAG, "erase_last_app"); @@ -798,7 +804,9 @@ TEST_CASE_MULTIPLE_STAGES("Test erase_last_boot_app_partition. factory, OTA1, OT static void test_flow6(void) { + uint8_t boot_count = get_boot_count_from_nvs(); boot_count++; + set_boot_count_in_nvs(boot_count); ESP_LOGI(TAG, "boot count %d", boot_count); const esp_partition_t *cur_app = get_running_firmware(); switch (boot_count) { @@ -847,4 +855,3 @@ TEST_CASE("Test bootloader_common_get_sha256_of_partition returns ESP_ERR_IMAGE_ TEST_ESP_ERR(ESP_ERR_IMAGE_INVALID, bootloader_common_get_sha256_of_partition(other_app->address, other_app->size, other_app->type, sha_256_other_app)); TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha_256_cur_app, sha_256_other_app, sizeof(sha_256_cur_app), "must be the same"); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) diff --git a/components/app_update/test_apps/partition_table_unit_test_two_ota.csv b/components/app_update/test_apps/partition_table_unit_test_two_ota.csv new file mode 100644 index 0000000000..e1bcc931c0 --- /dev/null +++ b/components/app_update/test_apps/partition_table_unit_test_two_ota.csv @@ -0,0 +1,11 @@ +# Special partition table for unit test app_update +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, , 0x4000 +otadata, data, ota, , 0x2000 +phy_init, data, phy, , 0x1000 +factory, 0, 0, , 0xB0000 +ota_0, 0, ota_0, , 0xB0000 +ota_1, 0, ota_1, , 0xB0000 +test, 0, test, , 0xB0000 +# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests +flash_test, data, fat, , 528K diff --git a/components/app_update/test_apps/partition_table_unit_test_two_ota_2m.csv b/components/app_update/test_apps/partition_table_unit_test_two_ota_2m.csv new file mode 100644 index 0000000000..9c097b4fad --- /dev/null +++ b/components/app_update/test_apps/partition_table_unit_test_two_ota_2m.csv @@ -0,0 +1,11 @@ +# Special partition table for unit test app_update +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, , 0x4000 +otadata, data, ota, , 0x2000 +phy_init, data, phy, , 0x1000 +factory, 0, 0, , 0x70000 +ota_0, 0, ota_0, , 0x70000 +ota_1, 0, ota_1, , 0x70000 +test, 0, test, , 0x70000 +# flash_test partition used for SPI flash tests, WL FAT tests, and SPIFFS tests +flash_test, data, fat, , 128K diff --git a/components/app_update/test_apps/pytest_app_update_ut.py b/components/app_update/test_apps/pytest_app_update_ut.py new file mode 100644 index 0000000000..e30eec250c --- /dev/null +++ b/components/app_update/test_apps/pytest_app_update_ut.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR 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') + + +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.supported_targets +@pytest.mark.generic +def test_app_update(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/app_update/test_apps/sdkconfig.defaults b/components/app_update/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..fb3ea86119 --- /dev/null +++ b/components/app_update/test_apps/sdkconfig.defaults @@ -0,0 +1,18 @@ +# 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 + +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota.csv" +CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota.csv" + +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_OFFSET=0x18000 +CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 +CONFIG_BOOTLOADER_OTA_DATA_ERASE=y diff --git a/components/app_update/test_apps/sdkconfig.defaults.esp32 b/components/app_update/test_apps/sdkconfig.defaults.esp32 new file mode 100644 index 0000000000..e515c9dc11 --- /dev/null +++ b/components/app_update/test_apps/sdkconfig.defaults.esp32 @@ -0,0 +1,7 @@ +CONFIG_IDF_TARGET="esp32" +CONFIG_BOOTLOADER_FACTORY_RESET=y +CONFIG_BOOTLOADER_APP_TEST=y +CONFIG_BOOTLOADER_DATA_FACTORY_RESET="" +CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=32 +CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=4 +CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 diff --git a/components/app_update/test_apps/sdkconfig.defaults.esp32c2 b/components/app_update/test_apps/sdkconfig.defaults.esp32c2 new file mode 100644 index 0000000000..defbe6ce10 --- /dev/null +++ b/components/app_update/test_apps/sdkconfig.defaults.esp32c2 @@ -0,0 +1,5 @@ +CONFIG_IDF_TARGET="esp32c2" +CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota_2m.csv" +CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota_2m.csv" +CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/components/app_update/test_apps/sdkconfig.defaults.esp32c3 b/components/app_update/test_apps/sdkconfig.defaults.esp32c3 new file mode 100644 index 0000000000..30e434ceb1 --- /dev/null +++ b/components/app_update/test_apps/sdkconfig.defaults.esp32c3 @@ -0,0 +1,2 @@ +CONFIG_IDF_TARGET="esp32c3" +CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/components/app_update/test_apps/sdkconfig.defaults.esp32s2 b/components/app_update/test_apps/sdkconfig.defaults.esp32s2 new file mode 100644 index 0000000000..a485a1603b --- /dev/null +++ b/components/app_update/test_apps/sdkconfig.defaults.esp32s2 @@ -0,0 +1,2 @@ +CONFIG_IDF_TARGET="esp32s2" +CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/tools/unit-test-app/configs/app_update b/tools/unit-test-app/configs/app_update deleted file mode 100644 index ce9e904286..0000000000 --- a/tools/unit-test-app/configs/app_update +++ /dev/null @@ -1,15 +0,0 @@ -# This config is split between targets since different component needs to be excluded (esp32, esp32s2) -CONFIG_IDF_TARGET="esp32" -TEST_COMPONENTS=app_update -TEST_EXCLUDE_COMPONENTS=bt -CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x18000 -CONFIG_BOOTLOADER_FACTORY_RESET=y -CONFIG_BOOTLOADER_APP_TEST=y -CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 -CONFIG_BOOTLOADER_OTA_DATA_ERASE=y -CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=4 -CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=32 diff --git a/tools/unit-test-app/configs/app_update_c2 b/tools/unit-test-app/configs/app_update_c2 deleted file mode 100644 index c912e5627f..0000000000 --- a/tools/unit-test-app/configs/app_update_c2 +++ /dev/null @@ -1,15 +0,0 @@ -# This config is split between targets since different component needs to be excluded (esp32, esp32s2) -CONFIG_IDF_TARGET="esp32c2" -TEST_COMPONENTS=app_update -TEST_EXCLUDE_COMPONENTS=bt -CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota_2m.csv" -CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota_2m.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x18000 -CONFIG_BOOTLOADER_FACTORY_RESET=y -CONFIG_BOOTLOADER_APP_TEST=y -CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 -CONFIG_BOOTLOADER_OTA_DATA_ERASE=y -CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=4 -CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/tools/unit-test-app/configs/app_update_c3 b/tools/unit-test-app/configs/app_update_c3 deleted file mode 100644 index c9505767fb..0000000000 --- a/tools/unit-test-app/configs/app_update_c3 +++ /dev/null @@ -1,15 +0,0 @@ -# This config is split between targets since different component needs to be excluded (esp32, esp32s2) -CONFIG_IDF_TARGET="esp32c3" -TEST_COMPONENTS=app_update -TEST_EXCLUDE_COMPONENTS=bt -CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x18000 -CONFIG_BOOTLOADER_FACTORY_RESET=y -CONFIG_BOOTLOADER_APP_TEST=y -CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 -CONFIG_BOOTLOADER_OTA_DATA_ERASE=y -CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=4 -CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/tools/unit-test-app/configs/app_update_s2 b/tools/unit-test-app/configs/app_update_s2 deleted file mode 100644 index 47343aaa44..0000000000 --- a/tools/unit-test-app/configs/app_update_s2 +++ /dev/null @@ -1,15 +0,0 @@ -# This config is split between targets since different component needs to be excluded (esp32, esp32s2) -CONFIG_IDF_TARGET="esp32s2" -TEST_COMPONENTS=app_update -TEST_EXCLUDE_COMPONENTS=bt -CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_FILENAME="partition_table_unit_test_two_ota.csv" -CONFIG_PARTITION_TABLE_OFFSET=0x18000 -CONFIG_BOOTLOADER_FACTORY_RESET=y -CONFIG_BOOTLOADER_APP_TEST=y -CONFIG_BOOTLOADER_HOLD_TIME_GPIO=2 -CONFIG_BOOTLOADER_OTA_DATA_ERASE=y -CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET=4 -CONFIG_BOOTLOADER_NUM_PIN_APP_TEST=18 diff --git a/tools/unit-test-app/configs/bt b/tools/unit-test-app/configs/bt index bec4468a7e..f10c710c52 100644 --- a/tools/unit-test-app/configs/bt +++ b/tools/unit-test-app/configs/bt @@ -1,5 +1,4 @@ CONFIG_IDF_TARGET="esp32" TEST_COMPONENTS=bt -TEST_EXCLUDE_COMPONENTS=app_update CONFIG_BT_ENABLED=y CONFIG_UNITY_FREERTOS_STACK_SIZE=12288 diff --git a/tools/unit-test-app/configs/default_2 b/tools/unit-test-app/configs/default_2 index 4d29040218..630f9c0693 100644 --- a/tools/unit-test-app/configs/default_2 +++ b/tools/unit-test-app/configs/default_2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component diff --git a/tools/unit-test-app/configs/default_2_c3 b/tools/unit-test-app/configs/default_2_c3 index fe1fb57093..44504fc9a2 100644 --- a/tools/unit-test-app/configs/default_2_c3 +++ b/tools/unit-test-app/configs/default_2_c3 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded CONFIG_IDF_TARGET="esp32c3" -TEST_EXCLUDE_COMPONENTS=bt app_update esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver soc spi_flash vfs lwip experimental_cpp_component perfmon test_utils +TEST_EXCLUDE_COMPONENTS=bt esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon test_utils diff --git a/tools/unit-test-app/configs/default_2_s2 b/tools/unit-test-app/configs/default_2_s2 index 0654e9e024..fc5fc9cba0 100644 --- a/tools/unit-test-app/configs/default_2_s2 +++ b/tools/unit-test-app/configs/default_2_s2 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs experimental_cpp_component diff --git a/tools/unit-test-app/configs/default_2_s3 b/tools/unit-test-app/configs/default_2_s3 index dd1a42050f..dcc7249252 100644 --- a/tools/unit-test-app/configs/default_2_s3 +++ b/tools/unit-test-app/configs/default_2_s3 @@ -1,3 +1,3 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s3" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs experimental_cpp_component test_utils +TEST_EXCLUDE_COMPONENTS=bt freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs experimental_cpp_component test_utils diff --git a/tools/unit-test-app/configs/psram b/tools/unit-test-app/configs/psram index 0b5da79b5c..f550a59836 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 spi_flash test_utils soc experimental_cpp_component esp-tls freertos sdmmc +TEST_EXCLUDE_COMPONENTS=bt driver esp_hw_support esp_ipc esp_pm esp_system esp_timer spi_flash test_utils 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/release_2 b/tools/unit-test-app/configs/release_2 index da9ea704a4..b667b13bdf 100644 --- a/tools/unit-test-app/configs/release_2 +++ b/tools/unit-test-app/configs/release_2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be included (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/tools/unit-test-app/configs/release_2_s2 b/tools/unit-test-app/configs/release_2_s2 index baf847dfed..5354f78f96 100644 --- a/tools/unit-test-app/configs/release_2_s2 +++ b/tools/unit-test-app/configs/release_2_s2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/tools/unit-test-app/configs/single_core_2 b/tools/unit-test-app/configs/single_core_2 index bfa9e19bba..ade7034957 100644 --- a/tools/unit-test-app/configs/single_core_2 +++ b/tools/unit-test-app/configs/single_core_2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver soc spi_flash vfs test_utils experimental_cpp_component CONFIG_MEMMAP_SMP=n CONFIG_FREERTOS_UNICORE=y CONFIG_ESP32_RTCDATA_IN_FAST_MEM=y diff --git a/tools/unit-test-app/configs/single_core_2_s2 b/tools/unit-test-app/configs/single_core_2_s2 index f8ca87e765..c56816e445 100644 --- a/tools/unit-test-app/configs/single_core_2_s2 +++ b/tools/unit-test-app/configs/single_core_2_s2 @@ -1,6 +1,6 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_system esp_pm esp_timer driver soc spi_flash vfs experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt freertos esp_hw_support esp_ipc esp_system esp_pm esp_timer driver soc spi_flash vfs experimental_cpp_component CONFIG_MEMMAP_SMP=n CONFIG_FREERTOS_UNICORE=y CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM=y