diff --git a/README.md b/README.md index 30eefc8..5072efd 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ sample_app is an example for how to build and link an application in cFS. See al ## Version History +### Development Build: 1.1.10 +- Test cases now compare an expected event string with a string derived from the spec string and arguments that were output by the unit under test. +- Replace references to `ccsds.h` types with the `cfe_sb.h`-provided type. +- See + ### Development Build: 1.1.9 - Applies the CFE_SB_MsgIdToValue() and CFE_SB_ValueToMsgId() routines where compatibility with an integer MsgId is necessary - syslog prints, events, compile-time MID #define values. diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 1686c5d..75bffae 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -271,7 +271,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg ) break; case SAMPLE_APP_SEND_HK_MID: - SAMPLE_ReportHousekeeping((CCSDS_CommandPacket_t *)Msg); + SAMPLE_ReportHousekeeping((CFE_SB_CmdHdr_t *)Msg); break; default: @@ -348,7 +348,7 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) /* telemetry, packetize it and send it to the housekeeping task via */ /* the software bus */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) +int32 SAMPLE_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg ) { int i; diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index a7c2c47..14ab525 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -116,7 +116,7 @@ void SAMPLE_AppMain(void); int32 SAMPLE_AppInit(void); void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg); void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg); -int32 SAMPLE_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg); +int32 SAMPLE_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg); int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); int32 SAMPLE_Process(const SAMPLE_Process_t *Msg); int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg); diff --git a/fsw/src/sample_app_version.h b/fsw/src/sample_app_version.h index 5fdc40f..c577a98 100644 --- a/fsw/src/sample_app_version.h +++ b/fsw/src/sample_app_version.h @@ -33,7 +33,7 @@ #define SAMPLE_APP_MAJOR_VERSION 1 #define SAMPLE_APP_MINOR_VERSION 1 -#define SAMPLE_APP_REVISION 9 +#define SAMPLE_APP_REVISION 10 #define SAMPLE_APP_MISSION_REV 0 diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 81cd5fc..e3da007 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -49,16 +49,19 @@ typedef struct { uint16 ExpectedEvent; uint32 MatchCount; + const char *ExpectedText; } UT_CheckEvent_t; /* * An example hook function to check for a specific event. */ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, - uint32 CallCount, const UT_StubContext_t *Context) + uint32 CallCount, const UT_StubContext_t *Context, va_list va) { UT_CheckEvent_t *State = UserObj; - uint16 *EventIdPtr; + char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; + uint16 EventId; + const char *Spec; /* * The CFE_EVS_SendEvent stub passes the EventID as the @@ -66,10 +69,36 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, */ if (Context->ArgCount > 0) { - EventIdPtr = (uint16*)Context->ArgPtr[0]; - if (*EventIdPtr == State->ExpectedEvent) + EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16); + if (EventId == State->ExpectedEvent) { - ++State->MatchCount; + /* + * Example of how to validate the full argument set. + * If reference text was supplied, also check against this. + * + * NOTE: While this can be done, use with discretion - This isn't really + * verifying that the FSW code unit generated the correct event text, + * rather it is validating what the system snprintf() library function + * produces when passed the format string and args. + * + * __This derived string is not an actual output of the unit under test__ + */ + if (State->ExpectedText != NULL) + { + Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *); + if (Spec != NULL) + { + vsnprintf(TestText, sizeof(TestText), Spec, va); + if (strcmp(TestText,State->ExpectedText) == 0) + { + ++State->MatchCount; + } + } + } + else + { + ++State->MatchCount; + } } } @@ -80,16 +109,16 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, * Helper function to set up for event checking * This attaches the hook function to CFE_EVS_SendEvent */ -static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) +static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *ExpectedText) { memset(Evt, 0, sizeof(*Evt)); Evt->ExpectedEvent = ExpectedEvent; - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); + Evt->ExpectedText = ExpectedText; + UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); } - /* ********************************************************************************** ** TEST CASE FUNCTIONS @@ -183,7 +212,7 @@ void Test_SAMPLE_AppMain(void) */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); UT_SetDeferredRetcode(UT_KEY(CFE_SB_RcvMsg), 1, CFE_SB_PIPE_RD_ERR); - UT_CheckEvent_Setup(&EventTest, SAMPLE_PIPE_ERR_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_PIPE_ERR_EID, "SAMPLE APP: SB Pipe Read Error, App Will Exit"); /* * Invoke again @@ -249,7 +278,7 @@ void Test_SAMPLE_ProcessCommandPacket(void) union { CFE_SB_Msg_t Base; - CCSDS_CommandPacket_t Cmd; + CFE_SB_CmdHdr_t Cmd; SAMPLE_Noop_t Noop; SAMPLE_ResetCounters_t Reset; SAMPLE_Process_t Process; @@ -258,7 +287,7 @@ void Test_SAMPLE_ProcessCommandPacket(void) UT_CheckEvent_t EventTest; memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffff"); /* * The CFE_SB_GetMsgId() stub uses a data buffer to hold the @@ -302,7 +331,7 @@ void Test_SAMPLE_ProcessGroundCommand(void) union { CFE_SB_Msg_t Base; - CCSDS_CommandPacket_t Cmd; + CFE_SB_CmdHdr_t Cmd; SAMPLE_Noop_t Noop; SAMPLE_ResetCounters_t Reset; SAMPLE_Process_t Process; @@ -323,14 +352,14 @@ void Test_SAMPLE_ProcessGroundCommand(void) /* test dispatch of NOOP */ UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_NOOP_CC); UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Noop)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL); SAMPLE_ProcessGroundCommand(&TestMsg.Base); /* test dispatch of RESET */ UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_RESET_COUNTERS_CC); UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Reset)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, NULL); SAMPLE_ProcessGroundCommand(&TestMsg.Base); @@ -344,7 +373,7 @@ void Test_SAMPLE_ProcessGroundCommand(void) SAMPLE_ProcessGroundCommand(&TestMsg.Base); /* test an invalid CC */ - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID, "Invalid ground command code: CC = 1000"); UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, 1000); SAMPLE_ProcessGroundCommand(&TestMsg.Base); @@ -361,9 +390,9 @@ void Test_SAMPLE_ReportHousekeeping(void) { /* * Test Case For: - * void SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) + * void SAMPLE_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg ) */ - CCSDS_CommandPacket_t CmdMsg; + CFE_SB_CmdHdr_t CmdMsg; SAMPLE_HkTlm_t HkTelemetryMsg; memset(&CmdMsg, 0, sizeof(CmdMsg)); @@ -426,7 +455,7 @@ void Test_SAMPLE_NoopCmd(void) memset(&TestMsg, 0, sizeof(TestMsg)); /* test dispatch of NOOP */ - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL); UT_TEST_FUNCTION_RC(SAMPLE_Noop(&TestMsg), CFE_SUCCESS); @@ -449,7 +478,7 @@ void Test_SAMPLE_ResetCounters(void) memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, "SAMPLE: RESET command"); UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); @@ -517,7 +546,7 @@ void Test_SAMPLE_VerifyCmdLength(void) * test a match case */ UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID); + UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID, "Invalid Msg length: ID = 0xFFFF, CC = 0, Len = 18, Expected = 8"); SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg));