Skip to content

Commit

Permalink
Fix nasa#17, Refactor redundant conditions to allow full code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jun 15, 2022
1 parent bb91036 commit 93405c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
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

0 comments on commit 93405c3

Please sign in to comment.