From d5833d0e083f8235d35e132e321ec74775ed9984 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 11 Sep 2020 09:24:06 -0400 Subject: [PATCH 1/4] Fix #87, Unit test MID string format now 32bit --- unit-test/coveragetest/coveragetest_sample_app.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index d3dc1c9..a2bd335 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -272,7 +272,7 @@ void Test_SAMPLE_ProcessCommandPacket(void) UT_CheckEvent_t EventTest; memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffff"); + UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffffffff"); /* * The CFE_SB_GetMsgId() stub uses a data buffer to hold the @@ -497,7 +497,7 @@ void Test_SAMPLE_VerifyCmdLength(void) */ UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg)); UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID, - "Invalid Msg length: ID = 0xFFFF, CC = 0, Len = 18, Expected = 8"); + "Invalid Msg length: ID = 0xFFFFFFFF, CC = 0, Len = 18, Expected = 8"); SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); From 8f5384a2df5d189732a47052af29be44a3cf54ff Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 11 Sep 2020 12:58:36 -0400 Subject: [PATCH 2/4] Fix #95, Install unit test to target directory --- unit-test/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 130fd8f..4890906 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -67,7 +67,9 @@ foreach(SRCFILE sample_app.c) # Add it to the set of tests to run as part of "make test" add_test(${TESTNAME} ${TESTNAME}-testrunner) - install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) + foreach(TGT ${INSTALL_TARGET_LIST}) + install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) + endforeach() endforeach() From 112945859959c1103c4ae89247410c43b43429df Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 17 Sep 2020 13:10:20 -0400 Subject: [PATCH 3/4] Fix #97, check event spec string The fully-rendered strings are not entirely consistent, affected by many external factors outside the control of the test cases. There was even a warning in the comment against doing this, but it was included nonetheless as an example of how it can be done. This now keeps the original example but keeps it in the comment only, and converts the actual test to follow the recommended practice of only testing the spec/format string, not the fully-rendered string. This should be much more stable going forward, and should work with both CCSDS v1 and v2 configs. --- .../coveragetest/coveragetest_sample_app.c | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index a2bd335..5671e5f 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -48,7 +48,7 @@ typedef struct { uint16 ExpectedEvent; uint32 MatchCount; - const char *ExpectedText; + const char *ExpectedFormat; } UT_CheckEvent_t; /* @@ -58,7 +58,6 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou va_list va) { UT_CheckEvent_t *State = UserObj; - char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; uint16 EventId; const char * Spec; @@ -71,24 +70,34 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16); if (EventId == State->ExpectedEvent) { - /* - * 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) + if (State->ExpectedFormat != NULL) { Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *); if (Spec != NULL) { - vsnprintf(TestText, sizeof(TestText), Spec, va); - if (strcmp(TestText, State->ExpectedText) == 0) + /* + * Example of how to validate the full argument set. + * ------------------------------------------------ + * + * If really desired one can call something like: + * + * char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; + * vsnprintf(TestText, sizeof(TestText), Spec, va); + * + * And then compare the output (TestText) to the expected fully-rendered string. + * + * 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 type of check has been demonstrated to make tests very fragile, + * because it is influenced by many factors outside the control of the + * test case. + * + * __This derived string is not an actual output of the unit under test__ + */ + if (strcmp(Spec, State->ExpectedFormat) == 0) { ++State->MatchCount; } @@ -108,11 +117,11 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou * 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, const char *ExpectedText) +static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *ExpectedFormat) { memset(Evt, 0, sizeof(*Evt)); Evt->ExpectedEvent = ExpectedEvent; - Evt->ExpectedText = ExpectedText; + Evt->ExpectedFormat = ExpectedFormat; UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); } @@ -272,7 +281,7 @@ void Test_SAMPLE_ProcessCommandPacket(void) UT_CheckEvent_t EventTest; memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffffffff"); + UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0x%x"); /* * The CFE_SB_GetMsgId() stub uses a data buffer to hold the @@ -351,7 +360,7 @@ void Test_SAMPLE_ProcessGroundCommand(void) SAMPLE_ProcessGroundCommand(&TestMsg.Base); /* test an invalid CC */ - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID, "Invalid ground command code: CC = 1000"); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID, "Invalid ground command code: CC = %d"); UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, 1000); SAMPLE_ProcessGroundCommand(&TestMsg.Base); @@ -497,7 +506,7 @@ void Test_SAMPLE_VerifyCmdLength(void) */ UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg)); UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID, - "Invalid Msg length: ID = 0xFFFFFFFF, CC = 0, Len = 18, Expected = 8"); + "Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d"); SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); From 80e044bae8ab7dccfe4a147702893d07ebd902d1 Mon Sep 17 00:00:00 2001 From: Yasir Khan Date: Mon, 21 Sep 2020 15:49:27 -0400 Subject: [PATCH 4/4] Increase version to 1.2.0-rc1+dev13, update readme. --- README.md | 7 +++++++ fsw/src/sample_app_version.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ccf0b5..0d05c75 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,13 @@ sample_app is an example for how to build and link an application in cFS. See al ## Version History +### Development Build: 1.2.0-rc1+dev13 + +- Unit test MID string format now 32bit +- Installs unit test to target directory +- Checks only format string in UT event test +- See + ### Development Build: 1.2.0-rc1+dev5 - Applies standard coding style. diff --git a/fsw/src/sample_app_version.h b/fsw/src/sample_app_version.h index 3ec042f..14f493e 100644 --- a/fsw/src/sample_app_version.h +++ b/fsw/src/sample_app_version.h @@ -32,7 +32,7 @@ /* Development Build Macro Definitions */ -#define SAMPLE_APP_BUILD_NUMBER 5 /*!< Development Build: Number of commits since baseline */ +#define SAMPLE_APP_BUILD_NUMBER 13 /*!< Development Build: Number of commits since baseline */ #define SAMPLE_APP_BUILD_BASELINE \ "v1.2.0-rc1" /*!< Development Build: git tag that is the base for the current development */