Added xTaskAbortDelayFromISR() and ulTaskNotifyValueClear() API functions.

Added tests for xTaskAbortDelayFromISR() into Demo/Common/Minimal/AbortDelay.c.
Added tests for ulTaskNotifyValueClear() into Demo/Common/Minimal/TaskNotify.c.
This commit is contained in:
Richard Barry 2020-01-02 18:55:20 +00:00
parent 0a29d350b1
commit be3561ed53
9 changed files with 336 additions and 27 deletions

View file

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

View file

@ -47,7 +47,12 @@
#endif
#define notifyTASK_PRIORITY ( tskIDLE_PRIORITY )
#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
/* Constants used in tests when setting/clearing bits. */
#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )
#define notifyUINT32_LOW_BYTE ( ( uint32_t ) 0x000000ff )
#define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )
/*-----------------------------------------------------------*/
@ -403,6 +408,37 @@ TimerHandle_t xSingleTaskTimer;
/* ------------------------------------------------------------------------
Clear bits in the notification value. */
/* Get the task to set all bits its own notification value. This is not a
normal thing to do, and is only done here for test purposes. */
xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eSetBits );
/* Now clear the top bytes - the returned value from the first call should
indicate that previously all bits were set. */
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
/* Next clear the bottom bytes - the returned value this time should indicate
that the top byte was clear (before the bottom byte was cleared. */
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
/* Next clear all bytes - the returned value should indicate that previously the
high and low bytes were clear. */
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
/* Now all bits should be clear. */
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, 0UL ) == 0 );
configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
/* Now the notification state should be eNotified, so it should now be
possible to clear the notification state. */
configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
/* ------------------------------------------------------------------------
Create a timer that will try notifying this task while it is suspended. */
xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );