mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-23 11:09:28 -05:00
Add a unit test for tasks.c (#867)
* Add a unit test for tasks.c This test simulates the scenario when a task with priority higher than the currently executing task is unblocked as a result of the xTaskIncrementTick call. This is needed to fix the coverage drop in PR https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/568. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> * Add description for the test Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> * Add doc for another test Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
4f87f485d5
commit
aa316fc1b4
1 changed files with 51 additions and 0 deletions
|
|
@ -2652,6 +2652,10 @@ void test_xTaskIncrementTick_success_update_next_unblock( void )
|
||||||
TEST_ASSERT_EQUAL( xTickCount + 4, xNextTaskUnblockTime );
|
TEST_ASSERT_EQUAL( xTickCount + 4, xNextTaskUnblockTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tests the scenario when a task with priority equal to the
|
||||||
|
* currently executing task is unblocked as a result of the
|
||||||
|
* xTaskIncrementTick call. Also, xPendedTicks is set to
|
||||||
|
* non-zero to ensure that tick hook is not called. */
|
||||||
void test_xTaskIncrementTick_success_unblock_tasks( void )
|
void test_xTaskIncrementTick_success_unblock_tasks( void )
|
||||||
{
|
{
|
||||||
BaseType_t ret_task_incrementtick;
|
BaseType_t ret_task_incrementtick;
|
||||||
|
|
@ -2693,6 +2697,10 @@ void test_xTaskIncrementTick_success_unblock_tasks( void )
|
||||||
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
|
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tests the scenario when a task with priority equal to the
|
||||||
|
* currently executing task is unblocked as a result of the
|
||||||
|
* xTaskIncrementTick call. Also, xPendedTicks is set to 0 to
|
||||||
|
* ensure that tick hook is called. */
|
||||||
void test_xTaskIncrementTick_success_unblock_tasks2( void )
|
void test_xTaskIncrementTick_success_unblock_tasks2( void )
|
||||||
{
|
{
|
||||||
BaseType_t ret_task_incrementtick;
|
BaseType_t ret_task_incrementtick;
|
||||||
|
|
@ -2735,6 +2743,49 @@ void test_xTaskIncrementTick_success_unblock_tasks2( void )
|
||||||
ASSERT_APP_TICK_HOOK_CALLED();
|
ASSERT_APP_TICK_HOOK_CALLED();
|
||||||
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
|
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tests the scenario when a task with priority higher than the
|
||||||
|
* currently executing task is unblocked as a result of the
|
||||||
|
* xTaskIncrementTick call. Also, xPendedTicks is set to
|
||||||
|
* non-zero to ensure that tick hook is not called. */
|
||||||
|
void test_xTaskIncrementTick_success_unblock_tasks3( void )
|
||||||
|
{
|
||||||
|
BaseType_t ret_task_incrementtick;
|
||||||
|
TaskHandle_t task_handle;
|
||||||
|
|
||||||
|
/* Setup. */
|
||||||
|
create_task_priority = 4;
|
||||||
|
task_handle = create_task();
|
||||||
|
block_task( task_handle );
|
||||||
|
create_task_priority = 3;
|
||||||
|
( void ) create_task();
|
||||||
|
ptcb = task_handle;
|
||||||
|
xPendedTicks = 3;
|
||||||
|
xTickCount = 50;
|
||||||
|
xNextTaskUnblockTime = 49; /* Task 2 is due unblocking. */
|
||||||
|
uxSchedulerSuspended = pdFALSE;
|
||||||
|
|
||||||
|
/* Expectations. */
|
||||||
|
listLIST_IS_EMPTY_ExpectAndReturn( pxDelayedTaskList, pdFALSE );
|
||||||
|
listGET_OWNER_OF_HEAD_ENTRY_ExpectAndReturn( pxDelayedTaskList, task_handle );
|
||||||
|
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &task_handle->xStateListItem,
|
||||||
|
xTickCount - 5 );
|
||||||
|
listREMOVE_ITEM_Expect( &( task_handle->xStateListItem ) );
|
||||||
|
listLIST_ITEM_CONTAINER_ExpectAndReturn( &task_handle->xEventListItem, NULL );
|
||||||
|
listINSERT_END_Expect( &pxReadyTasksLists[ task_handle->uxPriority ],
|
||||||
|
&task_handle->xStateListItem );
|
||||||
|
listLIST_IS_EMPTY_ExpectAndReturn( pxDelayedTaskList, pdTRUE );
|
||||||
|
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ task_handle->uxPriority ], 1 );
|
||||||
|
|
||||||
|
/* API Call */
|
||||||
|
ret_task_incrementtick = xTaskIncrementTick();
|
||||||
|
|
||||||
|
/* Validations */
|
||||||
|
TEST_ASSERT_EQUAL( pdTRUE, ret_task_incrementtick );
|
||||||
|
ASSERT_APP_TICK_HOOK_NOT_CALLED();
|
||||||
|
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
|
||||||
|
}
|
||||||
|
|
||||||
/* testing INCLUDE_xTaskAbortDelay */
|
/* testing INCLUDE_xTaskAbortDelay */
|
||||||
void test_xTaskAbortDelay_fail_current_task( void )
|
void test_xTaskAbortDelay_fail_current_task( void )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue