From c1938d5bbaab1997ca66eb708fa9d9a53bd8fea6 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Mon, 13 Jun 2022 14:41:24 -0600 Subject: [PATCH 1/3] Fix #15, Remove redundant condition in SC_UpdateNextTime for full coverage --- fsw/src/sc_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsw/src/sc_state.c b/fsw/src/sc_state.c index 28126f2..432c556 100644 --- a/fsw/src/sc_state.c +++ b/fsw/src/sc_state.c @@ -125,7 +125,7 @@ void SC_UpdateNextTime(void) ** This is determined by the RTS number in the RTP control block ** If it is zero, there is no RTS that needs to run */ - if (SC_OperData.RtsCtrlBlckAddr->RtsNumber > 0 && SC_OperData.RtsCtrlBlckAddr->RtsNumber <= SC_NUMBER_OF_RTS) + if (SC_OperData.RtsCtrlBlckAddr->RtsNumber > 0) { /* ** If the RTP needs to send commands, only send them if From 9fb24d509489fcfac4c9a0fcc5f295e53116e5ac Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Mon, 13 Jun 2022 14:53:04 -0600 Subject: [PATCH 2/3] Fix #36, Refactor redundant condition determining ATS A or B for reporting --- fsw/src/sc_cmds.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/fsw/src/sc_cmds.c b/fsw/src/sc_cmds.c index 02eb5f7..c655c77 100644 --- a/fsw/src/sc_cmds.c +++ b/fsw/src/sc_cmds.c @@ -170,11 +170,6 @@ void SC_ProcessAtpCmd(void) "ATS Command Distribution Failed, Cmd Number: %d, SB returned: 0x%08X", EntryPtr->Header.CmdNumber, (unsigned int)Result); - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSA) - TempAtsChar = 'A'; - else if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSB) - TempAtsChar = 'B'; - /* Mark this ATS for abortion */ AbortATS = true; } @@ -202,15 +197,7 @@ void SC_ProcessAtpCmd(void) SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_FAILED_CHECKSUM; if (SC_OperData.HkPacket.ContinueAtsOnFailureFlag == false) - { /* Stop ATS execution */ - /* - ** Set the temp ATS ID if it is valid - */ - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSA) - TempAtsChar = 'A'; - else if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSB) - TempAtsChar = 'B'; - + { /* Mark this ATS for abortion */ AbortATS = true; } @@ -239,14 +226,6 @@ void SC_ProcessAtpCmd(void) /* update the command status index table */ SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_SKIPPED; - /* - ** Set the temp ATS ID if it is valid - */ - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSA) - TempAtsChar = 'A'; - else if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSB) - TempAtsChar = 'B'; - /* Mark this ATS for abortion */ AbortATS = true; } /* end if the command number does not match */ @@ -277,6 +256,15 @@ void SC_ProcessAtpCmd(void) if (AbortATS == true) { + if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_ATSA) + { + TempAtsChar = 'A'; + } + else + { + TempAtsChar = 'B'; + } + CFE_EVS_SendEvent(SC_ATS_ABT_ERR_EID, CFE_EVS_EventType_ERROR, "ATS %c Aborted", TempAtsChar); /* Stop the ATS from executing */ From bb7e3a4620f46be706d657dceaff0d6013276975 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Mon, 13 Jun 2022 14:53:41 -0600 Subject: [PATCH 3/3] Fix #21, UT improvements for code coverage --- .github/workflows/unit-test-coverage.yml | 3 --- unit-test/sc_app_tests.c | 9 ++++---- unit-test/sc_loads_tests.c | 26 ++++++++++-------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unit-test-coverage.yml b/.github/workflows/unit-test-coverage.yml index d4aa2ac..d67e62b 100644 --- a/.github/workflows/unit-test-coverage.yml +++ b/.github/workflows/unit-test-coverage.yml @@ -8,6 +8,3 @@ jobs: unit-test-coverage: name: Run unit test and coverage uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main - with: - max-missed-branches: 6 - max-missed-lines: 1 diff --git a/unit-test/sc_app_tests.c b/unit-test/sc_app_tests.c index ccae770..3678c3e 100644 --- a/unit-test/sc_app_tests.c +++ b/unit-test/sc_app_tests.c @@ -117,15 +117,16 @@ void SC_AppMain_Test_Nominal(void) CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); size_t MsgSize = sizeof(SC_NoArgsCmd_t); - /* Same return value as default, but bypasses default hook function to simplify test */ - UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SUCCESS); - /* Called in a subfunction. Set here to prevent segmentation fault. */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - /* Set to make loop execute exactly once */ + /* Load return buffer to make loop execute twice */ UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); + + /* Return timeout first time through, will default to success on second */ + UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_TIME_OUT); /* Prevents error messages in call to SC_GetLoadTablePointers */ SC_APP_TEST_CFE_TBL_GetAddressHookCount = 0; diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index 65ac753..f136161 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -1182,13 +1182,12 @@ void SC_ParseRts_Test_CmdLengthEqualsBufferLength(void) void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize1 = SC_PACKET_MAX_SIZE; - size_t MsgSize2; - int BufEntrySize; + uint8 RtsIndex = 0; + uint32 RtsTable[SC_RTS_BUFF_SIZE32]; + CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; + size_t MsgSize1 = SC_PACKET_MAX_SIZE; + size_t MsgSize2; + int BufEntrySize; SC_InitTables(); @@ -1196,18 +1195,15 @@ void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void) SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); + /* Maximum size first command */ BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_RTS_HDR_NOPKT_WORDS; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); - /* Use the remaining buffer space to calculate the final message size */ - MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize) * SC_BYTES_IN_WORD); + /* All but last 32 bits for 2nd command */ + MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize - 1) * SC_BYTES_IN_WORD); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false); /* Execute the function being tested */ @@ -1240,11 +1236,11 @@ void SC_ParseRts_Test_CmdDoesNotFitBufferNotEmpty(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); + /* Maximum size first command */ BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_RTS_HDR_NOPKT_WORDS; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); - /* Use all but one 32-bit "word" of remaining space */ + /* All but last 32 bits for 2nd command */ MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize - 1) * SC_BYTES_IN_WORD); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false);