From a8db5b8128cee6c540f45926f9e04b3e9de42575 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Thu, 19 Mar 2026 15:08:55 +0100 Subject: [PATCH 1/2] fix(freertos): Fix flaky PSRAM tests for freertos This commit adds additional delays to the stress test where we create and self-delete tasks on PSRAM. iSuch tasks rely on the kernel creating a special cleanup task to delete them. Hence, the delays in the main task allow the cleanup task to bescheduled and the deletion to go through. --- .../freertos/test_apps/freertos/misc/test_idf_additions.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/freertos/test_apps/freertos/misc/test_idf_additions.c b/components/freertos/test_apps/freertos/misc/test_idf_additions.c index 99e67eb97b..d9fc67adb7 100644 --- a/components/freertos/test_apps/freertos/misc/test_idf_additions.c +++ b/components/freertos/test_apps/freertos/misc/test_idf_additions.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -103,7 +103,6 @@ TEST_CASE("IDF additions: Task creation with SPIRAM memory caps and self deletio for (int i = 0; i < TEST_NUM_TASKS; i++) { // Create a task with caps TEST_ASSERT_EQUAL(pdPASS, xTaskCreateWithCaps(task_with_caps_self_delete, "task", 4096, NULL, UNITY_FREERTOS_PRIORITY, &task_handle[i], MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)); - TEST_ASSERT_NOT_EQUAL(NULL, task_handle); // Get the task's memory TEST_ASSERT_EQUAL(pdTRUE, xTaskGetStaticBuffers(task_handle[i], &puxStackBuffer, &pxTaskBuffer)); } @@ -112,7 +111,11 @@ TEST_CASE("IDF additions: Task creation with SPIRAM memory caps and self deletio // Notify the task to delete itself xTaskNotifyGive(task_handle[i]); } + // Let the scheduler run the self-delete tasks. + vTaskDelay(1); } + // Allow the last batch to be freed by the cleanup task in vTaskDeleteWithCaps(). + vTaskDelay(50); } #endif /* CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM */ From eea52d65fb738d822abc956475c823c9e1717897 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 20 Mar 2026 14:41:46 +0100 Subject: [PATCH 2/2] fix(freertos): Use bare ticks for cleanup delays in freertos tests --- .../freertos/test_apps/freertos/main/test_freertos_main.c | 4 ++-- .../freertos/test_apps/freertos/misc/test_idf_additions.c | 2 +- .../freertos/test_apps/freertos/port/test_tlsp_del_cb.c | 2 +- .../test_apps/freertos/port/test_xtensa_loadstore_handler.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/freertos/test_apps/freertos/main/test_freertos_main.c b/components/freertos/test_apps/freertos/main/test_freertos_main.c index 2293213827..1683d31d77 100644 --- a/components/freertos/test_apps/freertos/main/test_freertos_main.c +++ b/components/freertos/test_apps/freertos/main/test_freertos_main.c @@ -31,8 +31,8 @@ void setUp(void) void tearDown(void) { - // Add a short delay of 10ms to allow the idle task to free an remaining memory - vTaskDelay(pdMS_TO_TICKS(10)); + // Add a short delay of 10 ticks to allow the idle task to free remaining memory. + vTaskDelay(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"); diff --git a/components/freertos/test_apps/freertos/misc/test_idf_additions.c b/components/freertos/test_apps/freertos/misc/test_idf_additions.c index d9fc67adb7..2b3c77a1db 100644 --- a/components/freertos/test_apps/freertos/misc/test_idf_additions.c +++ b/components/freertos/test_apps/freertos/misc/test_idf_additions.c @@ -357,7 +357,7 @@ TEST_CASE("IDF additions: IDF tick hooks during scheduler suspension", "[freerto /* Cleanup */ vTaskSuspend(suspend_task_handle[x]); - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelay(10); vTaskDelete(suspend_task_handle[x]); } } diff --git a/components/freertos/test_apps/freertos/port/test_tlsp_del_cb.c b/components/freertos/test_apps/freertos/port/test_tlsp_del_cb.c index 37a7c1cbdf..8a09bbd2db 100644 --- a/components/freertos/test_apps/freertos/port/test_tlsp_del_cb.c +++ b/components/freertos/test_apps/freertos/port/test_tlsp_del_cb.c @@ -67,7 +67,7 @@ TEST_CASE("Test TLSP deletion callbacks", "[freertos]") TEST_ASSERT_EQUAL(pdPASS, xTaskCreatePinnedToCore(tlsp_task, "tlsp_tsk", configMINIMAL_STACK_SIZE * 2, (void *)&tlsps[i], UNITY_FREERTOS_PRIORITY - 1, &tasks[i], i)); } // Significant delay to let tasks run and delete themselves - vTaskDelay(pdMS_TO_TICKS(100)); + vTaskDelay(100); // Check the values of the TLSPs to see if the del cb have ran for (int i = 0; i < CONFIG_FREERTOS_NUMBER_OF_CORES; i++) { diff --git a/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c b/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c index 704ce3dab2..ba1d0393d2 100644 --- a/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c +++ b/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c @@ -216,7 +216,7 @@ TEST_CASE("LoadStore: 8/16-bit field access in IRAM from ISRs when pending inter esp_rom_printf("test passed\n"); heap_caps_free((void *)s_iram); - vTaskDelay(pdMS_TO_TICKS(100)); // Wait for memory to be freed, to avoid affecting other tests. + vTaskDelay(100); // Wait in ticks for memory to be freed, to avoid affecting other tests. } TEST_CASE("LoadStore: zero-overhead loop continues after IRAM 8-bit store", "[freertos]") @@ -273,6 +273,6 @@ TEST_CASE("LoadStore: zero-overhead loop continues after IRAM 8-bit store", "[fr heap_caps_free(dst); heap_caps_free(src); - vTaskDelay(pdMS_TO_TICKS(100)); // Wait for free to complete before running other tests. + vTaskDelay(100); // Wait for free to complete before running other tests. } #endif // CONFIG_IDF_TARGET_ARCH_XTENSA && CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY