diff --git a/components/esp_pm/.build-test-rules.yml b/components/esp_pm/.build-test-rules.yml new file mode 100644 index 0000000000..d55a544579 --- /dev/null +++ b/components/esp_pm/.build-test-rules.yml @@ -0,0 +1,7 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/esp_pm/test_apps/esp_pm: + disable: + - if: IDF_TARGET in ["esp32c6"] + temporary: true + reason: Not supported yet diff --git a/components/esp_pm/test/CMakeLists.txt b/components/esp_pm/test/CMakeLists.txt deleted file mode 100644 index 34851aeb16..0000000000 --- a/components/esp_pm/test/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRC_DIRS . - PRIV_REQUIRES unity esp_pm ulp driver esp_timer test_utils) diff --git a/components/esp_pm/test_apps/esp_pm/CMakeLists.txt b/components/esp_pm/test_apps/esp_pm/CMakeLists.txt new file mode 100644 index 0000000000..78b5424a0c --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/CMakeLists.txt @@ -0,0 +1,12 @@ +# 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(SDKCONFIG_DEFAULTS "$ENV{IDF_PATH}/tools/test_apps/configs/sdkconfig.debug_helpers") +list(APPEND SDKCONFIG_DEFAULTS "sdkconfig.defaults") + +# "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(test_esp_pm) diff --git a/components/esp_pm/test_apps/esp_pm/README.md b/components/esp_pm/test_apps/esp_pm/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp_pm/test_apps/esp_pm/main/CMakeLists.txt b/components/esp_pm/test_apps/esp_pm/main/CMakeLists.txt new file mode 100644 index 0000000000..5cab931963 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/main/CMakeLists.txt @@ -0,0 +1,9 @@ +set(sources "test_app_main.c" + "test_pm.c") + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component must be registered as a WHOLE_ARCHIVE +idf_component_register(SRCS ${sources} + INCLUDE_DIRS "." + PRIV_REQUIRES unity esp_pm ulp driver esp_timer + WHOLE_ARCHIVE) diff --git a/components/esp_pm/test_apps/esp_pm/main/test_app_main.c b/components/esp_pm/test_apps/esp_pm/main/test_app_main.c new file mode 100644 index 0000000000..4f05594ef8 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/main/test_app_main.c @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +// esp_timer_init() lazily allocates memory +#define TEST_MEMORY_LEAK_THRESHOLD (-512) + +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) +{ + // Add a short delay of 10ms to allow the idle task to free an remaining memory + vTaskDelay(pdMS_TO_TICKS(10)); + 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("ESP Power Manager Tests\n"); + unity_run_menu(); +} diff --git a/components/esp_pm/test/test_pm.c b/components/esp_pm/test_apps/esp_pm/main/test_pm.c similarity index 99% rename from components/esp_pm/test/test_pm.c rename to components/esp_pm/test_apps/esp_pm/main/test_pm.c index 2965a66a68..84c1b89273 100644 --- a/components/esp_pm/test/test_pm.c +++ b/components/esp_pm/test_apps/esp_pm/main/test_pm.c @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + #include #include #include @@ -19,7 +25,6 @@ #include "soc/rtc_periph.h" #include "esp_rom_sys.h" #include "esp_private/esp_clk.h" -#include "test_utils.h" #include "sdkconfig.h" diff --git a/components/esp_pm/test_apps/esp_pm/pytest_esp_pm.py b/components/esp_pm/test_apps/esp_pm/pytest_esp_pm.py new file mode 100644 index 0000000000..43e40cef55 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/pytest_esp_pm.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from pytest_embedded import Dut + +CONFIGS = [ + pytest.param('default', marks=[pytest.mark.supported_targets, pytest.mark.temp_skip_ci(targets=['esp32c6'], reason='c6 support TBD')]), + pytest.param('limits', marks=[pytest.mark.supported_targets, pytest.mark.temp_skip_ci(targets=['esp32c6'], reason='c6 support TBD')]), + pytest.param('options', marks=[pytest.mark.supported_targets, pytest.mark.temp_skip_ci(targets=['esp32c6'], reason='c6 support TBD')]), +] + + +@pytest.mark.generic +@pytest.mark.parametrize('config', CONFIGS, indirect=True) +def test_esp_pm(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output() diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.default b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.default new file mode 100644 index 0000000000..c149cb926f --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.default @@ -0,0 +1 @@ +# This is left intentionally blank. It inherits all configurations from sdkconfg.defaults diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.limits b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.limits new file mode 100644 index 0000000000..2aec98155c --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.limits @@ -0,0 +1,14 @@ +# Test configuration for limit testing esp_pm (i.e., maximizing various parameters such as speed, frequency etc) + +# Limit test esp_pm auto light sleep logic with faster ticks and faster code +CONFIG_FREERTOS_HZ=1000 +CONFIG_COMPILER_OPTIMIZATION_PERF=y +# Minimize the automatic light sleep entry threshold +CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=2 + +# Enable PM options for automatic sleeping and DFS +CONFIG_PM_DFS_INIT_AUTO=y +CONFIG_PM_SLP_DISABLE_GPIO=y + +# Limit test PM to see if it can XIP from flash +CONFIG_PM_SLP_IRAM_OPT=n diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.options b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.options new file mode 100644 index 0000000000..f11cadcdc6 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.ci.options @@ -0,0 +1,9 @@ +# Test configuration for enabling optional features that are supported on esp_pm. Tested on all targets + +# Enable optional features +CONFIG_PM_DFS_INIT_AUTO=y +CONFIG_PM_PROFILING=y +CONFIG_PM_TRACE=y +CONFIG_PM_SLP_IRAM_OPT=y +CONFIG_PM_RTOS_IDLE_OPT=y +CONFIG_PM_SLP_DISABLE_GPIO=y diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults new file mode 100644 index 0000000000..a96750cd3b --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults @@ -0,0 +1,8 @@ +# This "default" configuration is appended to all other configurations +# The contents of "sdkconfig.debug_helpers" is also appended to all other configurations (see CMakeLists.txt) +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_ESP_TASK_WDT_INIT=n + +# SMP FreeRTOS currently does not support power management IDF-4997 +CONFIG_FREERTOS_SMP=n diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32 b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32 new file mode 100644 index 0000000000..9c81fe7db1 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32 @@ -0,0 +1,4 @@ +# Target specific default configurations + +# Enable the ULP FSM to test it as a wake up source +CONFIG_ULP_COPROC_TYPE_FSM=y diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s2 b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s2 new file mode 100644 index 0000000000..9c81fe7db1 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s2 @@ -0,0 +1,4 @@ +# Target specific default configurations + +# Enable the ULP FSM to test it as a wake up source +CONFIG_ULP_COPROC_TYPE_FSM=y diff --git a/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s3 b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000000..9c81fe7db1 --- /dev/null +++ b/components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s3 @@ -0,0 +1,4 @@ +# Target specific default configurations + +# Enable the ULP FSM to test it as a wake up source +CONFIG_ULP_COPROC_TYPE_FSM=y diff --git a/tools/unit-test-app/configs/default_2 b/tools/unit-test-app/configs/default_2 index de0745572b..2a76134ebd 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 esp_pm esp_system driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system 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 4312d539df..54bedf8982 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 esp_pm esp_system driver soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon test_utils +TEST_EXCLUDE_COMPONENTS=bt esp_system 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 9ca23f8cdd..178dadce02 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 esp_pm esp_system driver soc spi_flash vfs experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system 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 c1c3ecc7eb..e8aacbb2c7 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 esp32s3 esp_pm esp_system driver soc spi_flash vfs experimental_cpp_component test_utils +TEST_EXCLUDE_COMPONENTS=bt esp32s3 esp_system driver soc spi_flash vfs experimental_cpp_component test_utils diff --git a/tools/unit-test-app/configs/pm b/tools/unit-test-app/configs/pm deleted file mode 100644 index f66688be84..0000000000 --- a/tools/unit-test-app/configs/pm +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_IDF_TARGET="esp32" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -CONFIG_ULP_COPROC_TYPE_FSM=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/pm_c2 b/tools/unit-test-app/configs/pm_c2 deleted file mode 100644 index 71d9b5ea46..0000000000 --- a/tools/unit-test-app/configs/pm_c2 +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_IDF_TARGET="esp32c2" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/pm_c3 b/tools/unit-test-app/configs/pm_c3 deleted file mode 100644 index 49abdde9de..0000000000 --- a/tools/unit-test-app/configs/pm_c3 +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_IDF_TARGET="esp32c3" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/pm_c6 b/tools/unit-test-app/configs/pm_c6 deleted file mode 100644 index 644e80ecc4..0000000000 --- a/tools/unit-test-app/configs/pm_c6 +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_IDF_TARGET="esp32c6" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/pm_s2 b/tools/unit-test-app/configs/pm_s2 deleted file mode 100644 index a4d89f0c75..0000000000 --- a/tools/unit-test-app/configs/pm_s2 +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_IDF_TARGET="esp32s2" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -CONFIG_ULP_COPROC_TYPE_FSM=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/pm_s3 b/tools/unit-test-app/configs/pm_s3 deleted file mode 100644 index 040e91451c..0000000000 --- a/tools/unit-test-app/configs/pm_s3 +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_IDF_TARGET="esp32s3" -TEST_COMPONENTS=esp_pm -CONFIG_PM_ENABLE=y -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -CONFIG_ULP_COPROC_TYPE_FSM=y -# SMP FreeRTOS currently does not support power management IDF-4997 -CONFIG_FREERTOS_SMP=n diff --git a/tools/unit-test-app/configs/psram b/tools/unit-test-app/configs/psram index aa9f15aa61..78257ede8d 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 driver esp_pm esp_system spi_flash test_utils soc experimental_cpp_component esp-tls sdmmc +TEST_EXCLUDE_COMPONENTS=bt driver esp_system spi_flash test_utils soc experimental_cpp_component esp-tls 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 02b93712ad..7cecfb413d 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 esp_pm esp_system driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system 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 b89097679c..8f6bd3d32e 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 esp_pm esp_system driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system 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 86d91baf86..bc0527e5fd 100644 --- a/tools/unit-test-app/configs/single_core_2 +++ b/tools/unit-test-app/configs/single_core_2 @@ -1,5 +1,5 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32" -TEST_EXCLUDE_COMPONENTS=bt esp_system esp_pm driver soc spi_flash vfs test_utils experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system driver soc spi_flash vfs test_utils experimental_cpp_component 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 bf26adbb94..d434854c49 100644 --- a/tools/unit-test-app/configs/single_core_2_s2 +++ b/tools/unit-test-app/configs/single_core_2_s2 @@ -1,5 +1,5 @@ # This config is split between targets since different component needs to be excluded (esp32, esp32s2) CONFIG_IDF_TARGET="esp32s2" -TEST_EXCLUDE_COMPONENTS=bt esp_system esp_pm driver soc spi_flash vfs experimental_cpp_component +TEST_EXCLUDE_COMPONENTS=bt esp_system driver soc spi_flash vfs experimental_cpp_component CONFIG_FREERTOS_UNICORE=y CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM=y