mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-14 00:37:44 -04:00
Fix unit test for vTaskEndShceduler (#1163)
* Update unit test for vTaskEndScheduler change * test_coverage_vTaskDelete_scheduler_not_running is removed due to vTaskDelete implementation change --------- Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
This commit is contained in:
parent
8422d79383
commit
269b16a03a
2 changed files with 46 additions and 55 deletions
|
@ -500,57 +500,6 @@ void test_coverage_prvYieldCore_runstate_eq_yielding( void )
|
||||||
TEST_ASSERT_EQUAL( 1, task.xTaskRunState ); /* nothing has changed */
|
TEST_ASSERT_EQUAL( 1, task.xTaskRunState ); /* nothing has changed */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief vTaskDelete - scheduler not running.
|
|
||||||
*
|
|
||||||
* This test ensures that if vTaskDelete is called and the scheuler is
|
|
||||||
* not running, the core is not yielded, but it is removed from the
|
|
||||||
* stateList, the eventList and inserted in the taskwaitingtermination
|
|
||||||
* list, the uxdeletedtaskwaiting for cleanup is increased and the
|
|
||||||
* uxtasknumber is increased
|
|
||||||
*
|
|
||||||
* <b>Coverage</b>
|
|
||||||
* @code{c}
|
|
||||||
* if( ( xSchedulerRunning != pdFALSE ) &&
|
|
||||||
* ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) )
|
|
||||||
* ...
|
|
||||||
* @endcode
|
|
||||||
* ( xSchedulerRunning != pdFALSE ) is false.
|
|
||||||
*/
|
|
||||||
void test_coverage_vTaskDelete_scheduler_not_running( void )
|
|
||||||
{
|
|
||||||
TCB_t task;
|
|
||||||
TaskHandle_t xTaskToDelete;
|
|
||||||
|
|
||||||
task.xTaskRunState = 1; /* running on core 1 */
|
|
||||||
xTaskToDelete = &task;
|
|
||||||
pxCurrentTCBs[ 0 ] = &task;
|
|
||||||
|
|
||||||
xSchedulerRunning = pdFALSE;
|
|
||||||
|
|
||||||
uxDeletedTasksWaitingCleanUp = 0;
|
|
||||||
uxTaskNumber = 1;
|
|
||||||
|
|
||||||
/* Test Expectations */
|
|
||||||
vFakePortEnterCriticalSection_Expect();
|
|
||||||
uxListRemove_ExpectAnyArgsAndReturn( 0 );
|
|
||||||
listLIST_ITEM_CONTAINER_ExpectAnyArgsAndReturn( NULL );
|
|
||||||
|
|
||||||
/* if task != taskTaskNOT_RUNNING */
|
|
||||||
vListInsertEnd_ExpectAnyArgs();
|
|
||||||
vPortCurrentTaskDying_ExpectAnyArgs();
|
|
||||||
|
|
||||||
vFakePortExitCriticalSection_Expect();
|
|
||||||
|
|
||||||
|
|
||||||
/* API Call */
|
|
||||||
vTaskDelete( xTaskToDelete );
|
|
||||||
|
|
||||||
/* Test Verifications */
|
|
||||||
TEST_ASSERT_EQUAL( 1, uxDeletedTasksWaitingCleanUp );
|
|
||||||
TEST_ASSERT_EQUAL( 2, uxTaskNumber );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This test ensures that if xTask Delete is called and the scheuler is
|
* @brief This test ensures that if xTask Delete is called and the scheuler is
|
||||||
* running while the task runstate is more that the configNUMBER_OF_CORES,
|
* running while the task runstate is more that the configNUMBER_OF_CORES,
|
||||||
|
|
|
@ -886,10 +886,12 @@ void test_xTaskCreate_fail_tcb_malloc( void )
|
||||||
/* -------------------------- INCLUDE_vTaskDelete --------------------------- */
|
/* -------------------------- INCLUDE_vTaskDelete --------------------------- */
|
||||||
void test_vTaskDelete_success_current_task( void )
|
void test_vTaskDelete_success_current_task( void )
|
||||||
{
|
{
|
||||||
|
/* Setup */
|
||||||
ptcb = ( TCB_t * ) create_task();
|
ptcb = ( TCB_t * ) create_task();
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
||||||
|
|
||||||
|
xSchedulerRunning = pdTRUE;
|
||||||
|
|
||||||
/* Expectations */
|
/* Expectations */
|
||||||
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdPASS );
|
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdPASS );
|
||||||
listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL );
|
listLIST_ITEM_CONTAINER_ExpectAndReturn( &ptcb->xEventListItem, NULL );
|
||||||
|
@ -908,6 +910,8 @@ void test_vTaskDelete_success_current_task_ready_empty( void )
|
||||||
ptcb = ( TCB_t * ) create_task();
|
ptcb = ( TCB_t * ) create_task();
|
||||||
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
||||||
|
|
||||||
|
xSchedulerRunning = pdTRUE;
|
||||||
|
|
||||||
/* Expectations */
|
/* Expectations */
|
||||||
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdFAIL );
|
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdFAIL );
|
||||||
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ ptcb->uxPriority ], 0 );
|
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ ptcb->uxPriority ], 0 );
|
||||||
|
@ -923,10 +927,12 @@ void test_vTaskDelete_success_current_task_ready_empty( void )
|
||||||
|
|
||||||
void test_vTaskDelete_success_current_task_ready_empty_null_task( void )
|
void test_vTaskDelete_success_current_task_ready_empty_null_task( void )
|
||||||
{
|
{
|
||||||
|
/* Setup */
|
||||||
ptcb = ( TCB_t * ) create_task();
|
ptcb = ( TCB_t * ) create_task();
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
||||||
|
|
||||||
|
xSchedulerRunning = pdTRUE;
|
||||||
|
|
||||||
/* Expectations */
|
/* Expectations */
|
||||||
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdFAIL );
|
uxListRemove_ExpectAndReturn( &ptcb->xStateListItem, pdFAIL );
|
||||||
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ ptcb->uxPriority ], 1 );
|
listCURRENT_LIST_LENGTH_ExpectAndReturn( &pxReadyTasksLists[ ptcb->uxPriority ], 1 );
|
||||||
|
@ -1122,8 +1128,44 @@ void test_vTaskStartScheduler_idle_fail( void )
|
||||||
|
|
||||||
void test_vTaskEndScheduler_success()
|
void test_vTaskEndScheduler_success()
|
||||||
{
|
{
|
||||||
|
/* Setup. */
|
||||||
|
TCB_t * pIdleTaskTCB = ( TCB_t * ) create_task();
|
||||||
|
TCB_t * pTimerTaskTCB = ( TCB_t * ) create_task();
|
||||||
|
|
||||||
|
uxCurrentNumberOfTasks = 0;
|
||||||
|
pIdleTaskTCB = ( TCB_t * ) create_task();
|
||||||
|
TEST_ASSERT_EQUAL( 1, uxCurrentNumberOfTasks );
|
||||||
|
xIdleTaskHandles[ 0 ] = ( TaskHandle_t ) pIdleTaskTCB;
|
||||||
|
pTimerTaskTCB = ( TCB_t * ) create_task();
|
||||||
|
TEST_ASSERT_EQUAL( 2, uxCurrentNumberOfTasks );
|
||||||
|
ptcb = ( TCB_t * ) create_task();
|
||||||
|
TEST_ASSERT_EQUAL( 3, uxCurrentNumberOfTasks );
|
||||||
|
|
||||||
|
xSchedulerRunning = pdTRUE;
|
||||||
|
uxDeletedTasksWaitingCleanUp = 0U; /* prvCheckTasksWaitingTermination function call. */
|
||||||
|
|
||||||
|
/* Expectations. */
|
||||||
|
/* Delete the timer task. */
|
||||||
|
xTimerGetTimerDaemonTaskHandle_ExpectAndReturn( pTimerTaskTCB );
|
||||||
|
uxListRemove_ExpectAndReturn( &pTimerTaskTCB->xStateListItem, pdPASS );
|
||||||
|
listLIST_ITEM_CONTAINER_ExpectAndReturn( &pTimerTaskTCB->xEventListItem, NULL );
|
||||||
|
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
|
||||||
|
vPortFree_ExpectAnyArgs();
|
||||||
|
vPortFree_ExpectAnyArgs();
|
||||||
|
|
||||||
|
/* Delete the idle task. */
|
||||||
|
uxListRemove_ExpectAndReturn( &pIdleTaskTCB->xStateListItem, pdPASS );
|
||||||
|
listLIST_ITEM_CONTAINER_ExpectAndReturn( &pIdleTaskTCB->xEventListItem, NULL );
|
||||||
|
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
|
||||||
|
vPortFree_ExpectAnyArgs();
|
||||||
|
vPortFree_ExpectAnyArgs();
|
||||||
|
|
||||||
vPortEndScheduler_Expect();
|
vPortEndScheduler_Expect();
|
||||||
|
|
||||||
|
/* API call. */
|
||||||
vTaskEndScheduler();
|
vTaskEndScheduler();
|
||||||
|
|
||||||
|
/* Verification. */
|
||||||
TEST_ASSERT_EQUAL( pdFALSE, xSchedulerRunning );
|
TEST_ASSERT_EQUAL( pdFALSE, xSchedulerRunning );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4429,8 +4471,8 @@ void test_xTaskGetSchedulerState_not_running( void )
|
||||||
{
|
{
|
||||||
BaseType_t ret_sched_state;
|
BaseType_t ret_sched_state;
|
||||||
|
|
||||||
vPortEndScheduler_Expect();
|
xSchedulerRunning = pdFALSE;
|
||||||
vTaskEndScheduler();
|
|
||||||
ret_sched_state = xTaskGetSchedulerState();
|
ret_sched_state = xTaskGetSchedulerState();
|
||||||
TEST_ASSERT_EQUAL( taskSCHEDULER_NOT_STARTED, ret_sched_state );
|
TEST_ASSERT_EQUAL( taskSCHEDULER_NOT_STARTED, ret_sched_state );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue