Skip to content

Commit

Permalink
Exercise xTaskDelayUntil() in demos and tests (FreeRTOS#335)
Browse files Browse the repository at this point in the history
* Update AbortDelay.c so it uses both vTaskDelayUntil() and xTaskDelayUntil().
Update TaskNotifyArray.c to prevent false positive test failures that appear to be caused by unwarranted integer promotion.
Add use of xTaskDelayUntil() to blocktim.c
  • Loading branch information
RichardBarry authored Oct 12, 2020
1 parent e07d681 commit 56d44da
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 14 deletions.
18 changes: 14 additions & 4 deletions FreeRTOS/Demo/Common/Minimal/AbortDelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,29 @@ BaseType_t xReturned;
static void prvTestAbortingTaskDelayUntil( void )
{
TickType_t xTimeAtStart, xLastBlockTime;
BaseType_t xReturned;

/* Note the time before the delay so the length of the delay is known. */
xTimeAtStart = xTaskGetTickCount();

/* Take a copy of the time as it is updated in the call to
vTaskDelayUntil() but its original value is needed to determine the actual
xTaskDelayUntil() but its original value is needed to determine the actual
time spend in the Blocked state. */
xLastBlockTime = xTimeAtStart;

/* This first delay should just time out. */
vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
configASSERT( xReturned == pdTRUE );
/* Remove compiler warning about value being set but not used in the case
configASSERT() is not defined. */
( void ) xReturned;

/* This second delay should be aborted by the primary task half way
through. Again take a copy of the time as it is updated in the call to
vTaskDelayUntil() buts its original value is needed to determine the amount
of time actually spent in the Blocked state. */
of time actually spent in the Blocked state. This uses vTaskDelayUntil()
in place of xTaskDelayUntil() for test coverage. */
xTimeAtStart = xTaskGetTickCount();
xLastBlockTime = xTimeAtStart;
vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
Expand All @@ -319,8 +325,12 @@ TickType_t xTimeAtStart, xLastBlockTime;
/* As with the other tests, the third block period should not time out. */
xTimeAtStart = xTaskGetTickCount();
xLastBlockTime = xTimeAtStart;
vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
configASSERT( xReturned == pdTRUE );
/* Remove compiler warning about value being set but not used in the case
configASSERT() is not defined. */
( void ) xReturned;
}
/*-----------------------------------------------------------*/

Expand Down
21 changes: 14 additions & 7 deletions FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void prvSingleTaskTests( void )
const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
BaseType_t xReturned;
uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
TickType_t xTimeOnEntering;
TickType_t xTimeOnEntering, xTimeNow, xTimeDifference;
const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
UBaseType_t uxIndexToTest, uxOtherIndexes;
Expand All @@ -221,7 +221,9 @@ UBaseType_t uxIndexToTest, uxOtherIndexes;
( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */

/* Should have blocked for the entire block time. */
configASSERT( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToWait );
xTimeNow = xTaskGetTickCount();
xTimeDifference = xTimeNow - xTimeOnEntering;
configASSERT( xTimeDifference >= xTicksToWait );
configASSERT( xReturned == pdFAIL );
configASSERT( ulNotifiedValue == 0UL );
( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
Expand Down Expand Up @@ -268,7 +270,9 @@ UBaseType_t uxIndexToTest, uxOtherIndexes;
and so not time out. */
xTimeOnEntering = xTaskGetTickCount();
xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
configASSERT( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait );
xTimeNow = xTaskGetTickCount();
xTimeDifference = xTimeNow - xTimeOnEntering;
configASSERT( xTimeDifference < xTicksToWait );

/* The task should have been notified, and the notified value should
be equal to ulFirstNotifiedConst. */
Expand Down Expand Up @@ -992,7 +996,7 @@ const TickType_t xTimerPeriod = pdMS_TO_TICKS( 100 ), xMargin = pdMS_TO_TICKS( 5
UBaseType_t uxIndex, uxIndexToNotify;
uint32_t ulReceivedValue;
BaseType_t xReturned;
TickType_t xTimeBeforeBlocking;
TickType_t xTimeBeforeBlocking, xTimeNow, xTimeDifference;

/* Set all notify values within the array of tasks notifications to zero
ready for the next test. */
Expand Down Expand Up @@ -1028,13 +1032,16 @@ TickType_t xTimeBeforeBlocking;
xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xTimerPeriod + xMargin );

/* The notification will have been sent to task notification at index
uxIndexToNotify in this task by the timer callback after xTimerPeriodTicks.
The notification should not have woken this task, so xReturned should
uxIndexToNotify in this task by the timer callback after xTimerPeriodTicks.
The notification should not have woken this task, so xReturned should
be false and at least xTimerPeriod + xMargin ticks should have passed. */
configASSERT( xReturned == pdFALSE );
configASSERT( ( xTaskGetTickCount() - xTimeBeforeBlocking ) >= ( xTimerPeriod + xMargin ) );
xTimeNow = xTaskGetTickCount();
xTimeDifference = xTimeNow - xTimeBeforeBlocking;
configASSERT( xTimeDifference >= ( xTimerPeriod + xMargin ) );
( void ) xReturned; /* Remove compiler warnings if configASSERT() is not defined. */
( void ) xTimeBeforeBlocking;
( void ) xTimeDifference;

/* Only the notification at index position uxIndexToNotify should be
set. Calling this function will clear it again. */
Expand Down
45 changes: 44 additions & 1 deletion FreeRTOS/Demo/Common/Minimal/blocktim.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ BaseType_t xData;
static void prvBasicDelayTests( void )
{
TickType_t xPreTime, xPostTime, x, xLastUnblockTime, xExpectedUnblockTime;
const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 );
const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 ), xHalfPeriod = xPeriod / ( TickType_t ) 2;
BaseType_t xDidBlock;

/* Temporarily increase priority so the timing is more accurate, but not so
high as to disrupt the timer tests. */
Expand Down Expand Up @@ -511,6 +512,48 @@ const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MA
xPrimaryCycles++;
}

/* Crude tests for return value of xTaskDelayUntil(). First a standard block
should return that the task does block. */
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}

/* Now delay a few ticks so repeating the above block period will not block for
the full amount of time, but will still block. */
vTaskDelay( xHalfPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}

/* This time block for longer than xPeriod before calling xTaskDelayUntil() so
the call to xTaskDelayUntil() should not block. */
vTaskDelay( xPeriod );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdFALSE )
{
xErrorOccurred = pdTRUE;
}

/* Catch up. */
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdTRUE )
{
xErrorOccurred = pdTRUE;
}

/* Again block for slightly longer than a period so ensure the time is in the
past next time xTaskDelayUntil() gets called. */
vTaskDelay( xPeriod + xAllowableMargin );
xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
if( xDidBlock != pdFALSE )
{
xErrorOccurred = pdTRUE;
}

/* Reset to the original task priority ready for the other tests. */
vTaskPrioritySet( NULL, bktPRIMARY_PRIORITY );
}
Expand Down
2 changes: 1 addition & 1 deletion FreeRTOS/Source
Submodule Source updated 36 files
+22 −2 include/FreeRTOS.h
+1 −1 include/mpu_prototypes.h
+1 −1 include/mpu_wrappers.h
+54 −38 include/task.h
+2 −0 lexicon.txt
+7 −5 portable/Common/mpu_wrappers.c
+7 −0 portable/ThirdParty/GCC/Posix/port.c
+6 −3 portable/ThirdParty/GCC/Xtensa_ESP32/FreeRTOS-openocd.c
+26 −13 portable/ThirdParty/GCC/Xtensa_ESP32/include/portmacro.h
+43 −10 portable/ThirdParty/GCC/Xtensa_ESP32/port.c
+25 −1 portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S
+5 −1 portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_init.c
+5 −1 portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_intr.c
+1 −1 portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vector_defaults.S
+112 −4 portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S
+27 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/FreeRTOS-openocd.c
+46 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/portbenchmark.h
+489 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/portmacro.h
+132 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/xtensa_api.h
+145 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/xtensa_config.h
+378 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/xtensa_context.h
+231 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/xtensa_rtos.h
+158 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/include/xtensa_timer.h
+481 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/port.c
+653 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/portasm.S
+113 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/portmux_impl.h
+200 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/portmux_impl.inc.h
+648 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_context.S
+54 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_init.c
+174 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_intr.c
+225 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_intr_asm.S
+559 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_loadstore_handler.S
+67 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_overlay_os_hook.c
+164 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_vector_defaults.S
+1,919 −0 portable/ThirdParty/GCC/Xtensa_ESP32_IDF3/xtensa_vectors.S
+8 −6 tasks.c

0 comments on commit 56d44da

Please sign in to comment.