From 174b4562f4accf9c7653e77786bf3254bb9c2e1a Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Wed, 15 Nov 2023 15:39:50 +0800 Subject: [PATCH] Add test cases to cover prvCreateIdleTasks for SMP (#1114) * Add test cases to cover vApplicationGetIdleTaskMemory and vApplicationGetPassiveIdleTaskMemory for prvCreateIdleTasks --- ...g_multiple_priorities_no_timeslice_utest.c | 68 +++++++++++++++++-- .../multiple_priorities_no_timeslice_utest.c | 24 +++++-- 2 files changed, 79 insertions(+), 13 deletions(-) diff --git a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/covg_multiple_priorities_no_timeslice_utest.c b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/covg_multiple_priorities_no_timeslice_utest.c index c09082268e..7b340ec4d9 100644 --- a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/covg_multiple_priorities_no_timeslice_utest.c +++ b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/covg_multiple_priorities_no_timeslice_utest.c @@ -70,6 +70,7 @@ extern List_t xDelayedTaskList1; extern List_t xDelayedTaskList2; extern List_t * pxDelayedTaskList; extern List_t * pxOverflowDelayedTaskList; +extern TaskHandle_t xIdleTaskHandles[ configNUMBER_OF_CORES ]; /* =========================== EXTERN FUNCTIONS =========================== */ extern void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ); @@ -83,10 +84,14 @@ extern void prvCheckTasksWaitingTermination( void ); extern void prvDeleteTCB( TCB_t * pxTCB ); extern TCB_t * prvSearchForNameWithinSingleList( List_t * pxList, const char pcNameToQuery[] ); +extern BaseType_t prvCreateIdleTasks( void ); /* ============================== Global VARIABLES ============================== */ TaskHandle_t xTaskHandles[ configNUMBER_OF_CORES ] = { NULL }; +static StaticTask_t xIdleTaskTCBs[ configNUMBER_OF_CORES ]; +static StackType_t uxIdleTaskStacks[ configNUMBER_OF_CORES ][ configMINIMAL_STACK_SIZE ]; + /* ============================ Unity Fixtures ============================ */ /*! called before each testcase */ void setUp( void ) @@ -175,19 +180,24 @@ static void prvInitialiseTestStack( TCB_t * pxTCB, ( void ) pxTopOfStack; } - /* ============================ FreeRTOS static allocate function ============================ */ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize, - BaseType_t xCoreId ) + uint32_t * pulIdleTaskStackSize ) { - static StaticTask_t xIdleTaskTCBs[ configNUMBER_OF_CORES ]; - static StackType_t uxIdleTaskStacks[ configNUMBER_OF_CORES ][ configMINIMAL_STACK_SIZE ]; + *ppxIdleTaskTCBBuffer = &( xIdleTaskTCBs[ 0 ] ); + *ppxIdleTaskStackBuffer = &( uxIdleTaskStacks[ 0 ][ 0 ] ); + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} - *ppxIdleTaskTCBBuffer = &( xIdleTaskTCBs[ xCoreId ] ); - *ppxIdleTaskStackBuffer = &( uxIdleTaskStacks[ xCoreId ][ 0 ] ); +void vApplicationGetPassiveIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize, + BaseType_t xPassiveIdleTaskIndex ) +{ + *ppxIdleTaskTCBBuffer = &( xIdleTaskTCBs[ xPassiveIdleTaskIndex + 1 ] ); + *ppxIdleTaskStackBuffer = &( uxIdleTaskStacks[ xPassiveIdleTaskIndex + 1 ][ 0 ] ); *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; } @@ -4625,3 +4635,47 @@ void test_coverage_prvSearchForNameWithinSingleList_long_task_name( void ) /* Validation. */ TEST_ASSERT_EQUAL( NULL, pReturnedTCB ); } + +/** + * @brief prvCreateIdleTasks - get static idle task memory. + * + * Verify get static idle task memory is correct. + * + * Coverage + * @code{c} + * #if ( configNUMBER_OF_CORES == 1 ) + * ... + * #else + * { + * if( xCoreID == 0 ) + * { + * vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize ); + * } + * else + * { + * vApplicationGetPassiveIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize, xCoreID - 1 ); + * } + * } + * #endif + * @endcode + * ( xCoreID == 0 ) both true and false. + */ +void test_coverage_prvCreateIdleTasks_get_static_memory( void ) +{ + BaseType_t xReturn; + BaseType_t xCoreID; + + /* API call. */ + xReturn = prvCreateIdleTasks(); + + /* Validation. */ + TEST_ASSERT_EQUAL( pdTRUE, xReturn ); /* Verify this function should return without error. */ + + /* Verify that the idle tasks TCB and stack buffer are provided by vApplicationGetIdleTaskMemory and + * vApplicationGetPassiveIdleTaskMemory. */ + for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ ) + { + TEST_ASSERT_EQUAL( xIdleTaskHandles[ xCoreID ], &xIdleTaskTCBs[ xCoreID ] ); + TEST_ASSERT_EQUAL( xIdleTaskHandles[ xCoreID ].pxStack, &uxIdleTaskStacks[ xCoreID ][ 0 ] ); + } +} diff --git a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c index 97855a2cf7..3757ba8803 100644 --- a/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c +++ b/FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/multiple_priorities_no_timeslice_utest.c @@ -80,14 +80,26 @@ int suiteTearDown( int numFailures ) void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize, - BaseType_t xCoreId ) + uint32_t * pulIdleTaskStackSize ) { - static StaticTask_t xIdleTaskTCBs[ configNUMBER_OF_CORES ]; - static StackType_t uxIdleTaskStacks[ configNUMBER_OF_CORES ][ configMINIMAL_STACK_SIZE ]; + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; - *ppxIdleTaskTCBBuffer = &( xIdleTaskTCBs[ xCoreId ] ); - *ppxIdleTaskStackBuffer = &( uxIdleTaskStacks[ xCoreId ][ 0 ] ); + *ppxIdleTaskTCBBuffer = &( xIdleTaskTCB ); + *ppxIdleTaskStackBuffer = &( uxIdleTaskStack[ 0 ] ); + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} + +void vApplicationGetPassiveIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize, + BaseType_t xPassiveIdleTaskIndex ) +{ + static StaticTask_t xIdleTaskTCBs[ configNUMBER_OF_CORES - 1 ]; + static StackType_t uxIdleTaskStacks[ configNUMBER_OF_CORES - 1 ][ configMINIMAL_STACK_SIZE ]; + + *ppxIdleTaskTCBBuffer = &( xIdleTaskTCBs[ xPassiveIdleTaskIndex ] ); + *ppxIdleTaskStackBuffer = &( uxIdleTaskStacks[ xPassiveIdleTaskIndex ][ 0 ] ); *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; }