3838 * Includes
3939 */
4040
41- #include "sample_lib.h"
41+ #include "sample_lib.h" /* For SAMPLE_LIB_Function */
4242#include "sample_app_coveragetest_common.h"
4343#include "ut_sample_app.h"
4444
45- /* to get the SAMPLE_LIB_Function() declaration */
46-
45+ /*
46+ * Unit test check event hook information
47+ */
4748typedef struct
4849{
4950 uint16 ExpectedEvent ;
@@ -113,12 +114,25 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou
113114 return 0 ;
114115}
115116
117+ /* Macro to get expected event name */
118+ #define UT_CHECKEVENT_SETUP (Evt , ExpectedEvent , ExpectedFormat ) \
119+ UT_CheckEvent_Setup_Impl(Evt, ExpectedEvent, #ExpectedEvent, ExpectedFormat)
120+
116121/*
117122 * Helper function to set up for event checking
118123 * This attaches the hook function to CFE_EVS_SendEvent
119124 */
120- static void UT_CheckEvent_Setup (UT_CheckEvent_t * Evt , uint16 ExpectedEvent , const char * ExpectedFormat )
125+ static void UT_CheckEvent_Setup_Impl (UT_CheckEvent_t * Evt , uint16 ExpectedEvent , const char * EventName ,
126+ const char * ExpectedFormat )
121127{
128+ if (ExpectedFormat == NULL )
129+ {
130+ UtPrintf ("CheckEvent will match: %s(%u)" , EventName , ExpectedEvent );
131+ }
132+ else
133+ {
134+ UtPrintf ("CheckEvent will match: %s(%u), \"%s\"" , EventName , ExpectedEvent , ExpectedFormat );
135+ }
122136 memset (Evt , 0 , sizeof (* Evt ));
123137 Evt -> ExpectedEvent = ExpectedEvent ;
124138 Evt -> ExpectedFormat = ExpectedFormat ;
@@ -155,7 +169,7 @@ void Test_SAMPLE_APP_Main(void)
155169 /*
156170 * Confirm that CFE_ES_ExitApp() was called at the end of execution
157171 */
158- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_ExitApp )) == 1 , "CFE_ES_ExitApp() called" );
172+ UtAssert_STUB_COUNT ( CFE_ES_ExitApp , 1 );
159173
160174 /*
161175 * Now set up individual cases for each of the error paths.
@@ -179,14 +193,8 @@ void Test_SAMPLE_APP_Main(void)
179193 /*
180194 * This can validate that the internal "RunStatus" was
181195 * set to CFE_ES_RunStatus_APP_ERROR, by querying the struct directly.
182- *
183- * It is always advisable to include the _actual_ values
184- * when asserting on conditions, so if/when it fails, the
185- * log will show what the incorrect value was.
186196 */
187- UtAssert_True (SAMPLE_APP_Data .RunStatus == CFE_ES_RunStatus_APP_ERROR ,
188- "SAMPLE_APP_Data.RunStatus (%lu) == CFE_ES_RunStatus_APP_ERROR" ,
189- (unsigned long )SAMPLE_APP_Data .RunStatus );
197+ UtAssert_UINT32_EQ (SAMPLE_APP_Data .RunStatus , CFE_ES_RunStatus_APP_ERROR );
190198
191199 /*
192200 * Note that CFE_ES_RunLoop returns a boolean value,
@@ -210,7 +218,7 @@ void Test_SAMPLE_APP_Main(void)
210218 /*
211219 * Confirm that CFE_SB_ReceiveBuffer() (inside the loop) was called
212220 */
213- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_SB_ReceiveBuffer )) == 1 , "CFE_SB_ReceiveBuffer() called" );
221+ UtAssert_STUB_COUNT ( CFE_SB_ReceiveBuffer , 1 );
214222
215223 /*
216224 * Now also make the CFE_SB_ReceiveBuffer call fail,
@@ -219,7 +227,7 @@ void Test_SAMPLE_APP_Main(void)
219227 */
220228 UT_SetDeferredRetcode (UT_KEY (CFE_ES_RunLoop ), 1 , true);
221229 UT_SetDeferredRetcode (UT_KEY (CFE_SB_ReceiveBuffer ), 1 , CFE_SB_PIPE_RD_ERR );
222- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_PIPE_ERR_EID , "SAMPLE APP: SB Pipe Read Error, App Will Exit" );
230+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_PIPE_ERR_EID , "SAMPLE APP: SB Pipe Read Error, App Will Exit" );
223231
224232 /*
225233 * Invoke again
@@ -229,8 +237,7 @@ void Test_SAMPLE_APP_Main(void)
229237 /*
230238 * Confirm that the event was generated
231239 */
232- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_PIPE_ERR_EID generated (%u)" ,
233- (unsigned int )EventTest .MatchCount );
240+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
234241}
235242
236243void Test_SAMPLE_APP_Init (void )
@@ -241,31 +248,31 @@ void Test_SAMPLE_APP_Init(void)
241248 */
242249
243250 /* nominal case should return CFE_SUCCESS */
244- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_SUCCESS );
251+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_SUCCESS );
245252
246253 /* trigger a failure for each of the sub-calls,
247254 * and confirm a write to syslog for each.
248255 * Note that this count accumulates, because the status
249256 * is _not_ reset between these test cases. */
250257 UT_SetDeferredRetcode (UT_KEY (CFE_EVS_Register ), 1 , CFE_EVS_INVALID_PARAMETER );
251- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_EVS_INVALID_PARAMETER );
252- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 1 , "CFE_ES_WriteToSysLog() called" );
258+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_EVS_INVALID_PARAMETER );
259+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 1 );
253260
254261 UT_SetDeferredRetcode (UT_KEY (CFE_SB_CreatePipe ), 1 , CFE_SB_BAD_ARGUMENT );
255- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
256- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 2 , "CFE_ES_WriteToSysLog() called" );
262+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
263+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 2 );
257264
258265 UT_SetDeferredRetcode (UT_KEY (CFE_SB_Subscribe ), 1 , CFE_SB_BAD_ARGUMENT );
259- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
260- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 3 , "CFE_ES_WriteToSysLog() called" );
266+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
267+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 3 );
261268
262269 UT_SetDeferredRetcode (UT_KEY (CFE_SB_Subscribe ), 2 , CFE_SB_BAD_ARGUMENT );
263- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
264- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 4 , "CFE_ES_WriteToSysLog() called" );
270+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_SB_BAD_ARGUMENT );
271+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 4 );
265272
266273 UT_SetDeferredRetcode (UT_KEY (CFE_TBL_Register ), 1 , CFE_TBL_ERR_INVALID_OPTIONS );
267- UT_TEST_FUNCTION_RC (SAMPLE_APP_Init (), CFE_TBL_ERR_INVALID_OPTIONS );
268- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 5 , "CFE_ES_WriteToSysLog() called" );
274+ UtAssert_INT32_EQ (SAMPLE_APP_Init (), CFE_TBL_ERR_INVALID_OPTIONS );
275+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 5 );
269276}
270277
271278void Test_SAMPLE_APP_ProcessCommandPacket (void )
@@ -286,7 +293,7 @@ void Test_SAMPLE_APP_ProcessCommandPacket(void)
286293 UT_CheckEvent_t EventTest ;
287294
288295 memset (& TestMsg , 0 , sizeof (TestMsg ));
289- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_INVALID_MSGID_ERR_EID , "SAMPLE: invalid command packet,MID = 0x%x" );
296+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_INVALID_MSGID_ERR_EID , "SAMPLE: invalid command packet,MID = 0x%x" );
290297
291298 /*
292299 * The CFE_MSG_GetMsgId() stub uses a data buffer to hold the
@@ -312,8 +319,7 @@ void Test_SAMPLE_APP_ProcessCommandPacket(void)
312319 /*
313320 * Confirm that the event was generated only _once_
314321 */
315- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_COMMAND_ERR_EID generated (%u)" ,
316- (unsigned int )EventTest .MatchCount );
322+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
317323}
318324
319325void Test_SAMPLE_APP_ProcessGroundCommand (void )
@@ -351,24 +357,22 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
351357 Size = sizeof (TestMsg .Noop );
352358 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetFcnCode ), & FcnCode , sizeof (FcnCode ), false);
353359 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetSize ), & Size , sizeof (Size ), false);
354- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_COMMANDNOP_INF_EID , NULL );
360+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_COMMANDNOP_INF_EID , NULL );
355361
356362 SAMPLE_APP_ProcessGroundCommand (& TestMsg .SBBuf );
357363
358- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_COMMANDNOP_INF_EID generated (%u)" ,
359- (unsigned int )EventTest .MatchCount );
364+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
360365
361366 /* test dispatch of RESET */
362367 FcnCode = SAMPLE_APP_RESET_COUNTERS_CC ;
363368 Size = sizeof (TestMsg .Reset );
364369 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetFcnCode ), & FcnCode , sizeof (FcnCode ), false);
365370 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetSize ), & Size , sizeof (Size ), false);
366- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_COMMANDRST_INF_EID , NULL );
371+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_COMMANDRST_INF_EID , NULL );
367372
368373 SAMPLE_APP_ProcessGroundCommand (& TestMsg .SBBuf );
369374
370- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_COMMANDRST_INF_EID generated (%u)" ,
371- (unsigned int )EventTest .MatchCount );
375+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
372376
373377 /* test dispatch of PROCESS */
374378 /* note this will end up calling SAMPLE_APP_Process(), and as such it needs to
@@ -384,14 +388,13 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
384388 /* test an invalid CC */
385389 FcnCode = 1000 ;
386390 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetFcnCode ), & FcnCode , sizeof (FcnCode ), false);
387- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_COMMAND_ERR_EID , "Invalid ground command code: CC = %d" );
391+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_COMMAND_ERR_EID , "Invalid ground command code: CC = %d" );
388392 SAMPLE_APP_ProcessGroundCommand (& TestMsg .SBBuf );
389393
390394 /*
391395 * Confirm that the event was generated only _once_
392396 */
393- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_COMMAND_ERR_EID generated (%u)" ,
394- (unsigned int )EventTest .MatchCount );
397+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
395398}
396399
397400void Test_SAMPLE_APP_ReportHousekeeping (void )
@@ -417,17 +420,17 @@ void Test_SAMPLE_APP_ReportHousekeeping(void)
417420 SAMPLE_APP_ProcessCommandPacket ((CFE_SB_Buffer_t * )NULL );
418421
419422 /* Confirm message sent*/
420- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_SB_TransmitMsg )) == 1 , "CFE_SB_TransmitMsg() called once" );
423+ UtAssert_STUB_COUNT ( CFE_SB_TransmitMsg , 1 );
421424 UtAssert_ADDRESS_EQ (MsgSend , & SAMPLE_APP_Data .HkTlm );
422425
423426 /* Confirm timestamp msg address */
424- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_SB_TimeStampMsg )) == 1 , "CFE_SB_TimeStampMsg() called once" );
427+ UtAssert_STUB_COUNT ( CFE_SB_TimeStampMsg , 1 );
425428 UtAssert_ADDRESS_EQ (MsgTimestamp , & SAMPLE_APP_Data .HkTlm );
426429
427430 /*
428431 * Confirm that the CFE_TBL_Manage() call was done
429432 */
430- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_TBL_Manage )) == 1 , "CFE_TBL_Manage() called" );
433+ UtAssert_STUB_COUNT ( CFE_TBL_Manage , 1 );
431434}
432435
433436void Test_SAMPLE_APP_NoopCmd (void )
@@ -442,15 +445,14 @@ void Test_SAMPLE_APP_NoopCmd(void)
442445 memset (& TestMsg , 0 , sizeof (TestMsg ));
443446
444447 /* test dispatch of NOOP */
445- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_COMMANDNOP_INF_EID , NULL );
448+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_COMMANDNOP_INF_EID , NULL );
446449
447- UT_TEST_FUNCTION_RC (SAMPLE_APP_Noop (& TestMsg ), CFE_SUCCESS );
450+ UtAssert_INT32_EQ (SAMPLE_APP_Noop (& TestMsg ), CFE_SUCCESS );
448451
449452 /*
450453 * Confirm that the event was generated
451454 */
452- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_COMMANDNOP_INF_EID generated (%u)" ,
453- (unsigned int )EventTest .MatchCount );
455+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
454456}
455457
456458void Test_SAMPLE_APP_ResetCounters (void )
@@ -464,15 +466,14 @@ void Test_SAMPLE_APP_ResetCounters(void)
464466
465467 memset (& TestMsg , 0 , sizeof (TestMsg ));
466468
467- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_COMMANDRST_INF_EID , "SAMPLE: RESET command" );
469+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_COMMANDRST_INF_EID , "SAMPLE: RESET command" );
468470
469- UT_TEST_FUNCTION_RC (SAMPLE_APP_ResetCounters (& TestMsg ), CFE_SUCCESS );
471+ UtAssert_INT32_EQ (SAMPLE_APP_ResetCounters (& TestMsg ), CFE_SUCCESS );
470472
471473 /*
472474 * Confirm that the event was generated
473475 */
474- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_COMMANDRST_INF_EID generated (%u)" ,
475- (unsigned int )EventTest .MatchCount );
476+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
476477}
477478
478479void Test_SAMPLE_APP_ProcessCC (void )
@@ -492,25 +493,25 @@ void Test_SAMPLE_APP_ProcessCC(void)
492493 TestTblData .Int1 = 40 ;
493494 TestTblData .Int2 = 50 ;
494495 UT_SetDataBuffer (UT_KEY (CFE_TBL_GetAddress ), & TblPtr , sizeof (TblPtr ), false);
495- UT_TEST_FUNCTION_RC (SAMPLE_APP_Process (& TestMsg ), CFE_SUCCESS );
496+ UtAssert_INT32_EQ (SAMPLE_APP_Process (& TestMsg ), CFE_SUCCESS );
496497
497498 /*
498499 * Confirm that the CFE_TBL_GetAddress() call was done
499500 */
500- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_TBL_GetAddress )) == 1 , "CFE_TBL_GetAddress() called" );
501+ UtAssert_STUB_COUNT ( CFE_TBL_GetAddress , 1 );
501502
502503 /*
503504 * Confirm that the SAMPLE_LIB_Function() call was done
504505 * NOTE: This stub is provided by the sample_lib library
505506 */
506- UtAssert_True ( UT_GetStubCount ( UT_KEY ( SAMPLE_LIB_Function )) == 1 , "SAMPLE_LIB_Function() called" );
507+ UtAssert_STUB_COUNT ( SAMPLE_LIB_Function , 1 );
507508
508509 /*
509510 * Configure the CFE_TBL_GetAddress function to return an error
510511 * Exercise the error return path
511512 */
512513 UT_SetDefaultReturnValue (UT_KEY (CFE_TBL_GetAddress ), CFE_TBL_ERR_UNREGISTERED );
513- UT_TEST_FUNCTION_RC (SAMPLE_APP_Process (& TestMsg ), CFE_TBL_ERR_UNREGISTERED );
514+ UtAssert_INT32_EQ (SAMPLE_APP_Process (& TestMsg ), CFE_TBL_ERR_UNREGISTERED );
514515}
515516
516517void Test_SAMPLE_APP_VerifyCmdLength (void )
@@ -528,16 +529,15 @@ void Test_SAMPLE_APP_VerifyCmdLength(void)
528529 * test a match case
529530 */
530531 UT_SetDataBuffer (UT_KEY (CFE_MSG_GetSize ), & size , sizeof (size ), false);
531- UT_CheckEvent_Setup (& EventTest , SAMPLE_APP_LEN_ERR_EID ,
532+ UT_CHECKEVENT_SETUP (& EventTest , SAMPLE_APP_LEN_ERR_EID ,
532533 "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u" );
533534
534535 SAMPLE_APP_VerifyCmdLength (NULL , size );
535536
536537 /*
537538 * Confirm that the event was NOT generated
538539 */
539- UtAssert_True (EventTest .MatchCount == 0 , "SAMPLE_APP_LEN_ERR_EID NOT generated (%u)" ,
540- (unsigned int )EventTest .MatchCount );
540+ UtAssert_UINT32_EQ (EventTest .MatchCount , 0 );
541541
542542 /*
543543 * test a mismatch case
@@ -550,8 +550,7 @@ void Test_SAMPLE_APP_VerifyCmdLength(void)
550550 /*
551551 * Confirm that the event WAS generated
552552 */
553- UtAssert_True (EventTest .MatchCount == 1 , "SAMPLE_APP_LEN_ERR_EID generated (%u)" ,
554- (unsigned int )EventTest .MatchCount );
553+ UtAssert_UINT32_EQ (EventTest .MatchCount , 1 );
555554}
556555
557556void Test_SAMPLE_APP_TblValidationFunc (void )
@@ -565,11 +564,11 @@ void Test_SAMPLE_APP_TblValidationFunc(void)
565564 memset (& TestTblData , 0 , sizeof (TestTblData ));
566565
567566 /* nominal case (0) should succeed */
568- UT_TEST_FUNCTION_RC (SAMPLE_APP_TblValidationFunc (& TestTblData ), CFE_SUCCESS );
567+ UtAssert_INT32_EQ (SAMPLE_APP_TblValidationFunc (& TestTblData ), CFE_SUCCESS );
569568
570569 /* error case should return SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE */
571570 TestTblData .Int1 = 1 + SAMPLE_APP_TBL_ELEMENT_1_MAX ;
572- UT_TEST_FUNCTION_RC (SAMPLE_APP_TblValidationFunc (& TestTblData ), SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE );
571+ UtAssert_INT32_EQ (SAMPLE_APP_TblValidationFunc (& TestTblData ), SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE );
573572}
574573
575574void Test_SAMPLE_APP_GetCrc (void )
@@ -590,11 +589,11 @@ void Test_SAMPLE_APP_GetCrc(void)
590589
591590 UT_SetDefaultReturnValue (UT_KEY (CFE_TBL_GetInfo ), CFE_TBL_ERR_INVALID_NAME );
592591 SAMPLE_APP_GetCrc ("UT" );
593- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 1 , "CFE_ES_WriteToSysLog() called" );
592+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 1 );
594593
595594 UT_ClearDefaultReturnValue (UT_KEY (CFE_TBL_GetInfo ));
596595 SAMPLE_APP_GetCrc ("UT" );
597- UtAssert_True ( UT_GetStubCount ( UT_KEY ( CFE_ES_WriteToSysLog )) == 2 , "CFE_ES_WriteToSysLog() called" );
596+ UtAssert_STUB_COUNT ( CFE_ES_WriteToSysLog , 2 );
598597}
599598
600599/*
0 commit comments