mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
test(freertos): Fix race condition in suspend-resume tests
This commit fixes a race condition in suspend-resume tests where in a test task could escape deletion and result in a memory leak after test completion.
This commit is contained in:
+24
-2
@@ -223,6 +223,12 @@ TEST_CASE("Test vTaskSuspendAll() and xTaskResumeAll() multicore", "[freertos]")
|
|||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
xSemaphoreTake(done_sem, portMAX_DELAY);
|
xSemaphoreTake(done_sem, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suspend the test tasks in case they haven't suspended themselves yet
|
||||||
|
vTaskSuspend(taskA_hdl);
|
||||||
|
vTaskSuspend(taskB_hdl);
|
||||||
|
vTaskDelay(10);
|
||||||
|
|
||||||
// Cleanup the tasks
|
// Cleanup the tasks
|
||||||
vTaskDelete(taskA_hdl);
|
vTaskDelete(taskA_hdl);
|
||||||
vTaskDelete(taskB_hdl);
|
vTaskDelete(taskB_hdl);
|
||||||
@@ -332,6 +338,8 @@ static void test_unblk_a1_task(void *arg)
|
|||||||
|
|
||||||
// Cleanup A2 and interrupt
|
// Cleanup A2 and interrupt
|
||||||
deregister_intr_cb();
|
deregister_intr_cb();
|
||||||
|
vTaskSuspend(a2_task_hdl);
|
||||||
|
vTaskDelay(10);
|
||||||
vTaskDelete(a2_task_hdl);
|
vTaskDelete(a2_task_hdl);
|
||||||
|
|
||||||
// Indicate done and wait to be deleted
|
// Indicate done and wait to be deleted
|
||||||
@@ -384,6 +392,11 @@ TEST_CASE("Test vTaskSuspendAll allows scheduling on other cores", "[freertos]")
|
|||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
xSemaphoreTake(test_unblk_done_sem, portMAX_DELAY);
|
xSemaphoreTake(test_unblk_done_sem, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
// Suspend the test tasks in case they haven't suspended themselves yet
|
||||||
|
vTaskSuspend(a1_task_hdl);
|
||||||
|
vTaskSuspend(b1_task_hdl);
|
||||||
|
vTaskDelay(10);
|
||||||
|
|
||||||
// Cleanup tasks
|
// Cleanup tasks
|
||||||
vTaskDelete(a1_task_hdl);
|
vTaskDelete(a1_task_hdl);
|
||||||
vTaskDelete(b1_task_hdl);
|
vTaskDelete(b1_task_hdl);
|
||||||
@@ -506,6 +519,10 @@ TEST_CASE("Test vTaskSuspendAll doesn't block unpinned tasks from being schedule
|
|||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
xSemaphoreTake(test_unpinned_sem, portMAX_DELAY);
|
xSemaphoreTake(test_unpinned_sem, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
// Suspend the test tasks in case they haven't suspended themselves yet
|
||||||
|
vTaskSuspend(pinned_task_hdl);
|
||||||
|
vTaskSuspend(unpinned_task_hdl);
|
||||||
|
vTaskDelay(10);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
vTaskDelete(pinned_task_hdl);
|
vTaskDelete(pinned_task_hdl);
|
||||||
@@ -632,8 +649,9 @@ TEST_CASE("Test xTaskResumeAll resumes pended tasks", "[freertos]")
|
|||||||
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(test_pended_running_task, "susp", 2048, (void *)xTaskGetCurrentTaskHandle(), UNITY_FREERTOS_PRIORITY + 1, &susp_tsk_hdl, i));
|
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(test_pended_running_task, "susp", 2048, (void *)xTaskGetCurrentTaskHandle(), UNITY_FREERTOS_PRIORITY + 1, &susp_tsk_hdl, i));
|
||||||
// Wait for to be notified to test completion
|
// Wait for to be notified to test completion
|
||||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||||
// Add a short delay to allow the test_pended_running_task to go to suspend state
|
// Suspend the test task in case it hasn't suspended itself yet
|
||||||
vTaskDelay(1);
|
vTaskSuspend(susp_tsk_hdl);
|
||||||
|
vTaskDelay(10);
|
||||||
vTaskDelete(susp_tsk_hdl);
|
vTaskDelete(susp_tsk_hdl);
|
||||||
}
|
}
|
||||||
// Add a short delay to allow the idle task to free any remaining task memory
|
// Add a short delay to allow the idle task to free any remaining task memory
|
||||||
@@ -746,8 +764,12 @@ TEST_CASE("Test xTaskSuspendAll on all cores pends all tasks and xTaskResumeAll
|
|||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
for (int i = 0; i < TEST_PENDED_NUM_BLOCKED_TASKS; i++) {
|
for (int i = 0; i < TEST_PENDED_NUM_BLOCKED_TASKS; i++) {
|
||||||
|
vTaskSuspend(blkd_tasks[i]);
|
||||||
|
vTaskDelay(10);
|
||||||
vTaskDelete(blkd_tasks[i]);
|
vTaskDelete(blkd_tasks[i]);
|
||||||
}
|
}
|
||||||
|
vTaskSuspend(susp_task);
|
||||||
|
vTaskDelay(10);
|
||||||
vTaskDelete(susp_task);
|
vTaskDelete(susp_task);
|
||||||
vSemaphoreDelete(done_sem);
|
vSemaphoreDelete(done_sem);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user