]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/AbortDelay.c
Added xTaskAbortDelayFromISR() and ulTaskNotifyValueClear() API functions.
[freertos] / FreeRTOS / Demo / Common / Minimal / AbortDelay.c
index fc4e36f4d3d921423845045c3a6ebe78a5d76ff7..9fc8cfeb0d3b984168473d993c534e01e2cdc422 100644 (file)
@@ -101,6 +101,12 @@ static void prvTestAbortingEventGroupWait( void );
 static void prvTestAbortingQueueSend( void );\r
 static void prvTestAbortingStreamBufferReceive( void );\r
 \r
+/*\r
+ * Performs a few tests to cover code paths not otherwise covered by the continuous\r
+ * tests.\r
+ */\r
+static void prvPerformSingleTaskTests( void );\r
+\r
 /*\r
  * Checks the amount of time a task spent in the Blocked state is within the\r
  * expected bounds.\r
@@ -143,6 +149,10 @@ uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
 TickType_t xTimeAtStart;\r
 const TickType_t xStartMargin = 2UL;\r
 \r
+/* Used to control whether to use xTaskAbortDelay() or xTaskAbortDelayFromISR() so\r
+both are used with all the tests. */\r
+BaseType_t xUseFromISRVersion = pdFALSE, xHigherPriorityTaskWoken;\r
+\r
        /* Just to remove compiler warnings. */\r
        ( void ) pvParameters;\r
 \r
@@ -167,10 +177,46 @@ const TickType_t xStartMargin = 2UL;
                raise the priority of the controlling task to that of the blocking\r
                task to minimise discrepancies. */\r
                vTaskPrioritySet( NULL, abtBLOCKING_PRIORITY );\r
+\r
                vTaskDelay( xMaxBlockTime + xHalfMaxBlockTime + xStartMargin );\r
-               if( xTaskAbortDelay( xBlockingTask ) != pdPASS )\r
+\r
+               /* For test coverage sometimes xTaskAbortDelay() is used and sometimes\r
+               xTaskAbortDelayFromISR() is used. */\r
+               if( xUseFromISRVersion == pdFALSE )\r
                {\r
-                       xErrorOccurred = pdTRUE;\r
+                       if( xTaskAbortDelay( xBlockingTask ) != pdPASS )\r
+                       {\r
+                               xErrorOccurred = pdTRUE;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+                       /* For test coverage, sometimes xHigherPriorityTaskWoken is used, and\r
+                       sometimes NULL is used. */\r
+\r
+                       if( ( xControllingCycles % 2 ) == 0 )\r
+                       {\r
+                               if( xTaskAbortDelayFromISR( xBlockingTask, &xHigherPriorityTaskWoken ) != pdPASS )\r
+                               {\r
+                                       xErrorOccurred = pdTRUE;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               if( xTaskAbortDelayFromISR( xBlockingTask, NULL ) != pdPASS )\r
+                               {\r
+                                       xErrorOccurred = pdTRUE;\r
+                               }\r
+                       }\r
+\r
+                       /* The tasks have the same priority so xHigherPriorityTaskWoken should\r
+                       never get set. */\r
+                       if( xHigherPriorityTaskWoken != pdFALSE )\r
+                       {\r
+                               xErrorOccurred = pdTRUE;\r
+                       }\r
                }\r
 \r
                /* Reset the priority to the normal controlling priority. */\r
@@ -195,6 +241,13 @@ const TickType_t xStartMargin = 2UL;
 \r
                /* To indicate this task is still executing. */\r
                xControllingCycles++;\r
+\r
+               if( ( xControllingCycles % abtMAX_TESTS ) == 0 )\r
+               {\r
+                       /* Looped through all the tests.  Switch between using xTaskAbortDelay()\r
+                       and xTaskAbortDelayFromISR() for the next round of tests. */\r
+                       xUseFromISRVersion = !xUseFromISRVersion;\r
+               }\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -208,6 +261,10 @@ const uint32_t ulMax = 0xffffffffUL;
        /* Just to remove compiler warnings. */\r
        ( void ) pvParameters;\r
 \r
+       /* Start by performing a few tests to cover code not exercised in the loops\r
+       below. */\r
+       prvPerformSingleTaskTests();\r
+\r
        xControllingTask = xTaskGetHandle( pcControllingTaskName );\r
        configASSERT( xControllingTask );\r
 \r
@@ -264,6 +321,29 @@ const uint32_t ulMax = 0xffffffffUL;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvPerformSingleTaskTests( void )\r
+{\r
+TaskHandle_t xThisTask;\r
+BaseType_t xReturned;\r
+\r
+       /* Try unblocking this task using both the task and ISR versions of the API -\r
+       both should return false as this task is not blocked. */\r
+       xThisTask = xTaskGetCurrentTaskHandle();\r
+\r
+       xReturned = xTaskAbortDelay( xThisTask );\r
+       if( xReturned != pdFALSE )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       xReturned = xTaskAbortDelayFromISR( xThisTask, NULL );\r
+       if( xReturned != pdFALSE )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvTestAbortingTaskDelayUntil( void )\r
 {\r
 TickType_t xTimeAtStart, xLastBlockTime;\r