]> granicus.if.org Git - esp-idf/commitdiff
BugFix: uxTaskGetSystemState test case update
authorDarian Leung <darian@espressif.com>
Fri, 16 Jun 2017 03:49:48 +0000 (11:49 +0800)
committerDarian Leung <darian@espressif.com>
Fri, 16 Jun 2017 08:00:54 +0000 (16:00 +0800)
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

components/freertos/tasks.c
components/freertos/test/test_uxGetSystemState_Bugfix.c [new file with mode: 0644]

index ca73ba0a6706d59dd77a03892f16be2ebfe36ce0..ac82c5c8c810f57d7400e529439dbb8664e4ffab 100644 (file)
@@ -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;
        }
 
diff --git a/components/freertos/test/test_uxGetSystemState_Bugfix.c b/components/freertos/test/test_uxGetSystemState_Bugfix.c
new file mode 100644 (file)
index 0000000..e7e447f
--- /dev/null
@@ -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
\ No newline at end of file