Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FreeRTOS/Source
Submodule Source updated 750 files
20 changes: 17 additions & 3 deletions FreeRTOS/Test/CBMC/include/queue_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@

return xSet;
}

/* xQueueAddToSet() dereferences the queue set handle to confirm that the object
* really is a queue set, so passing NULL is API misuse rather than something the
* kernel defends against. When the queue set allocation fails, leave the queue
* outside of any set - its pxQueueSetContainer is already NULL at this point. */
void vAddToUnconstrainedQueueSet( QueueHandle_t xQueue )
{
QueueSetHandle_t xSet = xUnconstrainedQueueSet();

if( xSet != NULL )
{
xQueueAddToSet( xQueue, xSet );
}
}
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */

/* Create a mostly unconstrained Queue but bound the max item size.
Expand Down Expand Up @@ -126,7 +140,7 @@ QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound )
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
vAddToUnconstrainedQueueSet( xQueue );
#endif
}

Expand Down Expand Up @@ -163,7 +177,7 @@ QueueHandle_t xUnconstrainedQueue( void )
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
vAddToUnconstrainedQueueSet( xQueue );
#endif
}

Expand All @@ -190,7 +204,7 @@ QueueHandle_t xUnconstrainedMutex( void )
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
vAddToUnconstrainedQueueSet( xQueue );
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ void harness()

if( xQueue )
{
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
QueueSetHandle_t xSet = xUnconstrainedQueueSet();

/* xQueueAddToSet() dereferences the queue set handle to confirm that the
* object really is a queue set, so passing NULL is API misuse rather than
* something the kernel defends against. When the queue set allocation
* fails, leave the queue outside of any set - its pxQueueSetContainer is
* already NULL at this point. */
if( xSet != NULL )
{
xQueueAddToSet( xQueue, xSet );
}

if( xQueue->pxQueueSetContainer )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ void harness()
xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
#if ( configUSE_QUEUE_SETS == 1 )
xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
#endif
QueueSetHandle_t xSet = xUnconstrainedQueueSet();

/* xQueueAddToSet() dereferences the queue set handle to confirm that
* the object really is a queue set, so passing NULL is API misuse
* rather than something the kernel defends against. When the queue
* set allocation fails, leave the queue outside of any set - its
* pxQueueSetContainer is already NULL at this point. */
if( xSet != NULL )
{
xQueueAddToSet( xQueue, xSet );
}
#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
prvUnlockQueue( xQueue );
}
}
193 changes: 193 additions & 0 deletions FreeRTOS/Test/CMock/tasks/tasks_1_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,199 @@ void test_xTaskDelayUntil_success_yield_already( void )
TEST_ASSERT_TRUE( ret_xtask_delay );
}

/* Test the scenario that no tick has elapsed since the previous wake time. The
* task blocks for a full time increment and the previous wake time is left
* untouched. */
void test_xTaskPeriodicDelay_success_no_ticks_elapsed( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount; /* 500 */
TickType_t xTimeIncrement = 5;
TaskHandle_t task_handle;

/* Setup */
task_handle = create_task();
ptcb = ( TCB_t * ) task_handle;
TEST_ASSERT_EQUAL( pxCurrentTCB, ptcb );
/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + xTimeIncrement );
vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 0, ret_increments );
TEST_ASSERT_EQUAL( 500, previousWakeTime );
}

/* Test the scenario that exactly one time increment has elapsed since the
* previous wake time, which is the common case for a task running at a fixed
* frequency. */
void test_xTaskPeriodicDelay_success_one_increment_elapsed( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount - 5; /* 500 - 5 = 495 */
TickType_t xTimeIncrement = 5;
TaskHandle_t task_handle;

/* Setup */
task_handle = create_task();
ptcb = ( TCB_t * ) task_handle;
TEST_ASSERT_EQUAL( pxCurrentTCB, ptcb );
/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + xTimeIncrement );
vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 1, ret_increments );
TEST_ASSERT_EQUAL( 500, previousWakeTime );
}

/* Test the scenario that more than one, but not a whole number of, time
* increments have elapsed since the previous wake time. Only the whole
* increments are added to the previous wake time and the task blocks for the
* remainder of the current increment. */
void test_xTaskPeriodicDelay_success_partial_increment_elapsed( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount - 7; /* 500 - 7 = 493 */
TickType_t xTimeIncrement = 5;
TaskHandle_t task_handle;

/* Setup */
task_handle = create_task();
ptcb = ( TCB_t * ) task_handle;
TEST_ASSERT_EQUAL( pxCurrentTCB, ptcb );
/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + 3 );
vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 1, ret_increments );
TEST_ASSERT_EQUAL( 498, previousWakeTime );
}

/* Test the scenario that several time increments have elapsed since the
* previous wake time, as happens when the task is not resumed in time. All the
* skipped increments are caught up at once. */
void test_xTaskPeriodicDelay_success_multiple_increments_elapsed( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount - 12; /* 500 - 12 = 488 */
TickType_t xTimeIncrement = 5;
TaskHandle_t task_handle;

/* Setup */
task_handle = create_task();
ptcb = ( TCB_t * ) task_handle;
TEST_ASSERT_EQUAL( pxCurrentTCB, ptcb );
/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + 3 );
vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 2, ret_increments );
TEST_ASSERT_EQUAL( 498, previousWakeTime );
}

/* Test the scenario that the time at which the task must be woken overflows.
* The task is added to the overflow delayed task list. */
void test_xTaskPeriodicDelay_success_wake_time_overflow( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount - 3; /* 500 - 3 = 497 */
TickType_t xTimeIncrement = UINT32_MAX;
TaskHandle_t task_handle;

/* Setup */
task_handle = create_task();
ptcb = ( TCB_t * ) task_handle;
TEST_ASSERT_EQUAL( pxCurrentTCB, ptcb );
/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, previousWakeTime - 1 );
vListInsert_Expect( pxOverflowDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 0, ret_increments );
TEST_ASSERT_EQUAL( 497, previousWakeTime );
}

/* Test the scenario that a higher priority task is added to xPendingReadyList
* when the current task calls xTaskPeriodicDelay. The scheduler yields for the
* higher priority task in xTaskResumeAll, so xTaskPeriodicDelay does not need
* to yield itself. */
void test_xTaskPeriodicDelay_success_yield_already( void )
{
TickType_t ret_increments;
TickType_t previousWakeTime = xTickCount; /* 500 */
TickType_t xTimeIncrement = 5;
TaskHandle_t task_handle;
TaskHandle_t task_handle2;

/* Setup */
create_task_priority = 3;
task_handle = create_task();

/* Create another higher priority task to be added in xPendingReadyList. */
create_task_priority = 4;
task_handle2 = create_task();

ptcb = ( TCB_t * ) task_handle;
pxCurrentTCB = ( TCB_t * ) task_handle;

/* Expectations */
/* prvAddCurrentTaskToDelayedList */
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 0 );
listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + xTimeIncrement );
vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem );
/* xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdFALSE );
listGET_OWNER_OF_HEAD_ENTRY_ExpectAndReturn( &xPendingReadyList, task_handle2 );
listREMOVE_ITEM_Expect( &( task_handle2->xEventListItem ) );
listREMOVE_ITEM_Expect( &( task_handle2->xStateListItem ) );
/* prvAddTaskToReadyList */
listINSERT_END_Expect( &pxReadyTasksLists[ task_handle2->uxPriority ],
&task_handle2->xStateListItem );
/* back to xTaskResumeAll */
listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE );
/* prvResetNextTaskUnblockTime */
listLIST_IS_EMPTY_ExpectAndReturn( pxDelayedTaskList, pdTRUE );
/* API Call */
ret_increments = xTaskPeriodicDelay( &previousWakeTime, xTimeIncrement );
/* Validations */
ASSERT_PORT_YIELD_WITHIN_API_CALLED();
TEST_ASSERT_EQUAL( 0, ret_increments );
TEST_ASSERT_EQUAL( 500, previousWakeTime );
}

/* ----------------------- testing INCLUDE_vTaskSuspend ----------------------*/
void test_vTaskSuspend_success( void )
{
Expand Down
39 changes: 39 additions & 0 deletions FreeRTOS/Test/CMock/tasks/tasks_assert_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,45 @@ void test_vTaskDelayUntil_assert_uxSchedulerSuspended_neq_1( void )
validate_and_clear_assertions();
}

/*!
* @brief This test ensures that the code asserts if pxPreviousWakeTime is equal
* to NULL
*/
void test_xTaskPeriodicDelay_assert_pxPreviousWakeTime_NULL( void )
{
EXPECT_ASSERT_BREAK( xTaskPeriodicDelay( NULL, 23 ) );

validate_and_clear_assertions();
}

/*!
* @brief This test ensures that the code asserts if xTimeIncrement is equal to
* zero
*/
void test_xTaskPeriodicDelay_assert_xTimeIncrement_eq_zero( void )
{
TickType_t xPreviousWakeTime;

EXPECT_ASSERT_BREAK( xTaskPeriodicDelay( &xPreviousWakeTime, 0 ) );

validate_and_clear_assertions();
}

/*!
* @brief This test ensures that the code asserts if uxSchedulerSuspended is not
* equal to 1
*/
void test_xTaskPeriodicDelay_assert_uxSchedulerSuspended_neq_1( void )
{
TickType_t xPreviousWakeTime;

vTaskSuspendAll();

EXPECT_ASSERT_BREAK( xTaskPeriodicDelay( &xPreviousWakeTime, 6 ) );

validate_and_clear_assertions();
}

/*!
* @brief This test ensures that the code asserts if uxSchedulerSuspended is not
* equal to 1
Expand Down
Loading
Loading