esp-idf/components/freertos/test/test_uxGetSystemState_Bugfix.c
Darian Leung 1c798b0eab BugFix: uxTaskGetSystemState test case update
Updated test case to include configASSERT cases (+1 squashed commits)

Squashed commits:

[871ec26f] Freertos:Bugfix uxTaskGetSystemState

Bug (github #12142) with uxTaskGetSystemState where
if called immediately after creating a bunch of tasks,
those tasks would be added twice into the TaskStatusArray.
Bug caused due to use old implementation using vTaskSuspendAll
which did not stop newly created task on other core from accessing the
read/waiting task lists whilst the list were being read by
uxTaskGetSystemState. Fixed bug by replacing vTaskSuspendAll
with taskENTER_CRITICAL and added test case for the bugfix
2017-06-16 16:00:54 +08:00

67 lines
1.8 KiB
C

/*
Test Bugfix for uxTaskGetSystemState where getting system state immediately after creating
new tasks would lead them being include twice in the TaskStatusArray. Changed suspendScheduler
in function to taskENTER_CRITICAL
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
#define CreatedTaskDelayTicks 1
#define NumberOfTasksToCreate 4
#define CreatedTaskPriority 10
#define CoreToUse 1
#if (configUSE_TRACE_FACILITY)
void TaskCallback (void* pxParam){
int counter = 0;
while(1){
counter++;
vTaskDelay(CreatedTaskDelayTicks);
}
}
TEST_CASE("uxTaskGetSystemState Bugfix Test", "[freertos]")
{
TaskStatus_t *TaskStatusArray;
TaskHandle_t *TaskHandles;
UBaseType_t NumberOfTasks = 0;
UBaseType_t StartingNumberOfTasks = 0;
//Give Time for OS to remove dport tasks
vTaskDelay(1000);
//Allocate TaskStatusArray
StartingNumberOfTasks = uxTaskGetNumberOfTasks();
TaskStatusArray = pvPortMalloc((StartingNumberOfTasks+NumberOfTasksToCreate) * sizeof(TaskStatus_t));
TaskHandles = pvPortMalloc((StartingNumberOfTasks+NumberOfTasksToCreate) * sizeof(TaskHandle_t));
//Create Tasks
for(int i = 0; i < NumberOfTasksToCreate; i++){
xTaskCreatePinnedToCore(&TaskCallback, "Task" , 2048, NULL, CreatedTaskPriority, (TaskHandle_t*) &TaskHandles[i], CoreToUse);
}
NumberOfTasks = uxTaskGetSystemState(TaskStatusArray, (StartingNumberOfTasks+NumberOfTasksToCreate), NULL);
//Check if any taska have been repeated in TaskStatusArray
if(NumberOfTasks != 0){
printf("Tasks Created, Checking for Repeated Additions \n");
for(int i = 0; i <NumberOfTasks; i++){
for(int j = i + 1; j< NumberOfTasks; j++){
//Give error task handle matches another
configASSERT(!(TaskStatusArray[i].xHandle == TaskStatusArray[j].xHandle));
}
}
}
}
#endif