Skip to content

Commit

Permalink
Fix nasa#21, UT improvements for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jun 13, 2022
1 parent 9fb24d5 commit bb7e3a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 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
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 bb7e3a4

Please sign in to comment.