ci(esp_pm): add test case for USJ printing performance during wake-up

Add a new test case to verify that USJ printing doesn't block CPU on chip
wake-up from light sleep. The test measures the average time per print
operation and ensures it's below 5000 microseconds.
This commit is contained in:
wuzhenghui
2025-10-13 17:20:04 +08:00
parent 77f874049d
commit 119976ffc1
2 changed files with 26 additions and 2 deletions
@@ -5,5 +5,5 @@ set(sources "test_app_main.c"
# 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
PRIV_REQUIRES unity esp_pm ulp driver esp_timer vfs
WHOLE_ARCHIVE)
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/param.h>
@@ -392,6 +393,29 @@ TEST_CASE("esp_timer with SKIP_UNHANDLED_EVENTS does not wake up CPU from sleep"
TEST_ESP_OK(esp_timer_delete(periodic_timer));
}
TEST_CASE("Test USJ printing doesn't block CPU on chip wake-up", "[pm]")
{
light_sleep_enable();
fflush(stdout);
fsync(fileno(stdout));
int64_t printing_time_cost_us = 0, time_end, time_start;
for (int i = 0; i < 20; ++i)
{
time_start = esp_timer_get_time();
printf("Dummy print %02d\n", i);
fflush(stdout);
fsync(fileno(stdout));
time_end = esp_timer_get_time();
printing_time_cost_us += time_end - time_start;
vTaskDelay(10);
}
int32_t avg_cost = (int32_t)(printing_time_cost_us / 20);
printf("Average cost per print %ld\n", avg_cost);
TEST_ASSERT_LESS_THAN(5000, avg_cost);
light_sleep_disable();
}
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
#endif // CONFIG_PM_ENABLE