Skip to content

Commit

Permalink
Merge pull request nasa#37 from skliper/fix22-code_coverage
Browse files Browse the repository at this point in the history
Fix nasa#17 nasa#22, Code coverage improvements
  • Loading branch information
astrogeco authored Jun 22, 2022
2 parents 67bf038 + 426dde9 commit 7049399
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 323 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/unit-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 16 additions & 25 deletions fsw/src/lc_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -383,31 +374,31 @@ 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;

case LC_RPN_NOT:
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;

Expand All @@ -417,7 +408,7 @@ uint8 LC_EvaluateRPN(uint16 APNumber)
{
IllegalOperand = true;
}
if (StackPtr == 0)
else if (StackPtr == 0)
{
Done = true;
}
Expand All @@ -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
{
Expand Down
15 changes: 7 additions & 8 deletions fsw/src/lc_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,21 +976,20 @@ 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
*/
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
Expand Down
144 changes: 122 additions & 22 deletions unit-test/lc_action_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Loading

0 comments on commit 7049399

Please sign in to comment.