Skip to content

Commit 2dcc47e

Browse files
authored
Update unit test for TASK and ISR lock macros (FreeRTOS#1319)
This is needed for PR - FreeRTOS#1212.
1 parent 365a479 commit 2dcc47e

File tree

11 files changed

+113
-83
lines changed

11 files changed

+113
-83
lines changed

FreeRTOS/Test/CMock/config/fake_port.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
5050

5151
void portSetupTCB_CB( void * tcb );
5252

53-
void vFakePortGetISRLock( void );
54-
void vFakePortReleaseISRLock( void );
55-
void vFakePortGetTaskLock( void );
56-
void vFakePortReleaseTaskLock( void );
53+
void vFakePortGetISRLock( BaseType_t xCoreID );
54+
void vFakePortReleaseISRLock( BaseType_t xCoreID );
55+
void vFakePortGetTaskLock( BaseType_t xCoreID );
56+
void vFakePortReleaseTaskLock( BaseType_t xCoreID );
5757

5858
void vFakePortAssertIfISR();
5959
BaseType_t vFakePortCheckIfInISR( void );

FreeRTOS/Test/CMock/config/portmacro.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,37 +125,37 @@ typedef unsigned long UBaseType_t;
125125
/*-----------------------------------------------------------*/
126126

127127
#define portSAVE_CONTEXT()
128-
#define portYIELD() vFakePortYield()
129-
#define portYIELD_WITHIN_API() vFakePortYieldWithinAPI()
130-
#define portYIELD_FROM_ISR() vFakePortYieldFromISR()
128+
#define portYIELD() vFakePortYield()
129+
#define portYIELD_WITHIN_API() vFakePortYieldWithinAPI()
130+
#define portYIELD_FROM_ISR() vFakePortYieldFromISR()
131131

132132
/* Critical section handling. */
133-
#define portDISABLE_INTERRUPTS() vFakePortDisableInterrupts()
134-
#define portENABLE_INTERRUPTS() vFakePortEnableInterrupts()
133+
#define portDISABLE_INTERRUPTS() vFakePortDisableInterrupts()
134+
#define portENABLE_INTERRUPTS() vFakePortEnableInterrupts()
135135
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) \
136136
vFakePortClearInterruptMaskFromISR( x )
137137
#define portSET_INTERRUPT_MASK_FROM_ISR() \
138138
ulFakePortSetInterruptMaskFromISR()
139-
#define portSET_INTERRUPT_MASK() ulFakePortSetInterruptMask()
140-
#define portCLEAR_INTERRUPT_MASK( x ) vFakePortClearInterruptMask( x )
139+
#define portSET_INTERRUPT_MASK() ulFakePortSetInterruptMask()
140+
#define portCLEAR_INTERRUPT_MASK( x ) vFakePortClearInterruptMask( x )
141141
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() \
142142
vFakePortAssertIfInterruptPriorityInvalid()
143-
#define portENTER_CRITICAL() vFakePortEnterCriticalSection()
144-
#define portEXIT_CRITICAL() vFakePortExitCriticalSection()
145-
#define portGET_ISR_LOCK() vFakePortGetISRLock()
146-
#define portRELEASE_ISR_LOCK() vFakePortReleaseISRLock()
147-
#define portGET_TASK_LOCK() vFakePortGetTaskLock()
148-
#define portRELEASE_TASK_LOCK() vFakePortReleaseTaskLock()
149-
150-
#define portCHECK_IF_IN_ISR() vFakePortCheckIfInISR()
151-
#define portRESTORE_INTERRUPTS( x ) vFakePortRestoreInterrupts( x )
143+
#define portENTER_CRITICAL() vFakePortEnterCriticalSection()
144+
#define portEXIT_CRITICAL() vFakePortExitCriticalSection()
145+
#define portGET_ISR_LOCK( xCoreID ) vFakePortGetISRLock( xCoreID )
146+
#define portRELEASE_ISR_LOCK( xCoreID ) vFakePortReleaseISRLock( xCoreID )
147+
#define portGET_TASK_LOCK( xCoreID ) vFakePortGetTaskLock( xCoreID )
148+
#define portRELEASE_TASK_LOCK( xCoreID ) vFakePortReleaseTaskLock( xCoreID )
149+
150+
#define portCHECK_IF_IN_ISR() vFakePortCheckIfInISR()
151+
#define portRESTORE_INTERRUPTS( x ) vFakePortRestoreInterrupts( x )
152152
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) \
153153
vPortCurrentTaskDying( ( pvTaskToDelete ), ( pxPendYield ) )
154-
#define portSETUP_TCB( pxTCB ) portSetupTCB_CB( pxTCB );
155-
#define portASSERT_IF_IN_ISR() vFakePortAssertIfISR();
154+
#define portSETUP_TCB( pxTCB ) portSetupTCB_CB( pxTCB );
155+
#define portASSERT_IF_IN_ISR() vFakePortAssertIfISR();
156156

157-
#define portGET_CORE_ID() vFakePortGetCoreID()
158-
#define portYIELD_CORE( x ) vFakePortYieldCore( x )
157+
#define portGET_CORE_ID() vFakePortGetCoreID()
158+
#define portYIELD_CORE( x ) vFakePortYieldCore( x )
159159

160160
#define portENTER_CRITICAL_FROM_ISR vFakePortEnterCriticalFromISR
161161
#define portEXIT_CRITICAL_FROM_ISR vFakePortExitCriticalFromISR

FreeRTOS/Test/CMock/smp/config_assert/config_assert_utest.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ void test_prvSelectHighestPriorityTask_assert_scheduler_running_false( void )
311311
xSchedulerRunning = pdFALSE; /* causes the assert */
312312
uxSchedulerSuspended = pdFALSE;
313313

314-
vFakePortGetTaskLock_Expect();
315-
vFakePortGetISRLock_Expect();
314+
vFakePortGetTaskLock_Expect( 1 );
315+
vFakePortGetISRLock_Expect( 1 );
316316

317317
EXPECT_ASSERT_BREAK( vTaskSwitchContext( 1 ) );
318318
validate_and_clear_assertions();
@@ -344,8 +344,8 @@ void test_prvSelectHighestPriorityTask_assert_coreid_ne_runstate( void )
344344
xSchedulerRunning = pdTRUE;
345345
uxSchedulerSuspended = pdFALSE;
346346

347-
vFakePortGetTaskLock_Expect();
348-
vFakePortGetISRLock_Expect();
347+
vFakePortGetTaskLock_Expect( 0 );
348+
vFakePortGetISRLock_Expect( 0 );
349349

350350
listIS_CONTAINED_WITHIN_ExpectAnyArgsAndReturn( pdFALSE );
351351
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
@@ -467,8 +467,8 @@ void test_vTaskSwitchContext_assert_nexting_count_ne_zero( void )
467467

468468
pxCurrentTCBs[ 1 ] = &currentTCB;
469469

470-
vFakePortGetTaskLock_Expect();
471-
vFakePortGetISRLock_Expect();
470+
vFakePortGetTaskLock_Expect( 1 );
471+
vFakePortGetISRLock_Expect( 1 );
472472

473473
EXPECT_ASSERT_BREAK( vTaskSwitchContext( 1 ) );
474474

@@ -576,9 +576,10 @@ void test_prvGetExpectedIdleTime_assert_nextUnblock_lt_xTickCount( void )
576576
vFakePortAssertIfISR_Expect();
577577
ulFakePortSetInterruptMask_ExpectAndReturn( 0 );
578578
vFakePortGetCoreID_ExpectAndReturn( 0 );
579-
vFakePortGetTaskLock_Expect();
580-
vFakePortGetISRLock_Expect();
581-
vFakePortReleaseISRLock_Expect();
579+
vFakePortGetTaskLock_Expect( 0 );
580+
vFakePortGetCoreID_ExpectAndReturn( 0 );
581+
vFakePortGetISRLock_Expect( 0 );
582+
vFakePortReleaseISRLock_Expect( 0 );
582583
vFakePortClearInterruptMask_Expect( 0 );
583584

584585
/* API Call */

FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice/covg_multiple_priorities_no_timeslice_utest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,7 @@ void test_coverage_xTaskResumeAll_task_in_pending_ready_list( void )
33283328
vFakePortExitCriticalSection_StubWithCallback( NULL );
33293329

33303330
/* Expectations. */
3331-
vFakePortReleaseTaskLock_Expect();
3331+
vFakePortReleaseTaskLock_Expect( 0 );
33323332
vFakePortExitCriticalSection_Expect();
33333333

33343334
/* API call. */
@@ -3398,7 +3398,7 @@ void test_coverage_xTaskResumeAll_task_in_pending_ready_list_uxpriority_lesser(
33983398
vFakePortExitCriticalSection_StubWithCallback( NULL );
33993399

34003400
/* Expectations. */
3401-
vFakePortReleaseTaskLock_Expect();
3401+
vFakePortReleaseTaskLock_Expect( 0 );
34023402
vFakePortExitCriticalSection_Expect();
34033403

34043404
/* API call. */

FreeRTOS/Test/CMock/smp/multiple_priorities_no_timeslice_mock/covg_multiple_priorities_no_timeslice_mock_utest.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,14 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_1( void )
802802
vFakePortAssertIfISR_Expect();
803803
ulFakePortSetInterruptMask_ExpectAndReturn( 0 );
804804
vFakePortGetCoreID_ExpectAndReturn( 0 );
805-
vFakePortGetTaskLock_Expect();
805+
vFakePortGetTaskLock_Expect( 0 );
806806
/* prvCheckForRunStateChange */
807807
vFakePortGetCoreID_ExpectAndReturn( 0 );
808808
vFakePortAssertIfISR_Expect();
809809
/* End of prvCheckForRunStateChange */
810-
vFakePortGetISRLock_Expect();
811-
vFakePortReleaseISRLock_Expect();
810+
vFakePortGetCoreID_ExpectAndReturn( 0 );
811+
vFakePortGetISRLock_Expect( 0 );
812+
vFakePortReleaseISRLock_Expect( 0 );
812813
vFakePortClearInterruptMask_Expect( 0 );
813814
/* End of vTaskSuspendAll */
814815

@@ -826,7 +827,7 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_1( void )
826827

827828
vFakePortEnterCriticalSection_Expect();
828829
vFakePortGetCoreID_ExpectAndReturn( 0 );
829-
vFakePortReleaseTaskLock_Expect();
830+
vFakePortReleaseTaskLock_Expect( 0 );
830831
vFakePortExitCriticalSection_Expect();
831832

832833
listCURRENT_LIST_LENGTH_ExpectAndThrow( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ),
@@ -908,12 +909,13 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_2( void )
908909
vFakePortAssertIfISR_Stub( port_assert_if_isr_cb );
909910
ulFakePortSetInterruptMask_ExpectAndReturn( 0 );
910911
vFakePortGetCoreID_ExpectAndReturn( 0 );
911-
vFakePortGetTaskLock_Expect();
912+
vFakePortGetTaskLock_Expect( 0 );
912913
/* prvCheckForRunStateChange */
913914
vFakePortGetCoreID_ExpectAndReturn( 0 );
914915
/* End of prvCheckForRunStateChange */
915-
vFakePortGetISRLock_Expect();
916-
vFakePortReleaseISRLock_Expect();
916+
vFakePortGetCoreID_ExpectAndReturn( 0 );
917+
vFakePortGetISRLock_Expect( 0 );
918+
vFakePortReleaseISRLock_Expect( 0 );
917919
vFakePortClearInterruptMask_Expect( 0 );
918920
/* End of vTaskSuspendAll */
919921

@@ -926,7 +928,7 @@ void test_coverage_prvGetExpectedIdleTime_ready_list_eq_2( void )
926928

927929
vFakePortEnterCriticalSection_Expect();
928930
vFakePortGetCoreID_ExpectAndReturn( 0 );
929-
vFakePortReleaseTaskLock_Expect();
931+
vFakePortReleaseTaskLock_Expect( 0 );
930932
vFakePortExitCriticalSection_Expect();
931933

932934
listCURRENT_LIST_LENGTH_ExpectAndThrow( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ),

FreeRTOS/Test/CMock/smp/single_priority_no_timeslice/covg_single_priority_no_timeslice_utest.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ void test_coverage_prvCheckForRunStateChange_first_time_critical_section( void )
143143
/* Expection. */
144144
vFakePortEnableInterrupts_StubWithCallback( prvPortEnableInterruptsCb );
145145

146-
vFakePortReleaseISRLock_Expect();
147-
vFakePortReleaseTaskLock_Expect();
148-
vFakePortGetTaskLock_Expect();
149-
vFakePortGetISRLock_Expect();
146+
vFakePortReleaseISRLock_Expect( 0 );
147+
vFakePortReleaseTaskLock_Expect( 0 );
148+
vFakePortGetTaskLock_Expect( 0 );
149+
vFakePortGetISRLock_Expect( 0 );
150150

151151
/* API Call. */
152152
prvCheckForRunStateChange();
@@ -192,10 +192,10 @@ void test_coverage_prvCheckForRunStateChange_first_time_suspend_scheduler( void
192192
/* Expection. */
193193
vFakePortEnableInterrupts_StubWithCallback( prvPortEnableInterruptsCb );
194194

195-
vFakePortReleaseTaskLock_Expect();
196-
vFakePortGetTaskLock_Expect();
197-
vFakePortGetISRLock_Expect();
198-
vFakePortReleaseISRLock_Expect();
195+
vFakePortReleaseTaskLock_Expect( 0 );
196+
vFakePortGetTaskLock_Expect( 0 );
197+
vFakePortGetISRLock_Expect( 0 );
198+
vFakePortReleaseISRLock_Expect( 0 );
199199

200200
/* API Call. */
201201
prvCheckForRunStateChange();
@@ -234,6 +234,7 @@ void test_task_get_system_state( void )
234234

235235
/*Get System states */
236236
int no_of_tasks = uxTaskGetSystemState( tsk_status_array, MAX_TASKS, NULL );
237+
237238
TEST_ASSERT( ( no_of_tasks > 0 ) && ( no_of_tasks <= MAX_TASKS ) );
238239
}
239240

@@ -257,6 +258,7 @@ void test_task_get_system_state_custom_time( void )
257258

258259
/*Get System states */
259260
int no_of_tasks = uxTaskGetSystemState( tsk_status_array, MAX_TASKS, &ulTotalRunTime );
261+
260262
TEST_ASSERT( ( no_of_tasks > 0 ) && ( no_of_tasks <= MAX_TASKS ) );
261263
}
262264

@@ -279,6 +281,7 @@ void test_task_get_system_state_unavilable_task_space( void )
279281

280282
/*Get System states */
281283
int no_of_tasks = uxTaskGetSystemState( tsk_status_array, MAX_TASKS - 1, NULL );
284+
282285
TEST_ASSERT( ( no_of_tasks == 0 ) && ( no_of_tasks <= MAX_TASKS ) );
283286
}
284287

FreeRTOS/Test/CMock/smp/smp_utest_common.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ unsigned int vFakePortGetCoreIDCallback( int cmock_num_calls )
241241
return ( unsigned int ) xCurrentCoreId;
242242
}
243243

244-
void vFakePortGetISRLockCallback( int cmock_num_calls )
244+
void vFakePortGetISRLockCallback( BaseType_t xCoreID,
245+
int cmock_num_calls )
245246
{
246247
int i;
247248

@@ -250,25 +251,27 @@ void vFakePortGetISRLockCallback( int cmock_num_calls )
250251
/* Ensure that no other core is in the critical section. */
251252
for( i = 0; i < configNUMBER_OF_CORES; i++ )
252253
{
253-
if( i != xCurrentCoreId )
254+
if( i != xCoreID )
254255
{
255256
TEST_ASSERT_MESSAGE( xIsrLockCount[ i ] == 0, "vFakePortGetISRLock xIsrLockCount[ i ] > 0" );
256257
TEST_ASSERT_MESSAGE( xTaskLockCount[ i ] == 0, "vFakePortGetISRLock xTaskLockCount[ i ] > 0" );
257258
}
258259
}
259260

260-
xIsrLockCount[ xCurrentCoreId ]++;
261+
xIsrLockCount[ xCoreID ]++;
261262
}
262263

263-
void vFakePortReleaseISRLockCallback( int cmock_num_calls )
264+
void vFakePortReleaseISRLockCallback( BaseType_t xCoreID,
265+
int cmock_num_calls )
264266
{
265267
( void ) cmock_num_calls;
266268

267-
TEST_ASSERT_MESSAGE( xIsrLockCount[ xCurrentCoreId ] > 0, "xIsrLockCount[ xCurrentCoreId ] <= 0" );
268-
xIsrLockCount[ xCurrentCoreId ]--;
269+
TEST_ASSERT_MESSAGE( xIsrLockCount[ xCoreID ] > 0, "xIsrLockCount[ xCoreID ] <= 0" );
270+
xIsrLockCount[ xCoreID ]--;
269271
}
270272

271-
void vFakePortGetTaskLockCallback( int cmock_num_calls )
273+
void vFakePortGetTaskLockCallback( BaseType_t xCoreID,
274+
int cmock_num_calls )
272275
{
273276
int i;
274277

@@ -277,36 +280,38 @@ void vFakePortGetTaskLockCallback( int cmock_num_calls )
277280
/* Ensure that no other core is in the critical section. */
278281
for( i = 0; i < configNUMBER_OF_CORES; i++ )
279282
{
280-
if( i != xCurrentCoreId )
283+
if( i != xCoreID )
281284
{
282285
TEST_ASSERT_MESSAGE( xIsrLockCount[ i ] == 0, "vFakePortGetTaskLock xIsrLockCount[ i ] > 0" );
283286
TEST_ASSERT_MESSAGE( xTaskLockCount[ i ] == 0, "vFakePortGetTaskLock xTaskLockCount[ i ] > 0" );
284287
}
285288
}
286289

287-
xTaskLockCount[ xCurrentCoreId ]++;
290+
xTaskLockCount[ xCoreID ]++;
288291
}
289292

290-
void vFakePortReleaseTaskLockCallback( int cmock_num_calls )
293+
void vFakePortReleaseTaskLockCallback( BaseType_t xCoreID,
294+
int cmock_num_calls )
291295
{
292296
( void ) cmock_num_calls;
293297

294-
TEST_ASSERT_MESSAGE( xTaskLockCount[ xCurrentCoreId ] > 0, "xTaskLockCount[ xCurrentCoreId ] <= 0" );
295-
xTaskLockCount[ xCurrentCoreId ]--;
298+
TEST_ASSERT_MESSAGE( xTaskLockCount[ xCoreID ] > 0, "xTaskLockCount[ xCoreID ] <= 0" );
299+
xTaskLockCount[ xCoreID ]--;
296300

297301
/* When releasing the ISR lock, check if any core is waiting to yield. */
298-
if( xTaskLockCount[ xCurrentCoreId ] == 0 )
302+
if( xTaskLockCount[ xCoreID ] == 0 )
299303
{
300304
vYieldCores();
301305
}
302306
}
303307

304-
void vFakePortReleaseTaskLockAsyncCallback( int cmock_num_calls )
308+
void vFakePortReleaseTaskLockAsyncCallback( BaseType_t xCoreID,
309+
int cmock_num_calls )
305310
{
306311
( void ) cmock_num_calls;
307312

308-
TEST_ASSERT_MESSAGE( xTaskLockCount[ xCurrentCoreId ] > 0, "xTaskLockCount[ xCurrentCoreId ] <= 0" );
309-
xTaskLockCount[ xCurrentCoreId ]--;
313+
TEST_ASSERT_MESSAGE( xTaskLockCount[ xCoreID ] > 0, "xTaskLockCount[ xCoreID ] <= 0" );
314+
xTaskLockCount[ xCoreID ]--;
310315
}
311316

312317
portBASE_TYPE vFakePortEnterCriticalFromISRCallback( int cmock_num_calls )

0 commit comments

Comments
 (0)