From bf9bc9281f65ab8c299432bce010bcdd39f2dd57 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 20 May 2020 14:35:48 -0400 Subject: [PATCH 1/6] Fix #66, Add extended context information to event hook Add string validation to the sample event hook as an example of how to use the context information supplied to the hook to perform other validation. --- .../coveragetest/coveragetest_sample_app.c | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 81cd5fc..45dfdfd 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_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 @@ -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 @@ -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); @@ -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, "SAMPLE: NOOP command Version 1.1.9.0"); 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)); From 3e46de86be9771d72a16338b8896ca1f2d445dcc Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 28 May 2020 16:11:02 -0400 Subject: [PATCH 2/6] Fix #68, remove references to CCSDS types Applications should only use types provided by CFE_SB. --- fsw/src/sample_app.c | 4 ++-- fsw/src/sample_app.h | 2 +- unit-test/coveragetest/coveragetest_sample_app.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) 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/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 81cd5fc..5578f67 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -249,7 +249,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; @@ -302,7 +302,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; @@ -361,9 +361,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)); From 3874dbf46bf9f83da0ce329fd2e8ea6c90296dc4 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 8 Jun 2020 13:45:58 -0400 Subject: [PATCH 3/6] HOTFIX: Use non-deprecated symbol. Should use CFE_MISSION_EVS_MAX_MESSAGE_LENGTH --- unit-test/coveragetest/coveragetest_sample_app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 9abf9c7..856e440 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -59,7 +59,7 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context, va_list va) { UT_CheckEvent_t *State = UserObj; - char TestText[CFE_EVS_MAX_MESSAGE_LENGTH]; + char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; uint16 EventId; const char *Spec; From 878a8a3d8ee2c8c90d25a73a56da5f1ddb9dd0bf Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" Date: Tue, 9 Jun 2020 23:20:22 -0400 Subject: [PATCH 4/6] Increase version to 1.1.9 and update ReadMe --- README.md | 4 ++++ fsw/src/sample_app_version.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30eefc8..8716e96 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ sample_app is an example for how to build and link an application in cFS. See al ## Version History +- 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_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 From d4a857b7cb2a544d85563c6d13d2c3dea0310318 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 10 Jun 2020 16:15:39 -0400 Subject: [PATCH 5/6] HOTFIX: Remove hardcoded version number check --- unit-test/coveragetest/coveragetest_sample_app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 856e440..e3da007 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -455,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, "SAMPLE: NOOP command Version 1.1.9.0"); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL); UT_TEST_FUNCTION_RC(SAMPLE_Noop(&TestMsg), CFE_SUCCESS); From 0e0c71c1d68eb76882ceca32a05b9227fd6fe268 Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Wed, 10 Jun 2020 19:23:53 -0400 Subject: [PATCH 6/6] HOTFIX: Fix ReadMe version changes for 1.1.10 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8716e96..5072efd 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ 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