From a73c783695190f3f3d0b4fa8956a99436d90b2f9 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 14 Sep 2023 16:25:48 -0400 Subject: [PATCH] Fix #102, clean up sc_loads_test Significant buffer management issues existed in many/all of these test cases and was causing stack corruption. Rewriting the test cases to better follow current recommended practices, and reduce repetition. --- unit-test/sc_loads_tests.c | 2151 ++++++++++-------------------------- 1 file changed, 554 insertions(+), 1597 deletions(-) diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index 33016d0..47882cc 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -40,520 +40,437 @@ #include "utassert.h" #include "utstubs.h" -/* sc_loads_tests globals */ -uint8 call_count_CFE_EVS_SendEvent; +#define UT_SC_NOMINAL_CMD_SIZE (SC_PACKET_MAX_SIZE / 2) -uint32 SC_APP_TEST_GlobalAtsCmdStatusTbl[SC_NUMBER_OF_ATS * SC_MAX_ATS_CMDS]; +uint32 MyAtsDataTable1[SC_ATS_BUFF_SIZE32 + 4]; +uint32 MyRtsDataTable1[SC_RTS_BUFF_SIZE32 + 4]; +uint32 MyAppendTable1[SC_APPEND_BUFF_SIZE32 + 4]; +uint32 MyAtsCmdStatusTbl[SC_MAX_ATS_CMDS + 4]; -SC_AtpControlBlock_t SC_APP_TEST_GlobalAtsCtrlBlck; +SC_AtsInfoTable_t MyAtsInfoTbl[SC_NUMBER_OF_ATS]; +SC_AtpControlBlock_t MyAtpControlBlock; /* * Function Definitions */ -uint8 SC_LOADS_TEST_GetTotalMsgLengthHook_RunCount; -int32 SC_LOADS_TEST_CFE_MSG_GetSizeHook1(void *UserObj, int32 StubRetcode, uint32 CallCount, - const UT_StubContext_t *Context) +void UT_SC_CmdTableSizeHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - SC_LOADS_TEST_GetTotalMsgLengthHook_RunCount += 1; + const CFE_MSG_Message_t *MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", const CFE_MSG_Message_t *); + CFE_MSG_Size_t * Size = UT_Hook_GetArgValueByName(Context, "Size", CFE_MSG_Size_t *); + uint32 * StoredSize = (uint32 *)(void *)MsgPtr; - if (SC_LOADS_TEST_GetTotalMsgLengthHook_RunCount == 1) - SC_OperData.AtsCmdStatusTblAddr[0][1] = SC_LOADED; - - return CFE_SUCCESS; + *Size = *StoredSize; } -CFE_TIME_Compare_t UT_SC_Insert_CompareHookAgreaterthanB(void *UserObj, int32 StubRetcode, uint32 CallCount, - const UT_StubContext_t *Context) +void UT_SC_CmdTableMidHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { - return CFE_TIME_A_GT_B; + CFE_SB_MsgId_t *MsgId = UT_Hook_GetArgValueByName(Context, "MsgId", CFE_SB_MsgId_t *); + CFE_SB_MsgId_t *TestCaseMsgId = UserObj; + + *MsgId = *TestCaseMsgId; } -void SC_LoadAts_Test_Nominal(void) +void *UT_SC_ResetAtsTable(uint8 AtsIndex) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - size_t MsgSize = sizeof(SC_NoArgsCmd_t); - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; + memset(&MyAtsInfoTbl[AtsIndex], 0, sizeof(SC_AtsInfoTable_t)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - memset(&AtsTable, 0, sizeof(AtsTable)); + memset(MyAtsDataTable1, 0, sizeof(MyAtsDataTable1)); + memset(MyAtsCmdStatusTbl, 0, sizeof(MyAtsCmdStatusTbl)); - SC_InitTables(); + SC_OperData.AtsTblAddr[AtsIndex] = MyAtsDataTable1; + SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = MyAtsCmdStatusTbl; + SC_OperData.AtsInfoTblAddr = MyAtsInfoTbl; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + UT_SetHandlerFunction(UT_KEY(CFE_MSG_GetSize), UT_SC_CmdTableSizeHandler, NULL); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + return MyAtsDataTable1; +} - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; +void *UT_SC_ResetRtsTable(uint8 RtsIndex, CFE_SB_MsgId_t MsgId) +{ + static CFE_SB_MsgId_t TestCaseMsgId; - /* Set to satisfy the conditions of if-statement below comment "if the length of the command is valid", along - * with the if-statement immediately after */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + TestCaseMsgId = MsgId; + memset(MyRtsDataTable1, 0, sizeof(MyRtsDataTable1)); - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); + SC_OperData.RtsTblAddr[RtsIndex] = MyRtsDataTable1; - /* Verify results */ - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], 0); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + UT_SetHandlerFunction(UT_KEY(CFE_MSG_GetSize), UT_SC_CmdTableSizeHandler, NULL); + UT_SetHandlerFunction(UT_KEY(CFE_MSG_GetMsgId), UT_SC_CmdTableMidHandler, &TestCaseMsgId); - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + return MyRtsDataTable1; } -void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) +void *UT_SC_ResetAppendTable(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; - size_t MsgSize; - int BufEntrySize; - int MaxBufEntries; - int i; - int j; + memset(MyAppendTable1, 0, sizeof(MyAppendTable1)); + memset(&MyAtpControlBlock, 0, sizeof(MyAtpControlBlock)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); + SC_OperData.AppendTblAddr = MyAppendTable1; + SC_OperData.AtsCtrlBlckAddr = &MyAtpControlBlock; - SC_InitTables(); + return MyAppendTable1; +} - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; +void UT_SC_ModifyCmdSize(SC_AtsEntryHeader_t *Entry, size_t MsgSize) +{ + Entry->Pad = MsgSize; +} - /* Causes CFE_MSG_GetSize to satisfy the conditions of if-statement below comment "if the length of the command is - * valid", but NOT the if-statement immediately after */ - MsgSize = SC_PACKET_MAX_SIZE; - BufEntrySize = (MsgSize + SC_ROUND_UP_BYTES + SC_ATS_HEADER_SIZE) / SC_BYTES_IN_WORD; - MaxBufEntries = SC_ATS_BUFF_SIZE32 / BufEntrySize + 1; +void UT_SC_ModifyCmdStatus(SC_AtsEntryHeader_t *Entry, uint32 CmdStatus) +{ + /* Just need to update the stub to return the modified value here */ + uint16 Offset = SC_ATS_CMD_NUM_TO_INDEX(Entry->CmdNumber); - for (i = 0, j = 0; i < MaxBufEntries; i++, j += BufEntrySize) + if (Offset < SC_MAX_ATS_CMDS) { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + MyAtsCmdStatusTbl[Offset] = CmdStatus; } - - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); - - /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); - - 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); } -void SC_LoadAts_Test_CmdLengthInvalid(void) +void UT_SC_AdvanceTailPtr(void **TailPtr, size_t HdrSize, size_t MsgSize) { - size_t MsgSize; - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; - - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); + uint32 *U32Ptr = (uint32 *)(*TailPtr); - SC_InitTables(); + /* Advance past the header, in words */ + U32Ptr += HdrSize / sizeof(uint32); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; - - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + /* Stash the size here */ + if (MsgSize < sizeof(uint32)) + { + UtAssert_Failed("Cannot store a message with size = %lu", (unsigned long)MsgSize); + } + else + { + *U32Ptr = MsgSize; + } - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; + /* Advance past the command content, in words */ + U32Ptr += (MsgSize + SC_ROUND_UP_BYTES) / sizeof(uint32); - /* Set to make the if-statement below comment "if the length of the command is valid" fail */ - MsgSize = SC_PACKET_MAX_SIZE + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + *TailPtr = U32Ptr; +} - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); +SC_AtsEntryHeader_t *UT_SC_AppendSingleAtsEntry(void **TailPtr, uint16 CmdNumber, size_t MsgSize) +{ + SC_AtsEntryHeader_t *Entry = (SC_AtsEntryHeader_t *)(*TailPtr); - /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); + UT_SC_AdvanceTailPtr(TailPtr, SC_ATS_HEADER_SIZE, MsgSize); - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + Entry->CmdNumber = CmdNumber; - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + return Entry; } -void SC_LoadAts_Test_CmdLengthZero(void) +SC_RtsEntryHeader_t *UT_SC_AppendSingleRtsEntry(void **TailPtr, SC_RelTimeTag_t TimeTag, size_t MsgSize) { - size_t MsgSize; - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; - - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); + SC_RtsEntryHeader_t *Entry = (SC_RtsEntryHeader_t *)(*TailPtr); - SC_InitTables(); + UT_SC_AdvanceTailPtr(TailPtr, SC_RTS_HEADER_SIZE, MsgSize); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + Entry->TimeTag = TimeTag; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + return Entry; +} - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; +SC_AtsEntryHeader_t *UT_SC_SetupSingleAtsEntry(uint8 AtsIndex, uint16 CmdNumber, size_t MsgSize) +{ + void *TailPtr; - /* Set to make the if-statement below comment "if the length of the command is valid" fail */ - MsgSize = 0; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + TailPtr = UT_SC_ResetAtsTable(AtsIndex); - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); + return UT_SC_AppendSingleAtsEntry(&TailPtr, CmdNumber, MsgSize); +} - /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); +SC_RtsEntryHeader_t *UT_SC_SetupSingleRtsEntry(uint8 RtsIndex, CFE_SB_MsgId_t MsgId, SC_RelTimeTag_t TimeTag, + size_t MsgSize) +{ + void *TailPtr; - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + TailPtr = UT_SC_ResetRtsTable(RtsIndex, MsgId); - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + return UT_SC_AppendSingleRtsEntry(&TailPtr, TimeTag, MsgSize); } -void SC_LoadAts_Test_CmdNumberInvalid(void) +uint32 UT_SC_GetEntryWordCount(size_t HdrSize, size_t MsgSize) { - size_t MsgSize; - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; + return (MsgSize + HdrSize + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD; +} - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); +void *UT_SC_SetupFullTable(void **TailPtr, size_t HdrSize, size_t MsgSize, size_t MaxLimitWords, + size_t TargetEndingWord, void (*EntryInit_Callback)(void *, size_t, size_t)) +{ + uint8 *HeadPtr; + void * CurrPtr; + size_t BufEntryWords; + size_t LastUsableWord; + size_t Idx; + size_t WordsUsed; - SC_InitTables(); + HeadPtr = *TailPtr; + CurrPtr = NULL; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + /* Causes CFE_MSG_GetSize to satisfy the conditions of if-statement below comment "if the length of the command is + * valid", but NOT the if-statement immediately after */ + BufEntryWords = UT_SC_GetEntryWordCount(HdrSize, MsgSize); + LastUsableWord = MaxLimitWords; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = SC_MAX_ATS_CMDS * 2; + if (TargetEndingWord != 0 && TargetEndingWord < LastUsableWord) + { + LastUsableWord = TargetEndingWord; + } - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; + if (LastUsableWord > BufEntryWords) + { + LastUsableWord -= BufEntryWords; + } + else + { + LastUsableWord = 0; + } - /* Set to make the if-statement below comment "if the length of the command is valid" fail */ - MsgSize = SC_PACKET_MAX_SIZE + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + /* Fill the buffer up to the last "complete" entry */ + for (Idx = 0; Idx < SC_MAX_ATS_CMDS; ++Idx) + { + WordsUsed = ((uint8 *)(*TailPtr) - HeadPtr) / sizeof(uint32); + if (WordsUsed > LastUsableWord) + { + break; + } - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); + if ((WordsUsed + BufEntryWords) > LastUsableWord && TargetEndingWord != 0) + { + /* This will be the last entry. Adjust the size to hit the target. */ + BufEntryWords = TargetEndingWord - WordsUsed; + MsgSize = (BufEntryWords * sizeof(uint32)) - HdrSize; + } - /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); + CurrPtr = *TailPtr; + UT_SC_AdvanceTailPtr(TailPtr, HdrSize, MsgSize); - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + EntryInit_Callback(CurrPtr, Idx, MsgSize); + // EntryInit(CurrPtr, SC_ATS_CMD_INDEX_TO_NUM(Idx), MsgSize); + } - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + /* Capture the last entry that was complete - + * test case may want to change it to exercise end-of-buffer handling */ + return CurrPtr; } -void SC_LoadAts_Test_EndOfLoadReached(void) +void UT_SC_AtsEntryInit(void *EntryPtr, size_t Idx, size_t MsgSize) { - size_t MsgSize; - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - 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]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + SC_AtsEntryHeader_t *Entry = EntryPtr; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 0; - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; - - /* Set to make the if-statement below comment "if the length of the command is valid" fail */ - MsgSize = SC_PACKET_MAX_SIZE + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + Entry->CmdNumber = SC_ATS_CMD_INDEX_TO_NUM(Idx); +} - /* Execute the function being tested */ - SC_LoadAts(AtsIndex); +SC_AtsEntryHeader_t *UT_SC_SetupAtsTable(uint8 AtsIndex, size_t MsgSize, size_t TargetEndingWord, void **TailPtrOut) +{ + void * TailPtr; + SC_AtsEntryHeader_t *FinalEntry; - /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); + TailPtr = UT_SC_ResetAtsTable(AtsIndex); + FinalEntry = UT_SC_SetupFullTable(&TailPtr, SC_ATS_HEADER_SIZE, MsgSize, SC_ATS_BUFF_SIZE32, TargetEndingWord, + UT_SC_AtsEntryInit); - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + /* Capture a pointer to the _end_ of the filled data - + * the test case might need to write additional data here */ + if (TailPtrOut != NULL) + { + *TailPtrOut = TailPtr; + } - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + /* Capture the last ATS entry that was complete - + * test case may want to change it to exercise end-of-buffer handling */ + return FinalEntry; } -void SC_LoadAts_Test_AtsBufferTooSmall(void) +void UT_SC_RtsEntryInit(void *EntryPtr, size_t Idx, size_t MsgSize) { - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; - size_t MsgSize1; - size_t MsgSize2; - int BufEntrySize; - int MaxBufEntries; - int i; - int j; + SC_RtsEntryHeader_t *Entry = EntryPtr; - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - - SC_InitTables(); + Entry->TimeTag = 1; +} - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; +SC_RtsEntryHeader_t *UT_SC_SetupRtsTable(uint8 RtsIndex, CFE_SB_MsgId_t MsgId, size_t MsgSize, size_t TargetEndingWord, + void **TailPtrOut) +{ + void * TailPtr; + SC_RtsEntryHeader_t *FinalEntry; - /* Set to reach block of code starting with comment "even the smallest command will not fit in the buffer" */ - MsgSize1 = SC_PACKET_MAX_SIZE; - BufEntrySize = ((MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_NOPKT_WORDS; - MaxBufEntries = SC_ATS_BUFF_SIZE32 / BufEntrySize; + TailPtr = UT_SC_ResetRtsTable(RtsIndex, MsgId); + FinalEntry = UT_SC_SetupFullTable(&TailPtr, SC_RTS_HEADER_SIZE, MsgSize, SC_RTS_BUFF_SIZE32, TargetEndingWord, + UT_SC_RtsEntryInit); - for (i = 0, j = 0; i < MaxBufEntries; i++, j += BufEntrySize) + /* Capture a pointer to the _end_ of the filled data - + * the test case might need to write additional data here */ + if (TailPtrOut != NULL) { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); + *TailPtrOut = TailPtr; } - /* Next entry should not leave enough buffer space for an ATS command header */ - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i++ + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; - - /* Use the remaining buffer space to calculate the final message size */ - MsgSize2 = (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS - j) * SC_BYTES_IN_WORD; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false); + /* Capture the last Rts entry that was complete - + * test case may want to change it to exercise end-of-buffer handling */ + return FinalEntry; +} - /* Set up final entry that will create error condition */ - j += ((MsgSize2 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_NOPKT_WORDS; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); +void SC_LoadAts_Test_Nominal(void) +{ + uint8 AtsIndex = 0; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, sizeof(SC_NoArgsCmd_t)); /* Execute the function being tested */ SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR, - "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == SC_ERROR"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_EMPTY"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 0"); + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], 0); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} + +void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) +{ + uint8 AtsIndex = 0; + + /* Set up -- Modify the final entry so it would go off the end of the table */ + UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32 + 1, NULL); - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + /* Execute the function being tested */ + SC_LoadAts(AtsIndex); - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_LoadAts_Test_AtsEntryOverflow(void) +void SC_LoadAts_Test_CmdLengthInvalid(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - uint8 AtsIndex = 0; - size_t MsgSize1; - size_t MsgSize2; - int BufEntrySize; - int MaxBufEntries; - int i; - int j; + uint8 AtsIndex = 0; - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - memset(&AtsTable, 0, sizeof(AtsTable)); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE + 1); - SC_InitTables(); + /* Execute the function being tested */ + SC_LoadAts(AtsIndex); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} - MsgSize1 = SC_PACKET_MAX_SIZE; - BufEntrySize = ((MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_NOPKT_WORDS; - MaxBufEntries = SC_ATS_BUFF_SIZE32 / BufEntrySize; +void SC_LoadAts_Test_CmdLengthZero(void) +{ + uint8 AtsIndex = 0; - for (i = 0, j = 0; i < MaxBufEntries; i++, j += BufEntrySize) - { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); - } + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MIN_SIZE - 1); - /* Next entry should not leave enough buffer space for an ATS command header */ - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i++ + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; + /* Execute the function being tested */ + SC_LoadAts(AtsIndex); - /* Use the remaining buffer space to calculate the final message size */ - MsgSize2 = (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS + 4 - j) * SC_BYTES_IN_WORD; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false); + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} - /* Set up final entry that will create condition */ - j += ((MsgSize2 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_WORDS; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); +void SC_LoadAts_Test_CmdNumberInvalid(void) +{ + uint8 AtsIndex = 0; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; + UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS * 2, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ SC_LoadAts(AtsIndex); - /* 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_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_LoadAts_Test_LoadExactlyBufferLength(void) +void SC_LoadAts_Test_AtsBufferTooSmall(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; + SC_AtsEntryHeader_t *LastValidEntry; + void * TailPtr; + SC_AtsEntryHeader_t *InvalidEntry; uint8 AtsIndex = 0; - size_t MsgSize1; - size_t MsgSize2; - int BufEntrySize; - int MaxBufEntries; - int i; - int j; - SC_InitTables(); + /* Set up -- Modify the final entry so it would go off the end of the table */ + LastValidEntry = + UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_NOPKT_WORDS, &TailPtr); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + InvalidEntry = TailPtr; + /* + * Set up final (invalid) entry that will create error condition - + * This is an ATS header at the very end of the ATS buffer, where there is no room + * for a cmd message to follow it, but it has a nonzero command number + */ + InvalidEntry->CmdNumber = LastValidEntry->CmdNumber + 1; - /* Set to reach block of code starting with comment "we encountered a load exactly as long as the buffer" */ - MsgSize1 = SC_PACKET_MAX_SIZE; - BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES + SC_ATS_HEADER_SIZE) / SC_BYTES_IN_WORD; - MaxBufEntries = SC_ATS_BUFF_SIZE32 / BufEntrySize; + /* Execute the function being tested */ + SC_LoadAts(AtsIndex); - for (i = 0, j = 0; i < MaxBufEntries; i++, j += BufEntrySize) - { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); - } + /* Verify results */ + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} - /* Next entry should not leave enough buffer space for an ATS command header */ - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][j]; - Entry->CmdNumber = i++ + 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][j] = SC_EMPTY; +void SC_LoadAts_Test_AtsEmpty(void) +{ + uint8 AtsIndex = 0; - /* Use the remaining buffer space to calculate the final message size */ - MsgSize2 = ((SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_NOPKT_WORDS - j) * SC_BYTES_IN_WORD); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false); + UT_SC_ResetAtsTable(AtsIndex); /* Execute the function being tested */ SC_LoadAts(AtsIndex); /* 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_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_EMPTY); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); + UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_LoadAts_Test_CmdNotEmpty(void) +void SC_LoadAts_Test_LoadExactlyBufferLength(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - size_t MsgSize = sizeof(SC_NoArgsCmd_t); SC_AtsEntryHeader_t *Entry; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; uint8 AtsIndex = 0; - uint8 EntryLoc; - - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - memset(&AtsTable, 0, sizeof(AtsTable)); - - SC_InitTables(); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; + /* Set up -- Modify the final entry so it exactly takes up the remainder of the buffer */ + Entry = UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32, NULL); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + /* Execute the function being tested */ + SC_LoadAts(AtsIndex); - EntryLoc = ((MsgSize + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_NOPKT_WORDS; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryLoc]; - Entry->CmdNumber = 2; + /* Verify results */ + UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], 0); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, Entry->CmdNumber); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, SC_ATS_BUFF_SIZE32); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); +void SC_LoadAts_Test_CmdNotEmpty(void) +{ + void *TailPtr; + uint8 AtsIndex = 0; - /* This hook will set CmdNumber 2 SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] from SC_EMPTY to SC_LOADED */ - SC_LOADS_TEST_GetTotalMsgLengthHook_RunCount = 0; - UT_SetHookFunction(UT_KEY(CFE_MSG_GetSize), SC_LOADS_TEST_CFE_MSG_GetSizeHook1, NULL); + /* Set up a buffer that has a duplicate command number entry */ + TailPtr = UT_SC_ResetAtsTable(AtsIndex); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ SC_LoadAts(AtsIndex); @@ -569,41 +486,28 @@ void SC_LoadAts_Test_CmdNotEmpty(void) void SC_LoadAts_Test_InvalidIndex(void) { + uint8 AtsIndex = SC_NUMBER_OF_ATS; + /* Pass in invalid index */ - SC_LoadAts(SC_NUMBER_OF_ATS); + SC_LoadAts(AtsIndex); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_LOADATS_INV_INDEX_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } void SC_BuildTimeIndexTable_Test_InvalidIndex(void) { uint8 AtsIndex = SC_NUMBER_OF_ATS; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Build time index table error: invalid ATS index %%d"); - - SC_InitTables(); /* Execute the function being tested */ SC_BuildTimeIndexTable(AtsIndex); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_BUILD_TIME_IDXTBL_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_Insert_Test(void) @@ -612,7 +516,7 @@ void SC_Insert_Test(void) uint8 ListLength = 1; uint8 NewCmdIndex = 0; - SC_InitTables(); + UT_SC_ResetAtsTable(AtsIndex); SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; @@ -620,15 +524,10 @@ void SC_Insert_Test(void) SC_Insert(AtsIndex, NewCmdIndex, ListLength); /* Verify results */ - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex + 1, - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); } void SC_Insert_Test_MiddleOfList(void) @@ -641,7 +540,7 @@ void SC_Insert_Test_MiddleOfList(void) "new cmd will execute at same time or after this list entry" */ UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, false); - SC_InitTables(); + UT_SC_ResetAtsTable(AtsIndex); SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; @@ -649,15 +548,10 @@ void SC_Insert_Test_MiddleOfList(void) SC_Insert(AtsIndex, NewCmdIndex, ListLength); /* Verify results */ - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex + 1, - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex+1"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); } void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) @@ -670,7 +564,7 @@ void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) "new cmd will execute at same time or after this list entry" */ UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - SC_InitTables(); + UT_SC_ResetAtsTable(AtsIndex); SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; @@ -678,15 +572,10 @@ void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) SC_Insert(AtsIndex, NewCmdIndex, ListLength); /* Verify results */ - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex + 1, - "SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] == NewCmdIndex+1"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_True(call_count_CFE_EVS_SendEvent == 0, "CFE_EVS_SendEvent was called %u time(s), expected 0", - call_count_CFE_EVS_SendEvent); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); + UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); } void SC_Insert_Test_InvalidIndex(void) @@ -694,528 +583,207 @@ void SC_Insert_Test_InvalidIndex(void) uint8 AtsIndex = SC_NUMBER_OF_ATS; uint8 ListLength = 1; uint8 NewCmdIndex = 0; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "ATS insert error: invalid ATS index %%d"); - - SC_InitTables(); + UT_SC_ResetAtsTable(AtsIndex); /* Execute the function being tested */ SC_Insert(AtsIndex, NewCmdIndex, ListLength); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_INSERTATS_INV_INDEX_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_InitAtsTables_Test_InvalidIndex(void) { uint8 AtsIndex = SC_NUMBER_OF_ATS; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "ATS table init error: invalid ATS index %%d"); /* Execute the function being tested */ SC_InitAtsTables(AtsIndex); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_INIT_ATSTBL_INV_INDEX_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ValidateAts_Test(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 0; + UT_SC_ResetAtsTable(AtsIndex); /* Execute the function being tested */ - Result = SC_ValidateAts((uint16 *)(SC_OperData.AtsTblAddr[AtsIndex])); + UtAssert_INT32_EQ(SC_ValidateAts(SC_OperData.AtsTblAddr[AtsIndex]), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_MPT_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); } void SC_ValidateAppend_Test(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 0; + UT_SC_ResetAtsTable(AtsIndex); /* Execute the function being tested */ - Result = SC_ValidateAppend((SC_OperData.AtsTblAddr[AtsIndex])); + UtAssert_INT32_EQ(SC_ValidateAppend(SC_OperData.AtsTblAddr[AtsIndex]), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_MPT_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); } void SC_ValidateRts_Test(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; - size_t MsgSize = SC_PACKET_MIN_SIZE; - - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; + uint8 RtsIndex = 0; - /* The MsgId and MsgSize are here to satisfy TSF */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 1, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - Result = SC_ValidateRts((uint16 *)(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_INT32_EQ(SC_ValidateRts(SC_OperData.RtsTblAddr[RtsIndex]), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_INVLD_MID_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); } void SC_ValidateRts_Test_ParseRts(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; - size_t MsgSize = SC_PACKET_MIN_SIZE; - - SC_InitTables(); + uint8 RtsIndex = 0; - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 0; - - /* The MsgId and MsgSize are here to satisfy TSF */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 0, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - Result = SC_ValidateRts((uint16 *)(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_INT32_EQ(SC_ValidateRts(SC_OperData.RtsTblAddr[RtsIndex]), CFE_SUCCESS); /* Verify results */ - UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); - - 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); } void SC_LoadRts_Test_Nominal(void) { - uint8 AtsIndex = 0; + uint8 RtsIndex = 0; - SC_InitTables(); + UT_SC_ResetRtsTable(RtsIndex, CFE_SB_INVALID_MSG_ID); /* Execute the function being tested */ - SC_LoadRts(AtsIndex); + SC_LoadRts(RtsIndex); /* 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); } void SC_LoadRts_Test_InvalidIndex(void) { uint8 RtsIndex = SC_NUMBER_OF_RTS; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "RTS table init error: invalid RTS index %%d"); /* Execute the function being tested */ SC_LoadRts(RtsIndex); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_LOADRTS_INV_INDEX_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ParseRts_Test_EndOfFile(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; - size_t MsgSize = SC_PACKET_MIN_SIZE; + uint8 RtsIndex = 0; - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 0; - - /* Set these to satisfy if-statement to reach line with comment "assumed end of file" */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 0, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == true, "Result == true"); - - 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); } void SC_ParseRts_Test_InvalidMsgId(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; - size_t MsgSize = SC_PACKET_MIN_SIZE; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "RTS cmd loaded with invalid MID at %%d"); - - SC_InitTables(); + uint8 RtsIndex = 0; - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - - /* Set to generate error message SC_RTS_INVLD_MID_ERR_EID */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 1, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == false, "Result == false"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_INVLD_MID_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ParseRts_Test_LengthErrorTooShort(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize = 0; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "RTS cmd loaded with invalid length at %%d, len: %%d"); - - SC_InitTables(); + uint8 RtsIndex = 0; - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - - /* Set to generate error message SC_RTS_INVLD_MID_ERR_EID */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, SC_UT_MID_1, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == false, "Result == false"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LEN_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ParseRts_Test_LengthErrorTooLong(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize = SC_PACKET_MAX_SIZE + 1; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "RTS cmd loaded with invalid length at %%d, len: %%d"); + uint8 RtsIndex = 0; - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - - /* Set to generate error message SC_RTS_LEN_ERR_EID as a result of length being too long */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleRtsEntry(RtsIndex, SC_UT_MID_1, 1, SC_PACKET_MAX_SIZE + 1); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == false, "Result == false"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LEN_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ParseRts_Test_CmdRunsOffEndOfBuffer(void) { - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - int32 BufUnused = sizeof(RtsTable); - - memset(&RtsTable, 0, sizeof(RtsTable)); - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "RTS cmd at %%d runs off end of buffer"); + uint8 RtsIndex = 0; - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - - while (BufUnused > 0) - { - - /* Need to avoid exact fit and not having enough room for a command */ - if (BufUnused < SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE) - { - /* Use up more than what's left */ - MsgSize = SC_PACKET_MAX_SIZE; - } - else if (BufUnused < SC_PACKET_MIN_SIZE + SC_PACKET_MAX_SIZE + (2 * SC_RTS_HEADER_SIZE)) - { - /* Just set to min entry, use up next round */ - MsgSize = SC_PACKET_MIN_SIZE; - } - else - { - MsgSize = SC_PACKET_MAX_SIZE; - } - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), true); - BufUnused -= MsgSize; - } + /* Set up -- Modify the final entry so it would go off the end of the table */ + UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 + 1, NULL); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == false, "Result == false"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LEN_BUFFER_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ParseRts_Test_CmdLengthEqualsBufferLength(void) { - /* Also tests the case where CmdLength is less than the buffer length */ - - SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; - int16 Result; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize; - size_t BufUnused = sizeof(RtsTable); + uint8 RtsIndex = 0; - memset(&RtsTable, 0, sizeof(RtsTable)); - - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; - Entry->TimeTag = 1; - - /* Fill buffer with packets */ - while (BufUnused != 0) - { - - /* Need to consume data but leave room for a valid packet */ - if (BufUnused <= SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE) - { - /* Just use up what's left */ - MsgSize = BufUnused - SC_RTS_HEADER_SIZE; - } - else if (BufUnused < SC_PACKET_MIN_SIZE + SC_PACKET_MAX_SIZE + (2 * SC_RTS_HEADER_SIZE)) - { - /* Just set to min entry, use up next round */ - MsgSize = SC_PACKET_MIN_SIZE; - } - else - { - MsgSize = SC_PACKET_MAX_SIZE; - } - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), true); - BufUnused -= MsgSize + SC_RTS_HEADER_SIZE; - } + UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32, NULL); /* Execute the function being tested */ - Result = SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex]); + UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); /* Verify results */ - UtAssert_True(Result == true, "Result == true"); - - 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); } void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void) { - uint8 RtsIndex = 0; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize; - size_t BufUnused = sizeof(RtsTable); - - SC_InitTables(); + uint8 RtsIndex = 0; - memset(&RtsTable, 0, sizeof(RtsTable)); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - - /* Fill buffer with packets */ - while (BufUnused > SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE) - { - /* Need to consume data but leave room for a valid packet */ - if (BufUnused <= SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE) - { - /* Leave only room for another header */ - MsgSize = BufUnused - (2 * SC_RTS_HEADER_SIZE); - } - else if (BufUnused < SC_PACKET_MIN_SIZE + SC_PACKET_MAX_SIZE + (2 * SC_RTS_HEADER_SIZE)) - { - /* Just set to min entry, use up next round */ - MsgSize = SC_PACKET_MIN_SIZE; - } - else - { - MsgSize = SC_PACKET_MAX_SIZE; - } - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), true); - BufUnused -= MsgSize + SC_RTS_HEADER_SIZE; - } + UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 - 1, NULL); /* Execute the function being tested */ UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); @@ -1225,443 +793,193 @@ void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void) void SC_ParseRts_Test_CmdDoesNotFitBufferNotEmpty(void) { - uint8 RtsIndex = 0; - uint32 RtsTable[SC_RTS_BUFF_SIZE32]; - CFE_SB_MsgId_t TestMsgId = SC_UT_MID_1; - size_t MsgSize; - size_t BufUnused = sizeof(RtsTable); - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; + uint8 RtsIndex = 0; + void *TailPtr; - /* Filling the table so it is considered used wherever checked */ - memset(&RtsTable, 0xff, sizeof(RtsTable)); - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "RTS cmd loaded won't fit in buffer at %%d"); - - SC_InitTables(); - - SC_OperData.RtsTblAddr[RtsIndex] = &RtsTable[0]; - - /* Fill buffer with packets */ - while (BufUnused > SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE) - { - /* Need to consume data but leave room for a valid packet */ - if (BufUnused <= SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE) - { - /* Leave only room for another header */ - MsgSize = BufUnused - (2 * SC_RTS_HEADER_SIZE); - } - else if (BufUnused < SC_PACKET_MIN_SIZE + SC_PACKET_MAX_SIZE + (2 * SC_RTS_HEADER_SIZE)) - { - /* Just set to min entry, use up next round */ - MsgSize = SC_PACKET_MIN_SIZE; - } - else - { - MsgSize = SC_PACKET_MAX_SIZE; - } + UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 - 1, &TailPtr); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), true); - BufUnused -= MsgSize + SC_RTS_HEADER_SIZE; - } + /* Add some nonzero data at the tail end */ + *((uint32 *)TailPtr) = 0xFFFFFFFF; /* Execute the function being tested */ UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LEN_TOO_LONG_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); } void SC_UpdateAppend_Test_Nominal(void) { - /* Also tests the case where CmdLength is less than the buffer length */ + void *TailPtr; - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - Entry->CmdNumber = 1; - - /* Set to reach code block starting with comment "Compute buffer index for next Append ATS table entry" */ - MsgSize = 50; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 1, "SC_OperData.HkPacket.AppendEntryCount == 1"); - UtAssert_True(SC_AppData.AppendWordCount == 15, "SC_AppData.AppendWordCount == 15"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendEntryCount, 1); + UtAssert_UINT32_EQ(SC_AppData.AppendWordCount, (SC_ATS_HEADER_SIZE + UT_SC_NOMINAL_CMD_SIZE) / SC_BYTES_IN_WORD); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_CmdDoesNotFitBuffer(void) { - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int BufEntrySize; - int MaxBufEntries; - int j; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - - /* Set to reach code block starting with comment "Compute buffer index for next Append ATS table entry" */ - MsgSize = SC_PACKET_MAX_SIZE; - BufEntrySize = (MsgSize + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_ATS_HDR_NOPKT_WORDS; - MaxBufEntries = SC_APPEND_BUFF_SIZE32 / BufEntrySize; - - for (EntryIndex = 0, j = 0; EntryIndex <= MaxBufEntries; EntryIndex++, j += BufEntrySize) - { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[j]; - Entry->CmdNumber = EntryIndex + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - } + uint32 *FirstPtr; + uint32 *LastPtr; + void * TailPtr; + uint32 ExpectedCount; + + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + FirstPtr = TailPtr; + LastPtr = UT_SC_SetupFullTable(&TailPtr, SC_ATS_HEADER_SIZE, UT_SC_NOMINAL_CMD_SIZE, SC_APPEND_BUFF_SIZE32, + SC_APPEND_BUFF_SIZE32 + 1, UT_SC_AtsEntryInit); + ExpectedCount = (SC_APPEND_BUFF_SIZE32 / UT_SC_GetEntryWordCount(SC_ATS_HEADER_SIZE, UT_SC_NOMINAL_CMD_SIZE)) - 1; /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 30, "SC_OperData.HkPacket.AppendEntryCount == 30"); - UtAssert_True(SC_AppData.AppendWordCount == 1980, "SC_AppData.AppendWordCount == 1980"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendEntryCount, ExpectedCount); + UtAssert_UINT32_EQ(SC_AppData.AppendWordCount, LastPtr - FirstPtr); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_InvalidCmdLengthTooLow(void) { - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - Entry->CmdNumber = 1; + void *TailPtr; - /* Set to satisfy condition "(CommandBytes < SC_PACKET_MIN_SIZE)" */ - MsgSize = SC_PACKET_MIN_SIZE - 1; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 0, "SC_OperData.HkPacket.AppendEntryCount == 0"); - UtAssert_True(SC_AppData.AppendWordCount == 0, "SC_AppData.AppendWordCount == 0"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_ZERO(SC_OperData.HkPacket.AppendEntryCount); + UtAssert_ZERO(SC_AppData.AppendWordCount); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_InvalidCmdLengthTooHigh(void) { - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - Entry->CmdNumber = 1; + void *TailPtr; - /* Set to satisfy condition "(CommandBytes > SC_PACKET_MAX_SIZE)" */ - MsgSize = SC_PACKET_MAX_SIZE * 2; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, SC_PACKET_MAX_SIZE + 1); /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 0, "SC_OperData.HkPacket.AppendEntryCount == 0"); - UtAssert_True(SC_AppData.AppendWordCount == 0, "SC_AppData.AppendWordCount == 0"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_ZERO(SC_OperData.HkPacket.AppendEntryCount); + UtAssert_ZERO(SC_AppData.AppendWordCount); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_EndOfBuffer(void) { - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize1; - size_t MsgSize2; - int BufEntrySize; - int MaxBufEntries; - int j; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - - /* Cause condition to be met: "(EntryIndex >= SC_APPEND_BUFF_SIZE)" */ - MsgSize1 = SC_PACKET_MAX_SIZE; - BufEntrySize = (MsgSize1 + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD + SC_ATS_HDR_NOPKT_WORDS; - MaxBufEntries = SC_APPEND_BUFF_SIZE32 / BufEntrySize; - - for (EntryIndex = 0, j = 0; EntryIndex <= MaxBufEntries; EntryIndex++, j += BufEntrySize) - { - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[j]; - Entry->CmdNumber = EntryIndex + 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize1, sizeof(MsgSize1), false); - if (EntryIndex == (MaxBufEntries - 1)) - { - MsgSize2 = 72; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize2, sizeof(MsgSize2), false); - } - } + void * TailPtr; + uint32 ExpectedCount; + + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_SetupFullTable(&TailPtr, SC_ATS_HEADER_SIZE, UT_SC_NOMINAL_CMD_SIZE, SC_APPEND_BUFF_SIZE32, + SC_APPEND_BUFF_SIZE32, UT_SC_AtsEntryInit); + ExpectedCount = SC_APPEND_BUFF_SIZE32 / UT_SC_GetEntryWordCount(SC_ATS_HEADER_SIZE, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 31, "SC_OperData.HkPacket.AppendEntryCount == 31"); - UtAssert_True(SC_AppData.AppendWordCount == 2000, "SC_AppData.AppendWordCount == 2000"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendEntryCount, ExpectedCount); + UtAssert_UINT32_EQ(SC_AppData.AppendWordCount, SC_APPEND_BUFF_SIZE32); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_CmdNumberZero(void) { - /* Also tests the case where CmdLength is less than the buffer length */ - - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); - - SC_InitTables(); + void *TailPtr; - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - Entry->CmdNumber = 0; - - /* Cause condition to be met: "(Entry->CmdNumber == 0)" */ - MsgSize = 50; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 0, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - SC_UpdateAppend(); + UtAssert_VOIDCALL(SC_UpdateAppend()); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 0, "SC_OperData.HkPacket.AppendEntryCount == 0"); - UtAssert_True(SC_AppData.AppendWordCount == 0, "SC_AppData.AppendWordCount == 0"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_ZERO(SC_OperData.HkPacket.AppendEntryCount); + UtAssert_ZERO(SC_AppData.AppendWordCount); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_UpdateAppend_Test_CmdNumberTooHigh(void) { - /* Also tests the case where CmdLength is less than the buffer length */ - - SC_AtsEntryHeader_t *Entry; - uint8 EntryIndex = 0; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Update Append ATS Table: load count = %%d, command count = %%d, byte count = %%d"); + void *TailPtr; - SC_InitTables(); - - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - Entry->CmdNumber = SC_MAX_ATS_CMDS + 1; - - /* Cause condition to be met: "(Entry->CmdNumber > SC_MAX_ATS_CMDS)" */ - MsgSize = 50; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_ResetAtsTable(0); + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, SC_MAX_ATS_CMDS + 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ SC_UpdateAppend(); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.AppendLoadCount == 1, "SC_OperData.HkPacket.AppendLoadCount == 1"); - UtAssert_True(SC_OperData.HkPacket.AppendEntryCount == 0, "SC_OperData.HkPacket.AppendEntryCount == 0"); - UtAssert_True(SC_AppData.AppendWordCount == 0, "SC_AppData.AppendWordCount == 0"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.AppendLoadCount, 1); + UtAssert_ZERO(SC_OperData.HkPacket.AppendEntryCount); + UtAssert_ZERO(SC_AppData.AppendWordCount); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_UPDATE_APPEND_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_ProcessAppend_Test(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - - SC_InitTables(); - - memset(&AtsTable, 0, sizeof(AtsTable)); - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; - SC_OperData.AtsCtrlBlckAddr = &SC_APP_TEST_GlobalAtsCtrlBlck; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; + uint8 AtsIndex = 0; + void *TailPtr; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[AtsIndex]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.AppendEntryCount = 1; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - - MsgSize = SC_PACKET_MIN_SIZE; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; /* restart ATS */ UT_SetDeferredRetcode(UT_KEY(SC_BeginAts), 1, true); @@ -1670,654 +988,293 @@ void SC_ProcessAppend_Test(void) SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1"); - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0, "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtpState == SC_EXECUTING, - "SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_EXECUTING); - 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); } void SC_ProcessAppend_Test_CmdLoaded(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - - SC_InitTables(); - - memset(&AtsTable, 0, sizeof(AtsTable)); - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; - SC_OperData.AtsCtrlBlckAddr = &SC_APP_TEST_GlobalAtsCtrlBlck; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; + uint8 AtsIndex = 0; + void *TailPtr; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[AtsIndex]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.AppendEntryCount = 1; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_LOADED; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING; SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - MsgSize = SC_PACKET_MIN_SIZE; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - /* Execute the function being tested */ SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0"); - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0, "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtpState == SC_EXECUTING, - "SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 0); + UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_EXECUTING); - 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); } void SC_ProcessAppend_Test_NotExecuting(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - - SC_InitTables(); - - memset(&AtsTable, 0, sizeof(AtsTable)); - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; - SC_OperData.AtsCtrlBlckAddr = &SC_APP_TEST_GlobalAtsCtrlBlck; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; + uint8 AtsIndex = 0; + void *TailPtr; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[AtsIndex]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.AppendEntryCount = 1; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_IDLE; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - - MsgSize = SC_PACKET_MIN_SIZE; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_IDLE; + SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; /* Execute the function being tested */ SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1"); - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0, "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtpState == SC_IDLE, "SC_OperData.AtsCtrlBlckAddr->AtpState = SC_IDLE"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_IDLE); - 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); } void SC_ProcessAppend_Test_AtsNumber(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - SC_AtsInfoTable_t AtsInfoTbl; - uint32 AtsAppendTable[SC_APPEND_BUFF_SIZE32]; - size_t MsgSize; - - SC_InitTables(); - - memset(&AtsTable, 0, sizeof(AtsTable)); - memset(&AtsAppendTable, 0, sizeof(AtsAppendTable)); - memset(&AtsInfoTbl, 0, sizeof(AtsInfoTbl)); - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex] = &SC_APP_TEST_GlobalAtsCmdStatusTbl[0]; - SC_OperData.AtsInfoTblAddr = &AtsInfoTbl; - SC_OperData.AtsCtrlBlckAddr = &SC_APP_TEST_GlobalAtsCtrlBlck; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - SC_OperData.AppendTblAddr = &AtsAppendTable[0]; + uint8 AtsIndex = 0; + void *TailPtr; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr[AtsIndex]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + TailPtr = UT_SC_ResetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.AppendEntryCount = 1; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_EMPTY; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 0; - - MsgSize = SC_PACKET_MIN_SIZE; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->AtsNumber = 0; /* Execute the function being tested */ - SC_ProcessAppend(AtsIndex); + UtAssert_VOIDCALL(SC_ProcessAppend(AtsIndex)); /* Verify results */ - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize == 1"); - UtAssert_True(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1, - "SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 1"); - UtAssert_True(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0, "SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] == 0"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_LOADED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtpState == SC_EXECUTING, - "SC_OperData.AtsCtrlBlckAddr->AtpState = SC_EXECUTING"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); + UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); + UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_LOADED); + UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_EXECUTING); - 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); } void SC_ProcessAppend_Test_InvalidIndex(void) { uint8 AtsIndex = SC_NUMBER_OF_ATS; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "ATS process append error: invalid ATS index %%d"); /* Execute the function being tested */ - SC_ProcessAppend(AtsIndex); + UtAssert_VOIDCALL(SC_ProcessAppend(AtsIndex)); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_PROCESS_APPEND_INV_INDEX_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsTable_Test_Nominal(void) { - SC_AtsEntryHeader_t *Entry1; - SC_AtsEntryHeader_t *Entry2; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - memset(&AtsTable, 0, sizeof(AtsTable)); - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table: command count = %%d, byte count = %%d"); - - SC_InitTables(); - - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - - Entry1 = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry1->CmdNumber = 1; - - Entry2 = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][128]; - Entry2->CmdNumber = 0; + uint8 AtsIndex = 0; - /* Set to call to SC_VerifyAtsEntry will return SC_PACKET_MAX_SIZE, which will cause execution of - * code block starting with comment "Result is size (in words) of this entry" */ - MsgSize = SC_PACKET_MAX_SIZE; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), CFE_SUCCESS); /* Verify results */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); /* Test element 1. Note: element 0 is modified in call to SC_VerifyAtsEntry and so it does not need to be verified * in this test */ - UtAssert_True(SC_OperData.AtsDupTestArray[1] == SC_DUP_TEST_UNUSED, - "SC_OperData.AtsDupTestArray[1] == SC_DUP_TEST_UNUSED"); + UtAssert_INT32_EQ(SC_OperData.AtsDupTestArray[1], SC_DUP_TEST_UNUSED); /* Test middle element. Note: element 0 is modified in call to SC_VerifyAtsEntry */ - UtAssert_True(SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS / 2] == SC_DUP_TEST_UNUSED, - "SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS / 2] == SC_DUP_TEST_UNUSED"); + UtAssert_INT32_EQ(SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS / 2], SC_DUP_TEST_UNUSED); /* Test last element */ - UtAssert_True(SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS - 1] == SC_DUP_TEST_UNUSED, - "SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS - 1] == SC_DUP_TEST_UNUSED"); - - UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_EID); - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); + UtAssert_INT32_EQ(SC_OperData.AtsDupTestArray[SC_MAX_ATS_CMDS - 1], SC_DUP_TEST_UNUSED); } void SC_VerifyAtsTable_Test_InvalidEntry(void) { - SC_AtsEntryHeader_t *Entry1; - SC_AtsEntryHeader_t *Entry2; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - - SC_InitTables(); - - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - - Entry1 = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry1->CmdNumber = 5000; + uint8 AtsIndex = 0; - Entry2 = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][128]; - Entry2->CmdNumber = 0; + UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS + 10, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_NUM_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); } void SC_VerifyAtsTable_Test_EmptyTable(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Verify ATS Table error: table is empty"); - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 0; + UT_SC_ResetAtsTable(AtsIndex); /* Execute the function being tested */ - Result = SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_MPT_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_Nominal(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); SC_OperData.AtsDupTestArray[0] = SC_DUP_TEST_UNUSED; - /* Set to reach code block starting with comment "Compute length (in words) for this ATS table entry" */ - MsgSize = SC_PACKET_MAX_SIZE; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(SC_OperData.AtsTblAddr[AtsIndex], 0, SC_ATS_BUFF_SIZE), + SC_ATS_HDR_NOPKT_WORDS + ((SC_PACKET_MAX_SIZE + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD)); /* Verify results */ - UtAssert_True(Result == SC_ATS_HDR_NOPKT_WORDS + ((SC_PACKET_MAX_SIZE + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD), - "Result == SC_ATS_HDR_NOPKT_WORDS + (SC_PACKET_MAX_SIZE + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD"); - UtAssert_True(SC_OperData.AtsDupTestArray[0] == 0, "SC_OperData.AtsDupTestArray[0] == 0"); - - 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); + UtAssert_ZERO(SC_OperData.AtsDupTestArray[0]); } void SC_VerifyAtsEntry_Test_EndOfBuffer(void) { - uint16 AtsIndex = 10000; - int16 Result; + uint8 AtsIndex = 0; - SC_InitTables(); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[0]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 10000, SC_ATS_BUFF_SIZE), CFE_SUCCESS); /* Verify results */ - UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); - - 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); } void SC_VerifyAtsEntry_Test_InvalidCmdNumber(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: invalid command number: buf index = %%d, cmd num = %%d"); - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 5000; + UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS + 20, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_NUM_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_BufferFull(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: buffer full: buf index = %%d, cmd num = %%d, buf words = %%d"); - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, 2); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, 2), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_END_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooLow(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: invalid length: buf index = %%d, cmd num = %%d, pkt len = %%d"); - - SC_InitTables(); - - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + uint8 AtsIndex = 0; - /* Set to generate error message SC_VERIFY_ATS_PKT_ERR_EID by satisfying condition "(CommandBytes < - * SC_PACKET_MIN_SIZE)" */ - MsgSize = SC_PACKET_MIN_SIZE - 1; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_PKT_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooHigh(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: invalid length: buf index = %%d, cmd num = %%d, pkt len = %%d"); - - SC_InitTables(); - - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + uint8 AtsIndex = 0; - /* Set to generate error message SC_VERIFY_ATS_PKT_ERR_EID by satisfying condition "(CommandBytes < - * SC_PACKET_MIN_SIZE)" */ - MsgSize = SC_PACKET_MAX_SIZE * 2; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE * 2); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_PKT_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_BufferOverflow(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: buffer overflow: buf index = %%d, cmd num = %%d, pkt len = %%d"); - - SC_InitTables(); - - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + uint8 AtsIndex = 0; - /* Set to generate error message SC_VERIFY_ATS_BUF_ERR_EID */ - MsgSize = SC_PACKET_MAX_SIZE; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, 20); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, 20), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_BUF_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void SC_VerifyAtsEntry_Test_DuplicateCmdNumber(void) { - SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; - int16 Result; - uint32 AtsTable[SC_ATS_BUFF_SIZE32]; - size_t MsgSize; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Verify ATS Table error: dup cmd number: buf index = %%d, cmd num = %%d, dup index = %%d"); - - SC_InitTables(); + uint8 AtsIndex = 0; - SC_OperData.AtsTblAddr[AtsIndex] = &AtsTable[0]; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); /* Set to generate error message SC_VERIFY_ATS_DUP_ERR_EID */ - MsgSize = SC_PACKET_MAX_SIZE; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); - SC_OperData.AtsDupTestArray[0] = 99; /* Execute the function being tested */ - Result = SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE); + UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ - UtAssert_True(Result == SC_ERROR, "Result == SC_ERROR"); - + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_VERIFY_ATS_DUP_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1", - call_count_CFE_EVS_SendEvent); } void UtTest_Setup(void) @@ -2328,11 +1285,11 @@ void UtTest_Setup(void) UtTest_Add(SC_LoadAts_Test_CmdLengthInvalid, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_CmdLengthInvalid"); UtTest_Add(SC_LoadAts_Test_CmdLengthZero, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_CmdLengthZero"); UtTest_Add(SC_LoadAts_Test_CmdNumberInvalid, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_CmdNumberInvalid"); - UtTest_Add(SC_LoadAts_Test_EndOfLoadReached, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_EndOfLoadReached"); UtTest_Add(SC_LoadAts_Test_AtsBufferTooSmall, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_AtsBufferTooSmall"); - UtTest_Add(SC_LoadAts_Test_AtsEntryOverflow, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_AtsEntryOverflow"); + UtTest_Add(SC_LoadAts_Test_AtsEmpty, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_AtsEmpty"); UtTest_Add(SC_LoadAts_Test_LoadExactlyBufferLength, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_LoadExactlyBufferLength"); + UtTest_Add(SC_LoadAts_Test_CmdNotEmpty, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_CmdNotEmpty"); UtTest_Add(SC_LoadAts_Test_InvalidIndex, SC_Test_Setup, SC_Test_TearDown, "SC_LoadAts_Test_InvalidIndex");