From 31d6ace7e0551b9220c2cb53af3d95179fa28dd9 Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:46:21 +0800 Subject: [PATCH] Add eTaskConfirmSleepModeStatus unit test for SMP (#1118) * Add eTaskConfirmSleepModeStatus unit test for SMP --- ...tiple_priorities_no_timeslice_mock_utest.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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 2ac0955ad..2510cdbcc 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 @@ -116,6 +116,9 @@ extern List_t pxReadyTasksLists[ configMAX_PRIORITIES ]; extern UBaseType_t uxTaskNumber; extern volatile TickType_t xTickCount; extern volatile TickType_t xNextTaskUnblockTime; +extern List_t xSuspendedTaskList; +extern List_t xPendingReadyList; +extern volatile TickType_t xPendedTicks; /* =========================== EXTERN FUNCTIONS =========================== */ @@ -1257,3 +1260,51 @@ void test_coverage_xTaskGetSchedulerState_scheduler_not_running_and_suspended( v TEST_ASSERT_EQUAL( taskSCHEDULER_SUSPENDED, xRet ); } + +/** + * @brief eTaskConfirmSleepModeStatus - confirm no task is waiting for timeout. + * + * All the tasks except idle tasks are in suspended list. The system can stay in + * a low power state. This is a regression test for SMP to ensure uxNonApplicationTasks + * is set to configNUMBER_OF_CORES in the implementation. + * + * Coverage + * @code{c} + * #if ( INCLUDE_vTaskSuspend == 1 ) + * else if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) ) + * { + * ... + * eReturn = eNoTasksWaitingTimeout; + * } + * #endif + * @endcode + * ( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) ) is true. + */ +void test_coverage_eTaskConfirmSleepModeStatus_no_tasks_waiting_timeout( void ) +{ + eSleepModeStatus eRetStatus; + UBaseType_t uxSuspendedTask; + + /* Setup */ + xPendedTicks = 0; + uxSuspendedTask = 3U; /* Assume system has 3 suspended task. */ + xYieldPendings[ 0 ] = 0; + + /* System has uxSuspendedTask number of suspended task and configNUMBER_OF_CORES + * idle tasks. */ + uxCurrentNumberOfTasks = uxSuspendedTask + configNUMBER_OF_CORES; + + /* Expectations */ + listCURRENT_LIST_LENGTH_ExpectAndReturn( &xPendingReadyList, 0 ); + vFakePortGetCoreID_ExpectAndReturn( 0 ); + listCURRENT_LIST_LENGTH_ExpectAndReturn( &xSuspendedTaskList, uxSuspendedTask ); + + /* API Call */ + eRetStatus = eTaskConfirmSleepModeStatus(); + + /* Validations */ + + /* If the implementation sets uxNonApplicationTasks to a fixed number 1 instead of + * configNUMBER_OF_CORES, the following assertion will be violated. */ + TEST_ASSERT_EQUAL( eNoTasksWaitingTimeout, eRetStatus ); +}