From d603c9b1ba39a5f1c1ce8ea42397c72cc5bfcaa3 Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:34:14 +0800 Subject: [PATCH] Update for vTaskSuspend SMP unit test (#1160) --- .../smp/config_assert/config_assert_utest.c | 34 ++++++++++++++----- ...tiple_priorities_no_timeslice_mock_utest.c | 12 +++++++ 2 files changed, 37 insertions(+), 9 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 a99773c53d..58a524b1c1 100644 --- a/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c +++ b/FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c @@ -410,19 +410,27 @@ void test_vTaskDelete_assert_scheduler_suspended_eq_1( void ) } /** - * @brief This test ensures that the code asserts when a task is suspended while - * the scheduler is suspended + * @brief vTaskSuspend - scheduler suspended assertion. + * + * This test ensures that the code asserts when a task is suspended while + * the scheduler is suspended * * Coverage * @code{c} - * vTaskDelete( xTaskToDelete ); - * - * configASSERT( uxSchedulerSuspended == 0 ); - * + * if( xSchedulerRunning != pdFALSE ) + * { + * if( pxTCB->xTaskRunState == ( BaseType_t ) portGET_CORE_ID() ) + * { + * configASSERT( uxSchedulerSuspended == 0 ); + * vTaskYieldWithinAPI(); + * } + * else + * { + * prvYieldCore( pxTCB->xTaskRunState ); + * } + * } * @endcode - * - * configNUMBER_OF_CORES > 1 - * INCLUDE_vTaskSuspend + * configASSERT( uxSchedulerSuspended == 0 ) is triggered. */ void test_vTaskSuspend_assert_schedulersuspended_ne_zero( void ) { @@ -438,7 +446,15 @@ void test_vTaskSuspend_assert_schedulersuspended_ne_zero( void ) uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( NULL ); vListInsertEnd_ExpectAnyArgs(); + vFakePortExitCriticalSection_Expect(); + + /* Reset the next expected unblock time if scheduler is running. */ + vFakePortEnterCriticalSection_Expect(); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); + vFakePortExitCriticalSection_Expect(); + + /* Check task run state in critical section. */ + vFakePortEnterCriticalSection_Expect(); vFakePortGetCoreID_ExpectAndReturn( 1 ); EXPECT_ASSERT_BREAK( vTaskSuspend( xTaskToSuspend ) ); 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 06e0613791..b238ad1e7f 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 @@ -239,6 +239,10 @@ void test_coverage_vTaskSuspend_scheduler_running_false( void ) vListInsertEnd_ExpectAnyArgs(); vFakePortExitCriticalSection_Expect(); + /* Enter critical section to check task run state. */ + vFakePortEnterCriticalSection_Expect(); + vFakePortExitCriticalSection_Expect(); + /* API call. */ vTaskSuspend( &xTaskTCBs[ 0 ] ); @@ -277,6 +281,10 @@ void test_coverage_vTaskSuspend_running_state_below_range( void ) vListInsertEnd_ExpectAnyArgs(); vFakePortExitCriticalSection_Expect(); + /* Enter critical section to check task run state. */ + vFakePortEnterCriticalSection_Expect(); + vFakePortExitCriticalSection_Expect(); + /* API call. */ vTaskSuspend( &xTaskTCBs[ 0 ] ); @@ -314,6 +322,10 @@ void test_coverage_vTaskSuspend_running_state_above_range( void ) vListInsertEnd_ExpectAnyArgs(); vFakePortExitCriticalSection_Expect(); + /* Enter critical section to check task run state. */ + vFakePortEnterCriticalSection_Expect(); + vFakePortExitCriticalSection_Expect(); + /* API call. */ vTaskSuspend( &xTaskTCBs[ 0 ] );