Skip to content

Commit

Permalink
Merge pull request nasa#28 from skliper/fix22-ut_static_analysis
Browse files Browse the repository at this point in the history
Fix nasa#22 nasa#23, Resolve static analysis warnings
  • Loading branch information
astrogeco authored May 31, 2022
2 parents 82f2a06 + 7a408cb commit 4e55a38
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 60 deletions.
2 changes: 2 additions & 0 deletions fsw/src/sc_rtsrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ void SC_AutoStartRts(uint16 RtsNumber)
{
SC_RtsCmd_t CmdPkt; /* the command packet to start an RTS */

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

/* validate RTS ID */
if ((RtsNumber > 0) && (RtsNumber <= SC_NUMBER_OF_RTS))
{
Expand Down
12 changes: 0 additions & 12 deletions unit-test/sc_cmds_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ void SC_ProcessAtpCmd_Test_SwitchCmd(void)
SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[0][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set return value for CFE_TIME_Compare to make SC_CompareAbsTime return false, to satisfy first if-statement of
* SC_ProcessAtpCmd, and for all other calls to CFE_TIME_Compare called from subfunctions reached by this test */
UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), Ut_CFE_TIME_CompareHookAlessthanB, NULL);
Expand Down Expand Up @@ -159,8 +157,6 @@ void SC_ProcessAtpCmd_Test_NonSwitchCmd(void)
SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[0][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set return value for CFE_TIME_Compare to make SC_CompareAbsTime return false, to satisfy first if-statement of
* SC_ProcessAtpCmd, and for all other calls to CFE_TIME_Compare called from subfunctions reached by this test */
UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), Ut_CFE_TIME_CompareHookAlessthanB, NULL);
Expand Down Expand Up @@ -227,8 +223,6 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void)
SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[0][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set return value for CFE_TIME_Compare to make SC_CompareAbsTime return false, to satisfy first if-statement of
* SC_ProcessAtpCmd, and for all other calls to CFE_TIME_Compare called from subfunctions reached by this test */
UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), Ut_CFE_TIME_CompareHookAlessthanB, NULL);
Expand Down Expand Up @@ -306,8 +300,6 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void)
SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[0][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set to return true in order to satisfy the if-statement from which the function is called */
ChecksumValid = true;
UT_SetDataBuffer(UT_KEY(CFE_MSG_ValidateChecksum), &ChecksumValid, sizeof(ChecksumValid), false);
Expand Down Expand Up @@ -395,8 +387,6 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void)
SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[1][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set to return true in order to satisfy the if-statement from which the function is called */
ChecksumValid = true;
UT_SetDataBuffer(UT_KEY(CFE_MSG_ValidateChecksum), &ChecksumValid, sizeof(ChecksumValid), false);
Expand Down Expand Up @@ -1067,8 +1057,6 @@ void SC_ProcessAtpCmd_Test_CmdMid(void)
SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_LOADED;
SC_AppData.AtsCmdIndexBuffer[0][0] = 0;

SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

/* Set return value for CFE_TIME_Compare to make SC_CompareAbsTime return false, to satisfy first if-statement of
* SC_ProcessAtpCmd, and for all other calls to CFE_TIME_Compare called from subfunctions reached by this test */
UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), Ut_CFE_TIME_CompareHookAlessthanB, NULL);
Expand Down
12 changes: 12 additions & 0 deletions unit-test/sc_loads_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void)
int MaxBufEntries;
int i, j;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down Expand Up @@ -175,6 +177,8 @@ void SC_LoadAts_Test_CmdLengthInvalid(void)
uint32 AtsTable[SC_ATS_BUFF_SIZE32];
uint8 AtsIndex = 0;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down Expand Up @@ -218,6 +222,8 @@ void SC_LoadAts_Test_CmdLengthZero(void)
uint32 AtsTable[SC_ATS_BUFF_SIZE32];
uint8 AtsIndex = 0;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down Expand Up @@ -261,6 +267,8 @@ void SC_LoadAts_Test_CmdNumberInvalid(void)
uint32 AtsTable[SC_ATS_BUFF_SIZE32];
uint8 AtsIndex = 0;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down Expand Up @@ -304,6 +312,8 @@ void SC_LoadAts_Test_EndOfLoadReached(void)
uint32 AtsTable[SC_ATS_BUFF_SIZE32];
uint8 AtsIndex = 0;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down Expand Up @@ -351,6 +361,8 @@ void SC_LoadAts_Test_AtsBufferTooSmall(void)
int MaxBufEntries;
int i, j;

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

SC_InitTables();

SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0];
Expand Down
54 changes: 7 additions & 47 deletions unit-test/sc_state_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,54 +358,15 @@ void SC_GetNextRtsCommand_Test_GetNextCommand(void)

void SC_GetNextRtsCommand_Test_RtsNumberZero(void)
{
SC_RtsEntryHeader_t *Entry;
uint32 RtsTable[SC_RTS_BUFF_SIZE32];
size_t MsgSize;

SC_InitTables();

memset(&SC_ATSRQ_TEST_GlobalAtsInfoTable, 0, sizeof(SC_STATE_TEST_GlobalRtsCtrlBlck));
memset(&SC_ATSRQ_TEST_GlobalAtsCtrlBlck, 0, sizeof(SC_ATSRQ_TEST_GlobalAtsCtrlBlck));

memset(&SC_STATE_TEST_GlobalRtsInfoTbl, 0, sizeof(SC_STATE_TEST_GlobalRtsInfoTbl));
/* Sets SC_OperData.RtsCtrlBlckAddr->RtsNumber to zero */
memset(&SC_STATE_TEST_GlobalRtsCtrlBlck, 0, sizeof(SC_STATE_TEST_GlobalRtsCtrlBlck));

SC_OperData.AtsInfoTblAddr = &SC_ATSRQ_TEST_GlobalAtsInfoTable[0];
SC_OperData.AtsCtrlBlckAddr = &SC_ATSRQ_TEST_GlobalAtsCtrlBlck;

SC_OperData.RtsInfoTblAddr = &SC_STATE_TEST_GlobalRtsInfoTbl[0];
SC_OperData.RtsCtrlBlckAddr = &SC_STATE_TEST_GlobalRtsCtrlBlck;

SC_OperData.RtsTblAddr[0] = &RtsTable[0];

SC_AppData.NextCmdTime[SC_RTP] = 0;
SC_AppData.CurrentTime = 1;
SC_AppData.NextProcNumber = SC_RTP;
SC_OperData.RtsCtrlBlckAddr->RtsNumber = 0;
SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_EXECUTING;
SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0];

CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), sizeof(SC_NoArgsCmd_t));

/* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */
MsgSize = SC_PACKET_MIN_SIZE;

UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);

/* Set so checksum will pass in SC_ProcessRtpCommand */
UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true);

/* Execute the function being tested */
SC_GetNextRtsCommand();

/* Verify results */
call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0",
call_count_CFE_EVS_SendEvent);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

} /* end SC_GetNextRtsCommand_Test_RtsNumberZero */

Expand Down Expand Up @@ -484,12 +445,11 @@ void SC_GetNextRtsCommand_Test_RtsNumberOverMax(void)

SC_OperData.RtsTblAddr[SC_NUMBER_OF_RTS - 1] = &RtsTable[0];

SC_AppData.NextCmdTime[SC_RTP] = 0;
SC_AppData.CurrentTime = 1;
SC_AppData.NextProcNumber = SC_RTP;
SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS + 1;
SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_EXECUTING;
SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;
SC_AppData.NextCmdTime[SC_RTP] = 0;
SC_AppData.CurrentTime = 1;
SC_AppData.NextProcNumber = SC_RTP;
SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS + 1;
SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1;

Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_NUMBER_OF_RTS - 1][0];

Expand Down
2 changes: 1 addition & 1 deletion unit-test/utilities/sc_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void UT_Handler_CFE_EVS_SendEvent(void *UserObj, UT_EntryKey_t FuncKey, const UT
void UT_Handler_CFE_ES_WriteToSysLog(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, va_list va)
{
strncpy(context_CFE_ES_WriteToSysLog.Spec, UT_Hook_GetArgValueByName(Context, "SpecStringPtr", const char *),
CFE_MISSION_EVS_MAX_MESSAGE_LENGTH);
CFE_MISSION_EVS_MAX_MESSAGE_LENGTH - 1);
context_CFE_ES_WriteToSysLog.Spec[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH - 1] = '\0';
}

Expand Down

0 comments on commit 4e55a38

Please sign in to comment.