Skip to content

Commit

Permalink
Merge pull request nasa#37 from skliper/fix21-coverage_test
Browse files Browse the repository at this point in the history
Fix nasa#15 nasa#21 nasa#36, Code coverage improvements
  • Loading branch information
dzbaker committed Jun 22, 2022
2 parents 5ff1af4 + bb7e3a4 commit e484dc0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 45 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/unit-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 10 additions & 22 deletions fsw/src/sc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sc_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions unit-test/sc_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 11 additions & 15 deletions unit-test/sc_loads_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,32 +1182,28 @@ 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();

memset(&RtsTable, 0, sizeof(RtsTable));

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 */
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e484dc0

Please sign in to comment.