From 93405c3698faa1bc9dc3f11f0e9e69df3c33aacf Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 15 Jun 2022 12:04:58 -0600 Subject: [PATCH 1/2] Fix #17, Refactor redundant conditions to allow full code coverage --- fsw/src/lc_action.c | 41 ++++++++++++++++------------------------- fsw/src/lc_watch.c | 15 +++++++-------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/fsw/src/lc_action.c b/fsw/src/lc_action.c index bef49a6..41db97a 100644 --- a/fsw/src/lc_action.c +++ b/fsw/src/lc_action.c @@ -287,15 +287,6 @@ void LC_SampleSingleAP(uint16 APNumber) * in the RPMStack array, then returns the next element. */ #define POP_RPN_DATA ((StackPtr <= 0) ? (IllegalRPN = true) : (RPNStack[--StackPtr])) - -/* - * StackPtr is an index into an array RPNStack (see LC_EvaluateRPN) - * which contains values to be used in an RPN function. This macro - * validates the StackPtr to confirm that there is space for additional - * values in the RPNStack array, then inserts the provided element value - * into the next available location in the array. - */ -#define PUSH_RPN_DATA(x) ((StackPtr >= LC_MAX_RPN_EQU_SIZE) ? (IllegalRPN = true) : (RPNStack[StackPtr++] = x)) uint8 LC_EvaluateRPN(uint16 APNumber) { bool Done; @@ -341,19 +332,19 @@ uint8 LC_EvaluateRPN(uint16 APNumber) Operand1 = POP_RPN_DATA; if ((Operand1 == LC_WATCH_FALSE) || (Operand2 == LC_WATCH_FALSE)) { - PUSH_RPN_DATA(LC_WATCH_FALSE); + RPNStack[StackPtr++] = LC_WATCH_FALSE; } else if ((Operand1 == LC_WATCH_ERROR) || (Operand2 == LC_WATCH_ERROR)) { - PUSH_RPN_DATA(LC_WATCH_ERROR); + RPNStack[StackPtr++] = LC_WATCH_ERROR; } else if ((Operand1 == LC_WATCH_STALE) || (Operand2 == LC_WATCH_STALE)) { - PUSH_RPN_DATA(LC_WATCH_STALE); + RPNStack[StackPtr++] = LC_WATCH_STALE; } else { - PUSH_RPN_DATA(LC_WATCH_TRUE); + RPNStack[StackPtr++] = LC_WATCH_TRUE; } break; @@ -362,19 +353,19 @@ uint8 LC_EvaluateRPN(uint16 APNumber) Operand1 = POP_RPN_DATA; if ((Operand1 == LC_WATCH_TRUE) || (Operand2 == LC_WATCH_TRUE)) { - PUSH_RPN_DATA(LC_WATCH_TRUE); + RPNStack[StackPtr++] = LC_WATCH_TRUE; } else if ((Operand1 == LC_WATCH_ERROR) || (Operand2 == LC_WATCH_ERROR)) { - PUSH_RPN_DATA(LC_WATCH_ERROR); + RPNStack[StackPtr++] = LC_WATCH_ERROR; } else if ((Operand1 == LC_WATCH_STALE) || (Operand2 == LC_WATCH_STALE)) { - PUSH_RPN_DATA(LC_WATCH_STALE); + RPNStack[StackPtr++] = LC_WATCH_STALE; } else { - PUSH_RPN_DATA(LC_WATCH_FALSE); + RPNStack[StackPtr++] = LC_WATCH_FALSE; } break; @@ -383,15 +374,15 @@ uint8 LC_EvaluateRPN(uint16 APNumber) Operand1 = POP_RPN_DATA; if ((Operand1 == LC_WATCH_ERROR) || (Operand2 == LC_WATCH_ERROR)) { - PUSH_RPN_DATA(LC_WATCH_ERROR); + RPNStack[StackPtr++] = LC_WATCH_ERROR; } else if ((Operand1 == LC_WATCH_STALE) || (Operand2 == LC_WATCH_STALE)) { - PUSH_RPN_DATA(LC_WATCH_STALE); + RPNStack[StackPtr++] = LC_WATCH_STALE; } else { - PUSH_RPN_DATA(Operand1 != Operand2); + RPNStack[StackPtr++] = (Operand1 != Operand2); } break; @@ -399,15 +390,15 @@ uint8 LC_EvaluateRPN(uint16 APNumber) Operand1 = POP_RPN_DATA; if (Operand1 == LC_WATCH_ERROR) { - PUSH_RPN_DATA(LC_WATCH_ERROR); + RPNStack[StackPtr++] = LC_WATCH_ERROR; } else if (Operand1 == LC_WATCH_STALE) { - PUSH_RPN_DATA(LC_WATCH_STALE); + RPNStack[StackPtr++] = LC_WATCH_STALE; } else { - PUSH_RPN_DATA(Operand1 == LC_WATCH_FALSE); + RPNStack[StackPtr++] = (Operand1 == LC_WATCH_FALSE); } break; @@ -417,7 +408,7 @@ uint8 LC_EvaluateRPN(uint16 APNumber) { IllegalOperand = true; } - if (StackPtr == 0) + else if (StackPtr == 0) { Done = true; } @@ -434,7 +425,7 @@ uint8 LC_EvaluateRPN(uint16 APNumber) default: if (RPNData < LC_MAX_WATCHPOINTS) { - PUSH_RPN_DATA(LC_OperData.WRTPtr[RPNData].WatchResult); + RPNStack[StackPtr++] = LC_OperData.WRTPtr[RPNData].WatchResult; } else { diff --git a/fsw/src/lc_watch.c b/fsw/src/lc_watch.c index eb10bc1..3a8afaa 100644 --- a/fsw/src/lc_watch.c +++ b/fsw/src/lc_watch.c @@ -976,11 +976,10 @@ int32 LC_ValidateWDT(void *TableData) */ UnusedCount++; } - else if ((DataType != LC_DATA_BYTE) && (DataType != LC_DATA_UBYTE) && (DataType != LC_DATA_BYTE) && - (DataType != LC_DATA_UBYTE) && (DataType != LC_DATA_WORD_BE) && (DataType != LC_DATA_WORD_LE) && - (DataType != LC_DATA_UWORD_BE) && (DataType != LC_DATA_UWORD_LE) && (DataType != LC_DATA_DWORD_BE) && - (DataType != LC_DATA_DWORD_LE) && (DataType != LC_DATA_UDWORD_BE) && (DataType != LC_DATA_UDWORD_LE) && - (DataType != LC_DATA_FLOAT_BE) && (DataType != LC_DATA_FLOAT_LE)) + else if ((DataType != LC_DATA_BYTE) && (DataType != LC_DATA_UBYTE) && (DataType != LC_DATA_WORD_BE) && + (DataType != LC_DATA_WORD_LE) && (DataType != LC_DATA_UWORD_BE) && (DataType != LC_DATA_UWORD_LE) && + (DataType != LC_DATA_DWORD_BE) && (DataType != LC_DATA_DWORD_LE) && (DataType != LC_DATA_UDWORD_BE) && + (DataType != LC_DATA_UDWORD_LE) && (DataType != LC_DATA_FLOAT_BE) && (DataType != LC_DATA_FLOAT_LE)) { /* ** Invalid data type @@ -988,9 +987,9 @@ int32 LC_ValidateWDT(void *TableData) BadCount++; EntryResult = LC_WDTVAL_ERR_DATATYPE; } - else if ((OperatorID != LC_OPER_LT) && (OperatorID != LC_OPER_LT) && (OperatorID != LC_OPER_LE) && - (OperatorID != LC_OPER_NE) && (OperatorID != LC_OPER_EQ) && (OperatorID != LC_OPER_GE) && - (OperatorID != LC_OPER_GT) && (OperatorID != LC_OPER_CUSTOM)) + else if ((OperatorID != LC_OPER_LT) && (OperatorID != LC_OPER_LE) && (OperatorID != LC_OPER_NE) && + (OperatorID != LC_OPER_EQ) && (OperatorID != LC_OPER_GE) && (OperatorID != LC_OPER_GT) && + (OperatorID != LC_OPER_CUSTOM)) { /* ** Invalid operator From 426dde9d9244532c8696ac48e9b49b8dfe3f929d Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 15 Jun 2022 12:06:15 -0600 Subject: [PATCH 2/2] Fix #22, Improve UT code coverage --- .github/workflows/unit-test-coverage.yml | 3 - unit-test/lc_action_tests.c | 144 ++++++++-- unit-test/lc_app_tests.c | 349 ++++++++++++----------- unit-test/lc_watch_tests.c | 133 ++------- 4 files changed, 339 insertions(+), 290 deletions(-) diff --git a/.github/workflows/unit-test-coverage.yml b/.github/workflows/unit-test-coverage.yml index 84c9834..d67e62b 100644 --- a/.github/workflows/unit-test-coverage.yml +++ b/.github/workflows/unit-test-coverage.yml @@ -8,6 +8,3 @@ jobs: unit-test-coverage: name: Run unit test and coverage uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main - with: - max-missed-branches: 42 - max-missed-lines: 5 diff --git a/unit-test/lc_action_tests.c b/unit-test/lc_action_tests.c index 6521b9d..639ef58 100644 --- a/unit-test/lc_action_tests.c +++ b/unit-test/lc_action_tests.c @@ -1061,38 +1061,53 @@ void LC_EvaluateRPN_Test_NotNominal(void) } /* end LC_EvaluateRPN_Test_NotNominal */ -void LC_EvaluateRPN_Test_EqualIllegalRPN(void) +void LC_EvaluateRPN_Test_Equal(void) { - uint8 Result; uint16 APNumber = 0; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "AP has illegal RPN expression: AP = %%d, LastOperand = %%d, StackPtr = %%d"); + /* Pass */ + LC_OperData.ADTPtr[APNumber].RPNEquation[0] = 0; + LC_OperData.ADTPtr[APNumber].RPNEquation[1] = LC_RPN_EQUAL; + + LC_OperData.WRTPtr[0].WatchResult = LC_WATCH_FALSE; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(APNumber), LC_ACTION_PASS); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + + /* Fail */ + LC_OperData.WRTPtr[0].WatchResult = LC_WATCH_TRUE; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(APNumber), LC_ACTION_FAIL); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + + /* LC_WATCH_ERROR */ + LC_OperData.WRTPtr[0].WatchResult = LC_WATCH_ERROR; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(APNumber), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + + /* LC_WATCH_STALE */ + LC_OperData.WRTPtr[0].WatchResult = LC_WATCH_STALE; + UtAssert_UINT32_EQ(LC_EvaluateRPN(APNumber), LC_ACTION_STALE); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + + /* Fail empty stack pointer check */ LC_OperData.ADTPtr[APNumber].RPNEquation[0] = 0; - LC_OperData.ADTPtr[APNumber].RPNEquation[1] = 1; + LC_OperData.ADTPtr[APNumber].RPNEquation[1] = 0; LC_OperData.ADTPtr[APNumber].RPNEquation[2] = LC_RPN_EQUAL; LC_OperData.WRTPtr[0].WatchResult = 77; - LC_OperData.WRTPtr[1].WatchResult = 77; - - /* Execute the function being tested */ - Result = LC_EvaluateRPN(APNumber); - /* Verify results */ - UtAssert_True(Result == LC_ACTION_ERROR, "Result == LC_ACTION_ERROR"); + UtAssert_UINT32_EQ(LC_EvaluateRPN(APNumber), LC_ACTION_ERROR); - UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)), 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_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); - -} /* end LC_EvaluateRPN_Test_EqualIllegalRPN */ +} void LC_EvaluateRPN_Test_WatchpointNumberNominal(void) { @@ -1178,6 +1193,91 @@ void LC_EvaluateRPN_Test_EndOfBufferWhenNotDone(void) } /* end LC_EvaluateRPN_Test_EndOfBufferWhenNotDone */ +void LC_EvaluateRPN_Test_PushPopFail(void) +{ + /* Fail LC_RPN_AND pop 2 */ + LC_OperData.ADTPtr[0].RPNEquation[0] = 0; + LC_OperData.ADTPtr[0].RPNEquation[1] = LC_RPN_AND; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_AND pop 1 */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = LC_RPN_AND; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_OR pop 2 */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = 0; + LC_OperData.ADTPtr[0].RPNEquation[1] = LC_RPN_OR; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_OR pop 1 */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = LC_RPN_OR; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_XOR pop 2 */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = 0; + LC_OperData.ADTPtr[0].RPNEquation[1] = LC_RPN_XOR; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_XOR pop 1 */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = LC_RPN_XOR; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_NOT pop */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = LC_RPN_NOT; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Fail LC_RPN_EQUAL pop */ + UT_ResetState(0); + LC_OperData.ADTPtr[0].RPNEquation[0] = LC_RPN_EQUAL; + + UtAssert_UINT32_EQ(LC_EvaluateRPN(0), LC_ACTION_ERROR); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_INVALID_RPN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); +} + void LC_ValidateADT_Test_ActionNotUsed(void) { uint8 Result; @@ -1748,14 +1848,14 @@ void UtTest_Setup(void) UtTest_Add(LC_EvaluateRPN_Test_OrNominal, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_OrNominal"); UtTest_Add(LC_EvaluateRPN_Test_XorNominal, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_XorNominal"); UtTest_Add(LC_EvaluateRPN_Test_NotNominal, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_NotNominal"); - UtTest_Add(LC_EvaluateRPN_Test_EqualIllegalRPN, LC_Test_Setup, LC_Test_TearDown, - "LC_EvaluateRPN_Test_EqualIllegalRPN"); + UtTest_Add(LC_EvaluateRPN_Test_Equal, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_Equal"); UtTest_Add(LC_EvaluateRPN_Test_WatchpointNumberNominal, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_WatchpointNumberNominal"); UtTest_Add(LC_EvaluateRPN_Test_DefaultIllegalRPN, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_DefaultIllegalRPN"); UtTest_Add(LC_EvaluateRPN_Test_EndOfBufferWhenNotDone, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_EndOfBufferWhenNotDone"); + UtTest_Add(LC_EvaluateRPN_Test_PushPopFail, LC_Test_Setup, LC_Test_TearDown, "LC_EvaluateRPN_Test_PushPopFail"); UtTest_Add(LC_ValidateADT_Test_Nominal, LC_Test_Setup, LC_Test_TearDown, "LC_ValidateADT_Test_Nominal"); UtTest_Add(LC_ValidateADT_Test_ActionNotUsed, LC_Test_Setup, LC_Test_TearDown, "LC_ValidateADT_Test_ActionNotUsed"); diff --git a/unit-test/lc_app_tests.c b/unit-test/lc_app_tests.c index 5282eae..2d226e4 100644 --- a/unit-test/lc_app_tests.c +++ b/unit-test/lc_app_tests.c @@ -36,6 +36,8 @@ #include "lc_test_utils.h" #include "lc_cmds.h" +#include "cfe.h" + /* UT includes */ #include "uttest.h" #include "utassert.h" @@ -97,6 +99,35 @@ int32 LC_APP_TEST_CFE_TBL_RegisterHook4(void *UserObj, int32 StubRetcode, uint32 return -1; } +/* Hook used to override CDS settings */ +static void UT_Handler_CFE_ES_RunLoop(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) +{ + uint16 CallCount; + bool Status = false; + + CallCount = UT_GetStubCount(FuncKey); + + /* Exercise each option for coverage */ + if (CallCount == 1) + { + LC_OperData.HaveActiveCDS = false; + LC_AppData.CDSSavedOnExit = 0; + } + else if (CallCount == 2) + { + LC_OperData.HaveActiveCDS = true; + LC_AppData.CDSSavedOnExit = 0; + } + else + { + LC_OperData.HaveActiveCDS = true; + LC_AppData.CDSSavedOnExit = LC_CDS_SAVED; + } + + /* Always return false */ + UT_Stub_SetReturnValue(FuncKey, Status); +} + void LC_AppMain_Test_Nominal(void) { UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); @@ -119,35 +150,21 @@ void LC_AppMain_Test_Nominal(void) void LC_AppMain_Test_NominalCDSSave(void) { - LC_OperData.HaveActiveCDS = true; - LC_AppData.CDSSavedOnExit = LC_CDS_SAVED; - - /* Setup LC_CreateTaskCDS to succeed */ - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); - LC_AppData.CDSSavedOnExit = LC_CDS_SAVED; - - UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 3, CFE_TBL_INFO_RECOVERED_TBL); - UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_INFO_RECOVERED_TBL); - - UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, false); - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), CFE_SUCCESS); - - UT_SetDefaultReturnValue(UT_KEY(LC_AppPipe), CFE_SUCCESS); + /* Handler forces CDS conditions based on call count */ + UT_SetHandlerFunction(UT_KEY(CFE_ES_RunLoop), &UT_Handler_CFE_ES_RunLoop, NULL); + /* Cycle through all conditions forced by handler */ LC_AppMain(); + UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(LC_UpdateTaskCDS)), 0); - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - /* generates 2 messages we don't care about in this test */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 2); - - UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_ES_ExitApp)), 1); - - UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(LC_AppPipe)), 1); + /* Reset SendEvent to avoid filling buffer */ + UT_ResetState(UT_KEY(CFE_EVS_SendEvent)); + LC_AppMain(); + UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(LC_UpdateTaskCDS)), 0); - // UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(LC_UpdateTaskCDS)), 1); //TODO + UT_ResetState(UT_KEY(CFE_EVS_SendEvent)); + LC_AppMain(); + UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(LC_UpdateTaskCDS)), 1); } void LC_AppMain_Test_NominalCDSNoSave(void) @@ -512,29 +529,18 @@ void LC_SbInit_Test_SubscribeSampleCmdError(void) } /* end LC_SbInit_Test_SubscribeSampleCmdError */ -#ifndef LC_SAVE_TO_CDS -void LC_TableInit_Test_NoActiveCDS(void) -{ - LC_OperData.HaveActiveCDS = false; -} -#endif - void LC_TableInit_Test_CreateResultsTablesError(void) { - int32 Result; LC_OperData.HaveActiveCDS = true; /* force LC_CreateResultTables to fail */ UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), -1); - Result = LC_TableInit(); - - UtAssert_True(Result == -1, "Result == -1"); + UtAssert_INT32_EQ(LC_TableInit(), -1); } void LC_TableInit_Test_CreateDefinitionTablesError(void) { - int32 Result; LC_OperData.HaveActiveCDS = true; /* force LC_CreateDefinitionTables to fail (but allow LC_CreateResultsTables @@ -544,23 +550,98 @@ void LC_TableInit_Test_CreateDefinitionTablesError(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, -1); UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, -1); - Result = LC_TableInit(); - - UtAssert_True(Result == -1, "Result == -1"); + UtAssert_INT32_EQ(LC_TableInit(), -1); } -void LC_TableInit_Test_LoadDefaultTablesError(void) {} - -void LC_TableInit_Test_GetWDTAddressError(void) +/* Hits the uncovered branches related to LoadDefaultTables */ +void LC_TableInit_Test_LoadDefaultTables(void) { - int32 Result; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; + LC_OperData.HaveActiveCDS = true; + + /* Only recover WDT */ + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 3, CFE_TBL_INFO_RECOVERED_TBL); + + /* Setup LC_CreateTaskCDS to succeed */ + UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); + UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); + LC_AppData.CDSSavedOnExit = LC_CDS_SAVED; + + /* Hit table info updated case for LC_LoadDefaultTables */ + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 4, CFE_TBL_INFO_UPDATED); + + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); + + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_UPDATED_INF_EID); + + /* Reset SendEvent and don't recover WDT */ + UT_ResetState(UT_KEY(CFE_EVS_SendEvent)); + LC_OperData.TableResults = 0; + + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); + + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_UPDATED_INF_EID); + + /* Reset all states and only restore WRT and ART CDS */ + UT_ResetState(0); + LC_OperData.TableResults = 0; + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_ES_CDS_ALREADY_EXISTS); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_ES_CDS_ALREADY_EXISTS); - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Error getting WDT address, RC=0x%%08X"); + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_UPDATED_INF_EID); + + /* Reset all states and only restore WRT */ + UT_ResetState(0); + LC_OperData.TableResults = 0; + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_ES_CDS_ALREADY_EXISTS); + + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); + + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_NEQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_UPDATED_INF_EID); +} + +void LC_TableInit_Test_GetWDTAddressError(void) +{ LC_OperData.HaveActiveCDS = true; + /* Recover all but the first two tables so LC_CreateResultTables will succeed */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), CFE_TBL_INFO_RECOVERED_TBL); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + /* Setup LC_CreateTaskCDS to succeed */ UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); @@ -568,38 +649,30 @@ void LC_TableInit_Test_GetWDTAddressError(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 3, -1); - Result = LC_TableInit(); + UtAssert_INT32_EQ(LC_TableInit(), -1); - UtAssert_True(Result == -1, "Result == -1"); - - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_CREATED) == LC_WRT_CDS_CREATED), - "LC_OperData.TableResult & LC_WRT_CDS_CREATED == LC_WRT_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_CREATED) == LC_ART_CDS_CREATED), - "LC_OperData.TableResult & LC_ART_CDS_CREATED == LC_ART_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_CREATED) == LC_APP_CDS_CREATED), - "LC_OperData.TableResult & LC_APP_CDS_CREATED == LC_APP_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_RESTORED) == LC_WRT_CDS_RESTORED), - "LC_OperData.TableResult & LC_WRT_CDS_RESTORED == LC_WRT_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_RESTORED) == LC_ART_CDS_RESTORED), - "LC_OperData.TableResult & LC_ART_CDS_RESTORED == LC_ART_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_RESTORED) == LC_APP_CDS_RESTORED), - "LC_OperData.TableResult & LC_APP_CDS_RESTORED == LC_APP_CDS_RESTORED"); + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)), 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_WDT_GETADDR_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 LC_TableInit_Test_GetWDTAddressUpdated(void) { - int32 Result; - LC_OperData.HaveActiveCDS = true; + /* Recover all but the first two tables so LC_CreateResultTables will succeed */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), CFE_TBL_INFO_RECOVERED_TBL); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + /* Setup LC_CreateTaskCDS to succeed */ UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); @@ -607,34 +680,28 @@ void LC_TableInit_Test_GetWDTAddressUpdated(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 3, CFE_TBL_INFO_UPDATED); - Result = LC_TableInit(); + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); - UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_CREATED) == LC_WRT_CDS_CREATED), - "LC_OperData.TableResult & LC_WRT_CDS_CREATED == LC_WRT_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_CREATED) == LC_ART_CDS_CREATED), - "LC_OperData.TableResult & LC_ART_CDS_CREATED == LC_ART_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_CREATED) == LC_APP_CDS_CREATED), - "LC_OperData.TableResult & LC_APP_CDS_CREATED == LC_APP_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_RESTORED) == LC_WRT_CDS_RESTORED), - "LC_OperData.TableResult & LC_WRT_CDS_RESTORED == LC_WRT_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_RESTORED) == LC_ART_CDS_RESTORED), - "LC_OperData.TableResult & LC_ART_CDS_RESTORED == LC_ART_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_RESTORED) == LC_APP_CDS_RESTORED), - "LC_OperData.TableResult & LC_APP_CDS_RESTORED == LC_APP_CDS_RESTORED"); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_RESTORED_INF_EID); } void LC_TableInit_Test_GetADTAddressError(void) { - int32 Result; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Error getting ADT address, RC=0x%%08X"); - LC_OperData.HaveActiveCDS = true; + /* Recover all but the first two tables so LC_CreateResultTables will succeed */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), CFE_TBL_INFO_RECOVERED_TBL); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + /* Setup LC_CreateTaskCDS to succeed */ UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); @@ -642,38 +709,30 @@ void LC_TableInit_Test_GetADTAddressError(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 4, -1); - Result = LC_TableInit(); + UtAssert_INT32_EQ(LC_TableInit(), -1); - UtAssert_True(Result == -1, "Result == -1"); - - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_CREATED) == LC_WRT_CDS_CREATED), - "LC_OperData.TableResult & LC_WRT_CDS_CREATED == LC_WRT_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_CREATED) == LC_ART_CDS_CREATED), - "LC_OperData.TableResult & LC_ART_CDS_CREATED == LC_ART_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_CREATED) == LC_APP_CDS_CREATED), - "LC_OperData.TableResult & LC_APP_CDS_CREATED == LC_APP_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_RESTORED) == LC_WRT_CDS_RESTORED), - "LC_OperData.TableResult & LC_WRT_CDS_RESTORED == LC_WRT_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_RESTORED) == LC_ART_CDS_RESTORED), - "LC_OperData.TableResult & LC_ART_CDS_RESTORED == LC_ART_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_RESTORED) == LC_APP_CDS_RESTORED), - "LC_OperData.TableResult & LC_APP_CDS_RESTORED == LC_APP_CDS_RESTORED"); + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)), 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_ADT_GETADDR_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 LC_TableInit_Test_GetADTAddressUpdated(void) { - int32 Result; - LC_OperData.HaveActiveCDS = true; + /* Recover all but the first two tables so LC_CreateResultTables will succeed */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), CFE_TBL_INFO_RECOVERED_TBL); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_SUCCESS); + /* Setup LC_CreateTaskCDS to succeed */ UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RegisterCDS), CFE_ES_CDS_ALREADY_EXISTS); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RestoreFromCDS), CFE_SUCCESS); @@ -681,22 +740,17 @@ void LC_TableInit_Test_GetADTAddressUpdated(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 4, CFE_TBL_INFO_UPDATED); - Result = LC_TableInit(); + UtAssert_INT32_EQ(LC_TableInit(), CFE_SUCCESS); - UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS"); + /* Ensure correct table state */ + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WRT_CDS_RESTORED, LC_WRT_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ART_CDS_RESTORED, LC_ART_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_APP_CDS_RESTORED, LC_APP_CDS_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_WDT_TBL_RESTORED, LC_WDT_TBL_RESTORED); + UtAssert_UINT32_EQ(LC_OperData.TableResults & LC_ADT_TBL_RESTORED, LC_ADT_TBL_RESTORED); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_CREATED) == LC_WRT_CDS_CREATED), - "LC_OperData.TableResult & LC_WRT_CDS_CREATED == LC_WRT_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_CREATED) == LC_ART_CDS_CREATED), - "LC_OperData.TableResult & LC_ART_CDS_CREATED == LC_ART_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_CREATED) == LC_APP_CDS_CREATED), - "LC_OperData.TableResult & LC_APP_CDS_CREATED == LC_APP_CDS_CREATED"); - UtAssert_True(((LC_OperData.TableResults & LC_WRT_CDS_RESTORED) == LC_WRT_CDS_RESTORED), - "LC_OperData.TableResult & LC_WRT_CDS_RESTORED == LC_WRT_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_ART_CDS_RESTORED) == LC_ART_CDS_RESTORED), - "LC_OperData.TableResult & LC_ART_CDS_RESTORED == LC_ART_CDS_RESTORED"); - UtAssert_True(((LC_OperData.TableResults & LC_APP_CDS_RESTORED) == LC_APP_CDS_RESTORED), - "LC_OperData.TableResult & LC_APP_CDS_RESTORED == LC_APP_CDS_RESTORED"); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_CDS_RESTORED_INF_EID); } void LC_TableInit_Test_CreateTaskCDSError(void) @@ -1017,8 +1071,6 @@ void LC_CreateDefinitionTables_Test_WDTCriticalADTNoncritical(void) void LC_CreateDefinitionTables_Test_WDTReRegisterError(void) { - int32 Result; - LC_OperData.TableResults = 0; LC_OperData.HaveActiveCDS = false; @@ -1029,26 +1081,19 @@ void LC_CreateDefinitionTables_Test_WDTReRegisterError(void) UT_SetHookFunction(UT_KEY(CFE_TBL_Register), &LC_APP_TEST_CFE_TBL_RegisterHook4, NULL); /* Execute the function being tested */ - Result = LC_CreateDefinitionTables(); + UtAssert_INT32_EQ(LC_CreateDefinitionTables(), -1); /* Verify results */ - UtAssert_True(Result == -1, "Result == -1"); UtAssert_True(LC_OperData.TableResults == (LC_WDT_CRITICAL_TBL | LC_WDT_TBL_RESTORED | LC_ADT_NOT_CRITICAL), "LC_OperData.TableResults == (LC_WDT_CRITICAL_TBL | LC_WDT_TBL_RESTORED | LC_ADT_NOT_CRITICAL)"); - /*UtAssert_True - (Ut_CFE_EVS_EventSent(LC_WDT_REREGISTER_ERR_EID, CFE_EVS_ERROR, "Error re-registering WDT, RC=0xFFFFFFFF"), - "Error re-registering WDT, RC=0xFFFFFFFF"); -*/ - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_WDT_REREGISTER_ERR_EID); } /* end LC_CreateDefinitionTables_Test_WDTReRegisterError */ void LC_CreateDefinitionTables_Test_WDTRegisterError(void) { - int32 Result; - LC_OperData.TableResults = 0; LC_OperData.HaveActiveCDS = false; @@ -1056,23 +1101,16 @@ void LC_CreateDefinitionTables_Test_WDTRegisterError(void) UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), -1); /* Execute the function being tested */ - Result = LC_CreateDefinitionTables(); + UtAssert_INT32_EQ(LC_CreateDefinitionTables(), -1); /* Verify results */ - UtAssert_True(Result == -1, "Result == -1"); - /* UtAssert_True - (Ut_CFE_EVS_EventSent(LC_WDT_REGISTER_ERR_EID, CFE_EVS_ERROR, "Error registering WDT, RC=0xFFFFFFFF"), - "Error registering WDT, RC=0xFFFFFFFF"); - */ - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_WDT_REGISTER_ERR_EID); } /* end LC_CreateDefinitionTables_Test_WDTRegisterError */ void LC_CreateDefinitionTables_Test_ADTRegisterError(void) { - int32 Result; - LC_OperData.TableResults = 0; LC_OperData.HaveActiveCDS = false; @@ -1080,16 +1118,10 @@ void LC_CreateDefinitionTables_Test_ADTRegisterError(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 2, -1); /* Execute the function being tested */ - Result = LC_CreateDefinitionTables(); + UtAssert_INT32_EQ(LC_CreateDefinitionTables(), -1); - /* Verify results */ - UtAssert_True(Result == -1, "Result == -1"); - /* UtAssert_True - (Ut_CFE_EVS_EventSent(LC_ADT_REGISTER_ERR_EID, CFE_EVS_ERROR, "Error registering ADT, RC=0xFFFFFFFF"), - "Error registering ADT, RC=0xFFFFFFFF"); - */ - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_ADT_REGISTER_ERR_EID); } /* end LC_CreateDefinitionTables_Test_ADTRegisterError */ @@ -1269,8 +1301,6 @@ void LC_LoadDefaultTables_Test_LoadADTError(void) void LC_LoadDefaultTables_Test_GetADTAddressError(void) { - int32 Result; - LC_OperData.HaveActiveCDS = false; /* Set to satisfy all instances of condition "Result == CFE_SUCCESS" after calls to CFE_TBL_Load */ @@ -1280,17 +1310,14 @@ void LC_LoadDefaultTables_Test_GetADTAddressError(void) UT_SetDeferredRetcode(UT_KEY(CFE_TBL_GetAddress), 2, -1); /* Execute the function being tested */ - Result = LC_LoadDefaultTables(); + UtAssert_INT32_EQ(LC_LoadDefaultTables(), -1); /* Verify results */ /*UtAssert_True (Ut_CFE_EVS_EventSent(LC_ADT_GETADDR_ERR_EID, CFE_EVS_ERROR, "Error getting ADT address, RC=0xCC000001"), "Error getting ADT address, RC=0xCC000001"); */ - UtAssert_INT32_EQ(Result, -1); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } /* end LC_LoadDefaultTables_Test_GetADTAddressError */ @@ -1548,8 +1575,8 @@ void UtTest_Setup(void) "LC_TableInit_Test_CreateDefinitionTablesError"); UtTest_Add(LC_TableInit_Test_Nominal, LC_Test_Setup, LC_Test_TearDown, "LC_TableInit_Test_Nominal"); - UtTest_Add(LC_TableInit_Test_LoadDefaultTablesError, LC_Test_Setup, LC_Test_TearDown, - "LC_TableInit_Test_LoadDefaultTablesError"); + UtTest_Add(LC_TableInit_Test_LoadDefaultTables, LC_Test_Setup, LC_Test_TearDown, + "LC_TableInit_Test_LoadDefaultTables"); UtTest_Add(LC_TableInit_Test_GetWDTAddressError, LC_Test_Setup, LC_Test_TearDown, "LC_TableInit_Test_GetWDTAddressError"); UtTest_Add(LC_TableInit_Test_GetWDTAddressUpdated, LC_Test_Setup, LC_Test_TearDown, diff --git a/unit-test/lc_watch_tests.c b/unit-test/lc_watch_tests.c index 1f57d94..b1df7af 100644 --- a/unit-test/lc_watch_tests.c +++ b/unit-test/lc_watch_tests.c @@ -47,109 +47,41 @@ uint8 call_count_CFE_EVS_SendEvent; -void LC_CreateHashTable_Test_UnsubscribeError(void) +void LC_CreateHashTable_Test(void) { - LC_OperData.MessageIDsCount = 1; - LC_OperData.MessageLinks[0].MessageID = LC_UT_MID_1; - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Error unsubscribing watchpoint: MID=0x%%08lX, RC=0x%%08X"); - - /* Set to generate error message LC_UNSUB_WP_ERR_EID */ - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_Unsubscribe), -1); + uint32 i; - /* Execute the function being tested */ - LC_CreateHashTable(); - - /* Verify results */ - UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)), 1); - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_UNSUB_WP_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); - -} /* end LC_CreateHashTable_Test_UnsubscribeError */ - -void LC_CreateHashTable_Test_NominalAllSameMID(void) -{ - int32 WatchPtTblIndex; - - LC_OperData.MessageIDsCount = 1; - LC_OperData.WatchpointCount = 1; - - for (WatchPtTblIndex = 0; WatchPtTblIndex < LC_MAX_WATCHPOINTS; WatchPtTblIndex++) - { - LC_OperData.WDTPtr[WatchPtTblIndex].DataType = 99; - LC_OperData.MessageLinks[WatchPtTblIndex].MessageID = LC_UT_MID_1; - } - - /* Execute the function being tested */ - LC_CreateHashTable(); - - /* Verify results */ - /* Nothing to verify for LC_OperData.WatchPtLinks, because it depends on LC_AddWatchpoint, which we're not testing - * here */ - - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0, "UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0"); - -} /* end LC_CreateHashTable_Test_NominalAllSameMID */ - -void LC_CreateHashTable_Test_WatchpointNotUsed(void) -{ - int32 WatchPtTblIndex; - - LC_OperData.MessageIDsCount = 1; - LC_OperData.WatchpointCount = 1; + /* One valid and one invalid unsubscribe */ + LC_OperData.MessageIDsCount = 2; + UT_SetDeferredRetcode(UT_KEY(CFE_SB_Unsubscribe), 1, -1); - for (WatchPtTblIndex = 0; WatchPtTblIndex < LC_MAX_WATCHPOINTS; WatchPtTblIndex++) + /* Default entries to unused */ + for (i = 0; i < LC_MAX_WATCHPOINTS; i++) { - LC_OperData.WDTPtr[WatchPtTblIndex].DataType = 99; - LC_OperData.MessageLinks[WatchPtTblIndex].MessageID = LC_UT_MID_1; + LC_OperData.WDTPtr[i].DataType = LC_WATCH_NOT_USED; } - LC_OperData.WDTPtr[0].DataType = LC_WATCH_NOT_USED; - - /* Execute the function being tested */ - LC_CreateHashTable(); - - /* Verify results */ - /* Nothing to verify for LC_OperData.WatchPtLinks, because it depends on LC_AddWatchpoint, which we're not testing - * here */ - - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0, "UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0"); - -} /* end LC_CreateHashTable_Test_NominalAllSameMID */ - -void LC_CreateHashTable_Test_NullLink(void) -{ - int32 WatchPtTblIndex; - - LC_OperData.MessageIDsCount = 1; - LC_OperData.WatchpointCount = 1; + /* Match MsgID but null watch point list */ + LC_OperData.WDTPtr[0].DataType = LC_DATA_BYTE; + LC_OperData.WDTPtr[0].MessageID = CFE_SB_INVALID_MSG_ID; - for (WatchPtTblIndex = 0; WatchPtTblIndex < LC_MAX_WATCHPOINTS; WatchPtTblIndex++) - { - LC_OperData.WDTPtr[WatchPtTblIndex].DataType = 99; - LC_OperData.MessageLinks[WatchPtTblIndex].MessageID = LC_UT_MID_1; - } + /* MsgID mismatch */ + LC_OperData.WDTPtr[1].DataType = LC_DATA_BYTE; + LC_OperData.WDTPtr[1].MessageID = LC_UT_MID_1; - LC_OperData.WDTPtr[0].MessageID = CFE_SB_INVALID_MSG_ID; - LC_OperData.MessageLinks[0].MessageID = CFE_SB_INVALID_MSG_ID; + /* Match MsgID and non-NULL WatchPLink */ + LC_OperData.WDTPtr[2].DataType = LC_DATA_BYTE; + LC_OperData.WDTPtr[2].MessageID = LC_UT_MID_1; /* Execute the function being tested */ LC_CreateHashTable(); - /* Verify results */ - /* Nothing to verify for LC_OperData.WatchPtLinks, because it depends on LC_AddWatchpoint, which we're not testing - * here */ - - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0, "UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)) == 0"); + UtAssert_UINT32_EQ(LC_OperData.WatchpointCount, 3); -} /* end LC_CreateHashTable_Test_NominalAllSameMID */ + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, LC_UNSUB_WP_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); +} void LC_AddWatchpoint_Test_HashTableAndWatchPtListNullPointersNominal(void) { @@ -2054,13 +1986,12 @@ void LC_ValidateWDT_Test_AllOperatorIDs(void) /* Add an entry for each data type */ LC_OperData.WDTPtr[0].OperatorID = LC_OPER_LT; - LC_OperData.WDTPtr[1].OperatorID = LC_OPER_LT; - LC_OperData.WDTPtr[2].OperatorID = LC_OPER_LE; - LC_OperData.WDTPtr[3].OperatorID = LC_OPER_NE; - LC_OperData.WDTPtr[4].OperatorID = LC_OPER_EQ; - LC_OperData.WDTPtr[5].OperatorID = LC_OPER_GE; - LC_OperData.WDTPtr[6].OperatorID = LC_OPER_GT; - LC_OperData.WDTPtr[7].OperatorID = LC_OPER_CUSTOM; + LC_OperData.WDTPtr[1].OperatorID = LC_OPER_LE; + LC_OperData.WDTPtr[2].OperatorID = LC_OPER_NE; + LC_OperData.WDTPtr[3].OperatorID = LC_OPER_EQ; + LC_OperData.WDTPtr[4].OperatorID = LC_OPER_GE; + LC_OperData.WDTPtr[5].OperatorID = LC_OPER_GT; + LC_OperData.WDTPtr[6].OperatorID = LC_OPER_CUSTOM; /* Execute the function being tested */ Result = LC_ValidateWDT(LC_OperData.WDTPtr); @@ -2472,13 +2403,7 @@ void LC_Uint32IsInfinite_Test_False2(void) void UtTest_Setup(void) { - UtTest_Add(LC_CreateHashTable_Test_UnsubscribeError, LC_Test_Setup, LC_Test_TearDown, - "LC_CreateHashTable_Test_UnsubscribeError"); - UtTest_Add(LC_CreateHashTable_Test_NominalAllSameMID, LC_Test_Setup, LC_Test_TearDown, - "LC_CreateHashTable_Test_NominalAllSameMID"); - UtTest_Add(LC_CreateHashTable_Test_WatchpointNotUsed, LC_Test_Setup, LC_Test_TearDown, - "LC_CreateHashTable_Test_WatchpointNotUsed"); - UtTest_Add(LC_CreateHashTable_Test_NullLink, LC_Test_Setup, LC_Test_TearDown, "LC_CreateHashTable_Test_NullLink"); + UtTest_Add(LC_CreateHashTable_Test, LC_Test_Setup, LC_Test_TearDown, "LC_CreateHashTable_Test"); UtTest_Add(LC_AddWatchpoint_Test_HashTableAndWatchPtListNullPointersNominal, LC_Test_Setup, LC_Test_TearDown, "LC_AddWatchpoint_Test_HashTableAndWatchPtListNullPointersNominal");