Skip to content

Commit ad39453

Browse files
committed
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 FreeRTOS/FreeRTOS-Kernel#568. Signed-off-by: Gaurav Aggarwal <[email protected]>
1 parent 4f87f48 commit ad39453

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

FreeRTOS/Test/CMock/tasks/tasks_1_utest.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,45 @@ void test_xTaskIncrementTick_success_unblock_tasks2( void )
27352735
ASSERT_APP_TICK_HOOK_CALLED();
27362736
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
27372737
}
2738+
2739+
void test_xTaskIncrementTick_success_unblock_tasks3( void )
2740+
{
2741+
BaseType_t ret_task_incrementtick;
2742+
TaskHandle_t task_handle;
2743+
2744+
/* Setup. */
2745+
create_task_priority = 4;
2746+
task_handle = create_task();
2747+
block_task( task_handle );
2748+
create_task_priority = 3;
2749+
( void ) create_task();
2750+
ptcb = task_handle;
2751+
xPendedTicks = 3;
2752+
xTickCount = 50;
2753+
xNextTaskUnblockTime = 49; /* Task 2 is due unblocking. */
2754+
uxSchedulerSuspended = pdFALSE;
2755+
2756+
/* Expectations. */
2757+
listLIST_IS_EMPTY_ExpectAndReturn( pxDelayedTaskList, pdFALSE );
2758+
listGET_OWNER_OF_HEAD_ENTRY_ExpectAndReturn( pxDelayedTaskList, task_handle );
2759+
listGET_LIST_ITEM_VALUE_ExpectAndReturn( &task_handle->xStateListItem,
2760+
xTickCount - 5 );
2761+
listREMOVE_ITEM_Expect( &( task_handle->xStateListItem ) );
2762+
listLIST_ITEM_CONTAINER_ExpectAndReturn( &task_handle->xEventListItem, NULL );
2763+
listINSERT_END_Expect( &pxReadyTasksLists[ task_handle->uxPriority ],
2764+
&task_handle->xStateListItem );
2765+
listLIST_IS_EMPTY_ExpectAndReturn( pxDelayedTaskList, pdTRUE );
2766+
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ task_handle->uxPriority ], 1 );
2767+
2768+
/* API Call */
2769+
ret_task_incrementtick = xTaskIncrementTick();
2770+
2771+
/* Validations */
2772+
TEST_ASSERT_EQUAL( pdTRUE, ret_task_incrementtick );
2773+
ASSERT_APP_TICK_HOOK_NOT_CALLED();
2774+
TEST_ASSERT_EQUAL( portMAX_DELAY, xNextTaskUnblockTime );
2775+
}
2776+
27382777
/* testing INCLUDE_xTaskAbortDelay */
27392778
void test_xTaskAbortDelay_fail_current_task( void )
27402779
{

0 commit comments

Comments
 (0)