Skip to content

Commit bb7e3a4

Browse files
committed
Fix nasa#21, UT improvements for code coverage
1 parent 9fb24d5 commit bb7e3a4

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

.github/workflows/unit-test-coverage.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@ jobs:
88
unit-test-coverage:
99
name: Run unit test and coverage
1010
uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main
11-
with:
12-
max-missed-branches: 6
13-
max-missed-lines: 1

unit-test/sc_app_tests.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@ void SC_AppMain_Test_Nominal(void)
117117
CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID);
118118
size_t MsgSize = sizeof(SC_NoArgsCmd_t);
119119

120-
/* Same return value as default, but bypasses default hook function to simplify test */
121-
UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SUCCESS);
122-
123120
/* Called in a subfunction. Set here to prevent segmentation fault. */
124121
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
125122
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);
126123

127-
/* Set to make loop execute exactly once */
124+
/* Load return buffer to make loop execute twice */
128125
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
126+
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
127+
128+
/* Return timeout first time through, will default to success on second */
129+
UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_TIME_OUT);
129130

130131
/* Prevents error messages in call to SC_GetLoadTablePointers */
131132
SC_APP_TEST_CFE_TBL_GetAddressHookCount = 0;

unit-test/sc_loads_tests.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,32 +1182,28 @@ void SC_ParseRts_Test_CmdLengthEqualsBufferLength(void)
11821182

11831183
void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void)
11841184
{
1185-
SC_RtsEntryHeader_t *Entry;
1186-
uint8 RtsIndex = 0;
1187-
uint32 RtsTable[SC_RTS_BUFF_SIZE32];
1188-
CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1;
1189-
size_t MsgSize1 = SC_PACKET_MAX_SIZE;
1190-
size_t MsgSize2;
1191-
int BufEntrySize;
1185+
uint8 RtsIndex = 0;
1186+
uint32 RtsTable[SC_RTS_BUFF_SIZE32];
1187+
CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1;
1188+
size_t MsgSize1 = SC_PACKET_MAX_SIZE;
1189+
size_t MsgSize2;
1190+
int BufEntrySize;
11921191

11931192
SC_InitTables();
11941193

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

11971196
SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0];
11981197

1199-
Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0];
1200-
Entry->TimeTag = 1;
1201-
12021198
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
12031199
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
12041200

1201+
/* Maximum size first command */
12051202
BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_RTS_HDR_NOPKT_WORDS;
1206-
12071203
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false);
12081204

1209-
/* Use the remaining buffer space to calculate the final message size */
1210-
MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize) * SC_BYTES_IN_WORD);
1205+
/* All but last 32 bits for 2nd command */
1206+
MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize - 1) * SC_BYTES_IN_WORD);
12111207
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false);
12121208

12131209
/* Execute the function being tested */
@@ -1240,11 +1236,11 @@ void SC_ParseRts_Test_CmdDoesNotFitBufferNotEmpty(void)
12401236
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
12411237
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
12421238

1239+
/* Maximum size first command */
12431240
BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_RTS_HDR_NOPKT_WORDS;
1244-
12451241
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false);
12461242

1247-
/* Use all but one 32-bit "word" of remaining space */
1243+
/* All but last 32 bits for 2nd command */
12481244
MsgSize2 = ((SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_NOPKT_WORDS - BufEntrySize - 1) * SC_BYTES_IN_WORD);
12491245
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false);
12501246

0 commit comments

Comments
 (0)