kopia lustrzana https://github.com/espressif/esp-idf
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 bugfixpull/706/merge
rodzic
f114ef4a6a
commit
1c798b0eab
|
@ -2280,7 +2280,7 @@ UBaseType_t uxTaskGetNumberOfTasks( void )
|
|||
UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES;
|
||||
|
||||
UNTESTED_FUNCTION();
|
||||
vTaskSuspendAll(); //WARNING: This only suspends one CPU. ToDo: suspend others as well. Mux using taskQueueMutex maybe?
|
||||
taskENTER_CRITICAL(&xTaskQueueMutex);
|
||||
{
|
||||
/* Is there a space in the array for each task in the system? */
|
||||
if( uxArraySize >= uxCurrentNumberOfTasks )
|
||||
|
@ -2340,8 +2340,7 @@ UBaseType_t uxTaskGetNumberOfTasks( void )
|
|||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
( void ) xTaskResumeAll();
|
||||
|
||||
taskEXIT_CRITICAL(&xTaskQueueMutex);
|
||||
return uxTask;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
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
|
Ładowanie…
Reference in New Issue