summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>2022-11-04 00:18:53 +0530
committerGitHub <noreply@github.com>2022-11-03 11:48:53 -0700
commitaa316fc1b4f5398cdb0b8bdacd18c2591ad082f8 (patch)
tree2aafb30ed34462fa6c3fa1a2bfba949b128d5d24
parent4f87f485d561c883066d28211fea16a9810044ae (diff)
downloadfreertos-git-aa316fc1b4f5398cdb0b8bdacd18c2591ad082f8.tar.gz
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>
-rw-r--r--FreeRTOS/Test/CMock/tasks/tasks_1_utest.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c
index 9bce93e18..2517f3ffc 100644
--- a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c
+++ b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c
@@ -2652,6 +2652,10 @@ void test_xTaskIncrementTick_success_update_next_unblock( void )
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 )
{
BaseType_t ret_task_incrementtick;
@@ -2693,6 +2697,10 @@ void test_xTaskIncrementTick_success_unblock_tasks( void )
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 )
{
BaseType_t ret_task_incrementtick;
@@ -2735,6 +2743,49 @@ void test_xTaskIncrementTick_success_unblock_tasks2( void )
ASSERT_APP_TICK_HOOK_CALLED();
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 */
void test_xTaskAbortDelay_fail_current_task( void )
{