From 2f5b186ea2a9dde008eca3f79b609ad69f9dbc76 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Thu, 25 May 2023 16:24:35 +0530 Subject: [PATCH] Add unit tests for kernel PR #679 (#1015) Also, fix the broken tests by that PR. Signed-off-by: Gaurav Aggarwal --- FreeRTOS/Test/CMock/tasks/tasks_1_utest.c | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c index 90e3f2d2e51..559858e0ed6 100644 --- a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c +++ b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c @@ -1721,6 +1721,29 @@ void test_eTaskGetState_success_current_tcb( void ) TEST_ASSERT_EQUAL( eRunning, ret_task_state ); } +void test_eTaskGetState_success_not_current_tcb_pending_ready( void ) +{ + TaskHandle_t task_handle; + + create_task_priority = 3; + task_handle = create_task(); + create_task_priority = 5; + create_task(); + ptcb = ( TCB_t * ) task_handle; + TEST_ASSERT_NOT_EQUAL( pxCurrentTCB, ptcb ); + eTaskState ret_task_state; + /* Expectations */ + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, + NULL ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + &xPendingReadyList ); + + /* API Call */ + ret_task_state = eTaskGetState( task_handle ); + /* Validations */ + TEST_ASSERT_EQUAL( eReady, ret_task_state ); +} + void test_eTaskGetState_success_not_current_tcb_blocked_delayed( void ) { TaskHandle_t task_handle; @@ -1735,6 +1758,8 @@ void test_eTaskGetState_success_not_current_tcb_blocked_delayed( void ) /* Expectations */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, pxDelayedTaskList ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1756,6 +1781,8 @@ void test_eTaskGetState_success_not_current_tcb_blocked_overflow( void ) /* Expectations */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, pxOverflowDelayedTaskList ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1777,6 +1804,8 @@ void test_eTaskGetState_success_not_current_tcb_ready( void ) /* Expectations */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, &pxReadyTasksLists[ 0 ] ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1800,6 +1829,8 @@ void test_eTaskGetState_success_not_current_tcb_suspended( void ) &xSuspendedTaskList ); listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1821,6 +1852,8 @@ void test_eTaskGetState_success_not_current_tcb_deleted( void ) /* Expectations */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, &xTasksWaitingTermination ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1842,6 +1875,9 @@ void test_eTaskGetState_success_not_current_tcb_deleted_not_found( void ) /* Expectations */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, NULL ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); + /* API Call */ ret_task_state = eTaskGetState( task_handle ); /* Validations */ @@ -1870,6 +1906,8 @@ void test_eTaskGetState_success_not_current_tcb_wait_notif( void ) &xSuspendedTaskList ); listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + NULL ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); @@ -1893,6 +1931,8 @@ void test_eTaskGetState_success_not_current_tcb_blocked( void ) &xSuspendedTaskList ); listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, &xSuspendedTaskList ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + &xSuspendedTaskList ); /* API Call */ ret_task_state = eTaskGetState( task_handle ); /* Validations */ @@ -3101,6 +3141,7 @@ void test_xTaskAbortDelay_success( void ) /* eTaskGetState */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, pxDelayedTaskList ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL ); /* back */ uxListRemove_ExpectAndReturn( &tcb->xStateListItem, pdTRUE ); listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL ); @@ -3147,6 +3188,8 @@ void test_xTaskAbortDelay_success_notdelayed( void ) /* eTaskGetState */ listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xStateListItem, pxDelayedTaskList ); + listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, + pxDelayedTaskList ); /* back */ uxListRemove_ExpectAndReturn( &tcb->xStateListItem, pdTRUE ); listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem,