mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
freertos: Fix flakey event group unit test
The "FreeRTOS Event Groups" main task will only wait a single tick for the created tasks to set their response bits. This short delay may not be sufficent if the tick frequency is high. This commit updates the test so that - the main task waits indefinitely for all the response bits to be set. - created tasks are cleaned up by the main task
This commit is contained in:
parent
5e15bafd26
commit
c7c07c5fb2
@ -7,6 +7,7 @@
|
|||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "driver/timer.h"
|
#include "driver/timer.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
#include "test_utils.h"
|
||||||
|
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32S2
|
#ifdef CONFIG_IDF_TARGET_ESP32S2
|
||||||
#define int_clr_timers int_clr
|
#define int_clr_timers int_clr
|
||||||
@ -40,7 +41,8 @@ static void task_event_group_call_response(void *param)
|
|||||||
|
|
||||||
printf("Task %d done\n", task_num);
|
printf("Task %d done\n", task_num);
|
||||||
xSemaphoreGive(done_sem);
|
xSemaphoreGive(done_sem);
|
||||||
vTaskDelete(NULL);
|
// Wait to be deleted
|
||||||
|
vTaskSuspend(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("FreeRTOS Event Groups", "[freertos]")
|
TEST_CASE("FreeRTOS Event Groups", "[freertos]")
|
||||||
@ -48,6 +50,8 @@ TEST_CASE("FreeRTOS Event Groups", "[freertos]")
|
|||||||
eg = xEventGroupCreate();
|
eg = xEventGroupCreate();
|
||||||
done_sem = xSemaphoreCreateCounting(NUM_TASKS, 0);
|
done_sem = xSemaphoreCreateCounting(NUM_TASKS, 0);
|
||||||
|
|
||||||
|
TaskHandle_t task_handles[NUM_TASKS];
|
||||||
|
|
||||||
/* Note: task_event_group_call_response all have higher priority than this task, so on this core
|
/* Note: task_event_group_call_response all have higher priority than this task, so on this core
|
||||||
they will always preempt this task.
|
they will always preempt this task.
|
||||||
|
|
||||||
@ -55,7 +59,7 @@ TEST_CASE("FreeRTOS Event Groups", "[freertos]")
|
|||||||
or they get out of sync.
|
or they get out of sync.
|
||||||
*/
|
*/
|
||||||
for (int c = 0; c < NUM_TASKS; c++) {
|
for (int c = 0; c < NUM_TASKS; c++) {
|
||||||
xTaskCreatePinnedToCore(task_event_group_call_response, "tsk_call_resp", 4096, (void *)c, configMAX_PRIORITIES - 1, NULL, c % portNUM_PROCESSORS);
|
xTaskCreatePinnedToCore(task_event_group_call_response, "tsk_call_resp", 4096, (void *)c, configMAX_PRIORITIES - 1, &task_handles[c], c % portNUM_PROCESSORS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tasks all start instantly, but this task will resume running at the same time as the higher priority tasks on the
|
/* Tasks all start instantly, but this task will resume running at the same time as the higher priority tasks on the
|
||||||
@ -66,15 +70,19 @@ TEST_CASE("FreeRTOS Event Groups", "[freertos]")
|
|||||||
/* signal all tasks with "CALL" bit... */
|
/* signal all tasks with "CALL" bit... */
|
||||||
xEventGroupSetBits(eg, BIT_CALL);
|
xEventGroupSetBits(eg, BIT_CALL);
|
||||||
|
|
||||||
/* Only wait for 1 tick, the wakeup should be immediate... */
|
/* Wait until all tasks have set their respective response bits */
|
||||||
TEST_ASSERT_EQUAL_HEX16(ALL_RESPONSE_BITS, xEventGroupWaitBits(eg, ALL_RESPONSE_BITS, true, true, 1));
|
TEST_ASSERT_EQUAL_HEX16(ALL_RESPONSE_BITS, xEventGroupWaitBits(eg, ALL_RESPONSE_BITS, true, true, portMAX_DELAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure all tasks cleaned up correctly */
|
/* Ensure all tasks have suspend themselves */
|
||||||
for (int c = 0; c < NUM_TASKS; c++) {
|
for (int c = 0; c < NUM_TASKS; c++) {
|
||||||
TEST_ASSERT( xSemaphoreTake(done_sem, 100/portTICK_PERIOD_MS) );
|
TEST_ASSERT( xSemaphoreTake(done_sem, 100/portTICK_PERIOD_MS) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int c = 0; c < NUM_TASKS; c++) {
|
||||||
|
test_utils_task_delete(task_handles[c]);
|
||||||
|
}
|
||||||
|
|
||||||
vSemaphoreDelete(done_sem);
|
vSemaphoreDelete(done_sem);
|
||||||
vEventGroupDelete(eg);
|
vEventGroupDelete(eg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user