diff --git a/fsw/src/sc_rtsrq.c b/fsw/src/sc_rtsrq.c index 6d44c90..57efc88 100644 --- a/fsw/src/sc_rtsrq.c +++ b/fsw/src/sc_rtsrq.c @@ -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)) { diff --git a/unit-test/sc_cmds_tests.c b/unit-test/sc_cmds_tests.c index 5f5933e..2adfaf5 100644 --- a/unit-test/sc_cmds_tests.c +++ b/unit-test/sc_cmds_tests.c @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index 732ef6e..995ff61 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; @@ -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]; diff --git a/unit-test/sc_state_tests.c b/unit-test/sc_state_tests.c index e1edbf8..634fff8 100644 --- a/unit-test/sc_state_tests.c +++ b/unit-test/sc_state_tests.c @@ -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 */ @@ -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]; diff --git a/unit-test/utilities/sc_test_utils.c b/unit-test/utilities/sc_test_utils.c index 4db160e..8328f62 100644 --- a/unit-test/utilities/sc_test_utils.c +++ b/unit-test/utilities/sc_test_utils.c @@ -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'; }