From 2caee3ad9c0e719f61b974a0f4d12100c45aa51b Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 1 Sep 2026 10:32:23 +0800 Subject: [PATCH 1/2] fix(esp_system): wait for idle after light sleep stress tasks Self-deleted worker tasks are only freed once idle runs. A 500us periodic esp_timer can starve that cleanup and trip Unity's leak check. --- .../test_apps/esp_system_unity_tests/main/test_sleep.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c index aa301bb378a..fd4f843a283 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -96,6 +96,8 @@ TEST_CASE("light sleep stress test", "[lightsleep]") #if CONFIG_FREERTOS_NUMBER_OF_CORES == 2 xSemaphoreTake(done, portMAX_DELAY); #endif + /* vTaskDelete() only queues TCB/stack for idle; wait for two idle passes. */ + vTaskDelay(2); vSemaphoreDelete(done); } @@ -122,9 +124,12 @@ TEST_CASE("light sleep stress test with periodic esp_timer", "[lightsleep]") #if CONFIG_FREERTOS_NUMBER_OF_CORES == 2 xSemaphoreTake(done, portMAX_DELAY); #endif - vSemaphoreDelete(done); + /* Stop the periodic timer first, otherwise it starves idle and the + * self-deleted worker looks like a leak to Unity. */ esp_timer_stop(timer); esp_timer_delete(timer); + vTaskDelay(2); + vSemaphoreDelete(done); } #endif // !(CONFIG_SPIRAM) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384) From 87c280843a9f6ef5861b17b9063b9ac43f7aa289 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 1 Sep 2026 10:39:45 +0800 Subject: [PATCH 2/2] fix(esp_system): delay after light sleep stress cleanup --- .../test_apps/esp_system_unity_tests/main/test_sleep.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c index fd4f843a283..acab01b64a9 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c +++ b/components/esp_system/test_apps/esp_system_unity_tests/main/test_sleep.c @@ -96,9 +96,8 @@ TEST_CASE("light sleep stress test", "[lightsleep]") #if CONFIG_FREERTOS_NUMBER_OF_CORES == 2 xSemaphoreTake(done, portMAX_DELAY); #endif - /* vTaskDelete() only queues TCB/stack for idle; wait for two idle passes. */ - vTaskDelay(2); vSemaphoreDelete(done); + vTaskDelay(10); } static void timer_func(void* arg) @@ -124,12 +123,10 @@ TEST_CASE("light sleep stress test with periodic esp_timer", "[lightsleep]") #if CONFIG_FREERTOS_NUMBER_OF_CORES == 2 xSemaphoreTake(done, portMAX_DELAY); #endif - /* Stop the periodic timer first, otherwise it starves idle and the - * self-deleted worker looks like a leak to Unity. */ + vSemaphoreDelete(done); esp_timer_stop(timer); esp_timer_delete(timer); - vTaskDelay(2); - vSemaphoreDelete(done); + vTaskDelay(10); } #endif // !(CONFIG_SPIRAM) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384)