Преглед изворни кода

esp_pm: Migrate unit tests to test app

This commit migrates the esp_pm unit tests from the legacy unit test to a
stand alone test app. The following CI configurations are provided

- Default: Automatic light sleep with mostly default configurations
- Options: Enables all of the optional esp_pm features
- Limits: Limit tests esp_pm
Darian Leung пре 3 година
родитељ
комит
412b09abf4
30 измењених фајлова са 154 додато и 51 уклоњено
  1. 7 0
      components/esp_pm/.build-test-rules.yml
  2. 0 2
      components/esp_pm/test/CMakeLists.txt
  3. 12 0
      components/esp_pm/test_apps/esp_pm/CMakeLists.txt
  4. 2 0
      components/esp_pm/test_apps/esp_pm/README.md
  5. 9 0
      components/esp_pm/test_apps/esp_pm/main/CMakeLists.txt
  6. 46 0
      components/esp_pm/test_apps/esp_pm/main/test_app_main.c
  7. 6 1
      components/esp_pm/test_apps/esp_pm/main/test_pm.c
  8. 19 0
      components/esp_pm/test_apps/esp_pm/pytest_esp_pm.py
  9. 1 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.ci.default
  10. 14 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.ci.limits
  11. 9 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.ci.options
  12. 8 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.defaults
  13. 4 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32
  14. 4 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s2
  15. 4 0
      components/esp_pm/test_apps/esp_pm/sdkconfig.defaults.esp32s3
  16. 1 1
      tools/unit-test-app/configs/default_2
  17. 1 1
      tools/unit-test-app/configs/default_2_c3
  18. 1 1
      tools/unit-test-app/configs/default_2_s2
  19. 1 1
      tools/unit-test-app/configs/default_2_s3
  20. 0 7
      tools/unit-test-app/configs/pm
  21. 0 6
      tools/unit-test-app/configs/pm_c2
  22. 0 6
      tools/unit-test-app/configs/pm_c3
  23. 0 6
      tools/unit-test-app/configs/pm_c6
  24. 0 7
      tools/unit-test-app/configs/pm_s2
  25. 0 7
      tools/unit-test-app/configs/pm_s3
  26. 1 1
      tools/unit-test-app/configs/psram
  27. 1 1
      tools/unit-test-app/configs/release_2
  28. 1 1
      tools/unit-test-app/configs/release_2_s2
  29. 1 1
      tools/unit-test-app/configs/single_core_2
  30. 1 1
      tools/unit-test-app/configs/single_core_2_s2

+ 7 - 0
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

+ 0 - 2
components/esp_pm/test/CMakeLists.txt

@@ -1,2 +0,0 @@
-idf_component_register(SRC_DIRS .
-                       PRIV_REQUIRES unity esp_pm ulp driver esp_timer test_utils)

+ 12 - 0
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)

+ 2 - 0
components/esp_pm/test_apps/esp_pm/README.md

@@ -0,0 +1,2 @@
+| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
+| ----------------- | ----- | -------- | -------- | -------- | -------- |

+ 9 - 0
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)

+ 46 - 0
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();
+}

+ 6 - 1
components/esp_pm/test/test_pm.c → 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 <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -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"
 

+ 19 - 0
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()

+ 1 - 0
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

+ 14 - 0
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

+ 9 - 0
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

+ 8 - 0
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

+ 4 - 0
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

+ 4 - 0
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

+ 4 - 0
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 0 - 7
tools/unit-test-app/configs/pm

@@ -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

+ 0 - 6
tools/unit-test-app/configs/pm_c2

@@ -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

+ 0 - 6
tools/unit-test-app/configs/pm_c3

@@ -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

+ 0 - 6
tools/unit-test-app/configs/pm_c6

@@ -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

+ 0 - 7
tools/unit-test-app/configs/pm_s2

@@ -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

+ 0 - 7
tools/unit-test-app/configs/pm_s3

@@ -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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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