From ce28d945163e6b17b2652b2b58a3dd9fdd2804a6 Mon Sep 17 00:00:00 2001 From: Darian <32921628+Dazza0@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:51:43 +0800 Subject: [PATCH] Update unit tests due to task notification changes (#1177) This commit updates the CMock unit tests according to the changes introduced to https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/982. Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> --- .../smp/config_assert/config_assert_utest.c | 1 + ...tiple_priorities_no_timeslice_mock_utest.c | 52 ++++--------------- FreeRTOS/Test/CMock/tasks/tasks_1_utest.c | 24 +++++++-- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c b/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c index 1b70c461c..b738b1554 100644 --- a/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c +++ b/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c @@ -583,6 +583,7 @@ void test_prvGetExpectedIdleTime_assert_nextUnblock_lt_xTickCount( void ) /* vTaskSuspendAll */ vFakePortAssertIfISR_Expect(); + vFakePortGetCoreID_ExpectAndReturn( 0 ); ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); vFakePortGetTaskLock_Expect(); vFakePortGetISRLock_Expect(); diff --git a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice_mock/covg_multiple_priorities_no_timeslice_mock_utest.c b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice_mock/covg_multiple_priorities_no_timeslice_mock_utest.c index f6f59d73a..53079d74a 100644 --- a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice_mock/covg_multiple_priorities_no_timeslice_mock_utest.c +++ b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice_mock/covg_multiple_priorities_no_timeslice_mock_utest.c @@ -619,46 +619,6 @@ void test_coverage_vTaskPreemptionDisable_null_handle( void ) TEST_ASSERT_EQUAL( pdTRUE, pxCurrentTCBs[ 0 ]->xPreemptionDisable ); } -/** - * @brief This test ensures that when we call vTaskSuspendAll and we task of the - * current core has a critical nesting count of 1 only the scheduler is - * suspended - * - * Coverage - * @code{c} - * vTaskSuspendAll(); - * - * if( portGET_CRITICAL_NESTING_COUNT() == 0U ) - * - * @endcode - * - * configNUMBER_OF_CORES > 1 - */ -void test_coverage_vTaskSuspendAll_critical_nesting_ne_zero( void ) -{ - TCB_t xTask = { 0 }; - - xTask.uxCriticalNesting = 1; - pxCurrentTCBs[ 0 ] = &xTask; - xSchedulerRunning = pdTRUE; - uxSchedulerSuspended = 0U; - - /* Test Expectations */ - vFakePortAssertIfISR_Expect(); - ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); - vFakePortGetTaskLock_Expect(); - vFakePortGetCoreID_ExpectAndReturn( 0 ); - vFakePortGetISRLock_Expect(); - vFakePortReleaseISRLock_Expect(); - vFakePortClearInterruptMask_Expect( 0 ); - - /* API Call */ - vTaskSuspendAll(); - - /* Test Verifications */ - TEST_ASSERT_EQUAL( 1, uxSchedulerSuspended ); -} - /** * @brief This test ensures that when we call prvGetExpectedIdleTime and the top * ready priority is greater than the idle task, we return zero, @@ -840,12 +800,17 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_1( void ) /* vTaskSuspendAll */ vFakePortAssertIfISR_Expect(); + vFakePortGetCoreID_ExpectAndReturn( 0 ); ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); vFakePortGetTaskLock_Expect(); + /* prvCheckForRunStateChange */ + vFakePortAssertIfISR_Expect(); + vFakePortGetCoreID_ExpectAndReturn( 0 ); + /* End of prvCheckForRunStateChange */ vFakePortGetISRLock_Expect(); vFakePortReleaseISRLock_Expect(); vFakePortClearInterruptMask_Expect( 0 ); - + /* End of vTaskSuspendAll */ ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); vFakePortGetCoreID_ExpectAndReturn( 0 ); @@ -941,11 +906,16 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_2( void ) /* vTaskSuspendAll */ vFakePortAssertIfISR_Stub( port_assert_if_isr_cb ); + vFakePortGetCoreID_ExpectAndReturn( 0 ); ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); vFakePortGetTaskLock_Expect(); + /* prvCheckForRunStateChange */ + vFakePortGetCoreID_ExpectAndReturn( 0 ); + /* End of prvCheckForRunStateChange */ vFakePortGetISRLock_Expect(); vFakePortReleaseISRLock_Expect(); vFakePortClearInterruptMask_Expect( 0 ); + /* End of vTaskSuspendAll */ ulFakePortSetInterruptMask_ExpectAndReturn( 0 ); diff --git a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c index 8a376d8e1..b931400b3 100644 --- a/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c +++ b/FreeRTOS/Test/CMock/tasks/tasks_1_utest.c @@ -4928,6 +4928,8 @@ void test_ulTaskGenericNotifyTake_success( void ) task_handle = create_task(); task_handle->ulNotifiedValue[ uxIndexToWait ] = 0; /* Expectations */ + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret_gen_notify_take = ulTaskGenericNotifyTake( uxIndexToWait, pdFALSE, @@ -4948,6 +4950,8 @@ void test_ulTaskGenericNotifyTake_success2( void ) task_handle = create_task(); task_handle->ulNotifiedValue[ uxIndexToWait ] = 2; /* Expectations */ + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret_gen_notify_take = ulTaskGenericNotifyTake( uxIndexToWait, pdFALSE, @@ -4968,6 +4972,8 @@ void test_ulTaskGenericNotifyTake_success_clear_count( void ) task_handle = create_task(); task_handle->ulNotifiedValue[ uxIndexToWait ] = 5; /* Expectations */ + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret_gen_notify_take = ulTaskGenericNotifyTake( uxIndexToWait, pdTRUE, @@ -4993,7 +4999,8 @@ void test_ulTaskGenericNotifyTake_success_yield( void ) uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, 1 ); listSET_LIST_ITEM_VALUE_Expect( &ptcb->xStateListItem, xTickCount + 9 ); vListInsert_Expect( pxDelayedTaskList, &ptcb->xStateListItem ); - listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret_gen_notify_take = ulTaskGenericNotifyTake( uxIndexToWait, pdFALSE, @@ -5607,16 +5614,21 @@ void test_xTaskGenericNotifyWait_success_notif_received( void ) TaskHandle_t task_handle; + /* Setup */ task_handle = create_task(); ptcb = task_handle; ptcb->ucNotifyState[ uxIndexToWait ] = 2; /* taskNOTIFICATION_RECEIVED */ ptcb->ulNotifiedValue[ uxIndexToWait ] = 5; - + /* Expectations */ + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); + /* API Call */ ret = xTaskGenericNotifyWait( uxIndexToWait, ulBitsToClearOnEntry, ulBitsToClearOnExit, &pullNotificationValue, xTicksToWait ); + /* Validations */ TEST_ASSERT_EQUAL( pdTRUE, ret ); TEST_ASSERT_EQUAL( 5, pullNotificationValue ); ASSERT_PORT_YIELD_WITHIN_API_NOT_CALLED(); @@ -5667,12 +5679,14 @@ void test_xTaskGenericNotifyWait_success_notif_not_received_no_wait( void ) TaskHandle_t task_handle; + /* Setup */ task_handle = create_task(); ptcb = task_handle; ptcb->ucNotifyState[ uxIndexToWait ] = 1; /* taskWAITING_NOTIFICATION */ ptcb->ulNotifiedValue[ uxIndexToWait ] = 5; /* Expectations */ - + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret = xTaskGenericNotifyWait( uxIndexToWait, ulBitsToClearOnEntry, @@ -5695,12 +5709,14 @@ void test_xTaskGenericNotifyWait_success_notif_not_received_pull_null( void ) TaskHandle_t task_handle; + /* Setup */ task_handle = create_task(); ptcb = task_handle; ptcb->ucNotifyState[ uxIndexToWait ] = 1; /* taskWAITING_NOTIFICATION */ ptcb->ulNotifiedValue[ uxIndexToWait ] = 5; /* Expectations */ - + /* xTaskResumeAll */ + listLIST_IS_EMPTY_ExpectAndReturn( &xPendingReadyList, pdTRUE ); /* API Call */ ret = xTaskGenericNotifyWait( uxIndexToWait, ulBitsToClearOnEntry,