Skip to content

Commit f702d40

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'test/freertos_flaky_tests_stabilization_v5.5' into 'release/v5.5'
test(freertos): Added miscellaneous stability fixes to unit tests (v5.5) See merge request espressif/esp-idf!43123
2 parents 85604da + 2a89a24 commit f702d40

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

components/freertos/test_apps/freertos/kernel/tasks/test_freertos_psram.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ TEST_CASE("Task on specific core works", "[freertos][psram]")
140140
TEST_ASSERT_EQUAL((size_t) corenum, corenum_info.recorded_core_num);
141141

142142
vTaskDelete(task_handle);
143+
144+
// Add a short delay to allow the idle task to free any remaining task memory
145+
vTaskDelay(10);
143146
}
144147
}
145148
#endif // !CONFIG_FREERTOS_UNICORE

components/freertos/test_apps/freertos/kernel/tasks/test_vTaskSuspendAll_xTaskResumeAll.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ TEST_CASE("Test vTaskSuspendAll allows scheduling on other cores", "[freertos]")
394394
// Cleanup tasks
395395
vTaskDelete(a1_task_hdl);
396396
vTaskDelete(b1_task_hdl);
397+
vTaskDelay(10);
397398
}
398399

399400
vSemaphoreDelete(test_unblk_done_sem);

components/freertos/test_apps/freertos/kernel/tasks/test_yielding.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -34,6 +34,9 @@ static volatile uint32_t count;
3434
// Lock variable to create a blocked task scenario
3535
static volatile SemaphoreHandle_t task_mutex;
3636

37+
// Semaphore to synchronize yield test tasks
38+
static SemaphoreHandle_t yield_sync_sem;
39+
3740
// This helper macro is used to store the task id atomically
3841
#define STORE_TASK_ID(task_id) ({ \
3942
portENTER_CRITICAL(&idx_lock); \
@@ -56,10 +59,11 @@ static void yield_task1(void *arg)
5659
/* Store task_id in the sequence array */
5760
STORE_TASK_ID(task_id);
5861

59-
/* Notify the yield_task2 to run */
60-
task_sequence_ready = true;
62+
/* Give semaphore to unblock yield_task2, making it READY (not just setting a flag).
63+
* This ensures task2 is in the ready queue when we yield. */
64+
xSemaphoreGive(yield_sync_sem);
6165

62-
/* Yield */
66+
/* Yield - now task2 is guaranteed to be READY and should run next */
6367
taskYIELD();
6468

6569
/* Increment task count to notify unity task */
@@ -73,10 +77,9 @@ static void yield_task2(void *arg)
7377
{
7478
uint32_t task_id = (uint32_t)arg;
7579

76-
/* Wait for the other task to run for the test to begin */
77-
while (!task_sequence_ready) {
78-
vTaskDelay(10);
79-
};
80+
/* Block on semaphore - this ensures task1 runs first and we don't poll.
81+
* When task1 gives the semaphore, we transition directly to READY state. */
82+
xSemaphoreTake(yield_sync_sem, portMAX_DELAY);
8083

8184
/* Store task_id in the sequence array */
8285
STORE_TASK_ID(task_id);
@@ -108,9 +111,16 @@ TEST_CASE("Task yield must run the next ready task of the same priority", "[free
108111
/* Reset task sequence flag */
109112
task_sequence_ready = false;
110113

111-
/* Create test tasks */
112-
xTaskCreatePinnedToCore(yield_task1, "yield_task1", 2048, (void *)1, UNITY_FREERTOS_PRIORITY - 1, NULL, UNITY_FREERTOS_CPU);
114+
/* Create semaphore for synchronization - start empty so task2 blocks */
115+
yield_sync_sem = xSemaphoreCreateBinary();
116+
TEST_ASSERT_NOT_NULL(yield_sync_sem);
117+
118+
/* Create test tasks - order matters!
119+
* Task2 is created first and will immediately block on the semaphore.
120+
* Task1 is created second and will run first since task2 is blocked. */
113121
xTaskCreatePinnedToCore(yield_task2, "yield_task2", 2048, (void *)2, UNITY_FREERTOS_PRIORITY - 1, NULL, UNITY_FREERTOS_CPU);
122+
vTaskDelay(1); /* Ensure task2 has blocked on semaphore before creating task1 */
123+
xTaskCreatePinnedToCore(yield_task1, "yield_task1", 2048, (void *)1, UNITY_FREERTOS_PRIORITY - 1, NULL, UNITY_FREERTOS_CPU);
114124

115125
/* Wait for the tasks to finish up */
116126
while (count != 2) {
@@ -122,6 +132,9 @@ TEST_CASE("Task yield must run the next ready task of the same priority", "[free
122132
/* Verify that the yield is successful and the next ready task is run */
123133
TEST_ASSERT_EQUAL(1, task_yield_sequence[idx++]);
124134
TEST_ASSERT_EQUAL(2, task_yield_sequence[idx++]);
135+
136+
/* Clean up semaphore */
137+
vSemaphoreDelete(yield_sync_sem);
125138
}
126139

127140
/*

components/freertos/test_apps/freertos/misc/test_tickless_idle.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "freertos/semphr.h"
1111
#include "esp_pm.h"
1212
#include "esp_private/esp_clk.h"
13+
#include "esp_clk_tree.h"
1314

1415
#include "sdkconfig.h"
1516

@@ -66,9 +67,11 @@ static void consumer_task(void *arg)
6667
TEST_CASE("Test semaphore timeout during tickless idle", "[freertos]")
6768
{
6869
// Configure tickless idle
70+
uint32_t xtal_hz = 0;
71+
esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_XTAL, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &xtal_hz);
6972
esp_pm_config_t pm_config = {
70-
.max_freq_mhz = esp_clk_cpu_freq() / MHZ,
71-
.min_freq_mhz = esp_clk_cpu_freq() / MHZ,
73+
.max_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ,
74+
.min_freq_mhz = xtal_hz / MHZ,
7275
.light_sleep_enable = true,
7376
};
7477
TEST_ESP_OK(esp_pm_configure(&pm_config));

0 commit comments

Comments
 (0)