Skip to content

Commit

Permalink
Fix #1626, rename/clean CFE coverage assert macros
Browse files Browse the repository at this point in the history
Rename CFE coverage test assert macros in ut_support.h to have
consistent name prefix.

Adds implementation functions for completely generic signed/unsigned
comparison asserts, and wrapper macros to invoke those functions.
These functions return the pass/fail status of the assert as a bool
value, so the test case can act on the result.

Also adds a "VOIDCALL" and "RESOURCEID_EQ" macro for logging void
functions and ID checks, respectively.
  • Loading branch information
jphickey committed Jun 21, 2021
1 parent da76015 commit 9568c88
Show file tree
Hide file tree
Showing 18 changed files with 1,661 additions and 1,372 deletions.
282 changes: 236 additions & 46 deletions modules/core_private/ut-stubs/inc/ut_support.h

Large diffs are not rendered by default.

145 changes: 117 additions & 28 deletions modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,46 +694,135 @@ void UT_AddSubTest(void (*Test)(void), void (*Setup)(void), void (*Teardown)(voi
UtTest_Add(Test, Setup, Teardown, strdup(CompleteTestName));
}

void UT_SETUP_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
const char *CFE_UtAssert_GetOpText(CFE_UtAssert_Compare_t CompareType)
{
UtAssertEx(FnRet == CFE_SUCCESS, UTASSERT_CASETYPE_TSF, FileName, LineNum, "%s - Setup - %s returned 0x%lx",
TestName, FnName, (long int)FnRet);
}
const char *OpText;

void UT_ASSERT_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
UtAssertEx(FnRet == CFE_SUCCESS, UtAssert_GetContext(), FileName, LineNum,
"%s - %s returned 0x%lx, expected CFE_SUCCESS", TestName, FnName, (long int)FnRet);
}
switch (CompareType)
{
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
OpText = "==";
break;
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
OpText = "!=";
break;
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
OpText = "<";
break;
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
OpText = ">";
break;
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
OpText = "<=";
break;
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
OpText = ">=";
break;
default: /* should never happen */
OpText = "??";
break;
}

void UT_ASSERT_EQ_impl(const char *FileName, int LineNum, const char *FnName, int32 FnRet, const char *ExpName,
int32 Exp)
{
UtAssertEx(FnRet == Exp, UtAssert_GetContext(), FileName, LineNum, "%s - value %ld 0x%lx, expected %s[%ld 0x%lx]",
FnName, (long)FnRet, (long)FnRet, ExpName, (long)Exp, (long)Exp);
return OpText;
}

void UT_ASSERT_TRUE_impl(const char *FileName, int LineNum, const char *TestName, const char *ExpName, bool Exp)
bool CFE_UtAssert_SuccessCheck_Impl(CFE_Status_t Status, UtAssert_CaseType_t CaseType, const char *File, uint32 Line,
const char *Text)
{
UtAssertEx(Exp, UtAssert_GetContext(), FileName, LineNum, "%s - %s", TestName, ExpName);
}
bool Result = (Status >= CFE_SUCCESS);

void UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int32 CntExp)
{
int32 CntSent = UT_GetNumEventsSent();
if (!Result || (CaseType != UTASSERT_CASETYPE_TSF && CaseType != UTASSERT_CASETYPE_TTF))
{
UtAssertEx(Result, CaseType, File, Line, "%s (0x%lx) == CFE_SUCCESS", Text, (unsigned long)Status);
}

UtAssertEx(CntSent == CntExp, UtAssert_GetContext(), FileName, LineNum, "%s - event count (sent %ld, expected %ld)",
TestName, (long int)CntSent, (long int)CntExp);
return Result;
}

void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
bool CFE_UtAssert_GenericUnsignedCompare_Impl(uint32 ActualValue, CFE_UtAssert_Compare_t CompareType,
uint32 ReferenceValue, const char *File, uint32 Line, const char *Desc,
const char *ActualText, const char *ReferenceText)
{
UtAssertEx(UT_EventIsInHistory(EvtId), UtAssert_GetContext(), FileName, LineNum, "%s - sent event %s [%ld]",
TestName, EvtName, (long int)EvtId);
bool Result;

switch (CompareType)
{
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
Result = (ActualValue == ReferenceValue);
break;
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
Result = (ActualValue != ReferenceValue);
break;
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
Result = (ActualValue < ReferenceValue);
break;
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
Result = (ActualValue > ReferenceValue);
break;
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
Result = (ActualValue <= ReferenceValue);
break;
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
Result = (ActualValue >= ReferenceValue);
break;
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
Result = ActualValue;
if (!ReferenceValue)
{
/* Invert the result if reference is false */
Result = !Result;
}
break;
default: /* should never happen */
Result = false;
break;
}

return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, "%s%s (0x%lx) %s %s (0x%lx)", Desc, ActualText,
(unsigned long)ActualValue, CFE_UtAssert_GetOpText(CompareType), ReferenceText,
(unsigned long)ReferenceValue);
}

void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
bool CFE_UtAssert_GenericSignedCompare_Impl(int32 ActualValue, CFE_UtAssert_Compare_t CompareType, int32 ReferenceValue,
const char *File, uint32 Line, const char *Desc, const char *ActualText,
const char *ReferenceText)
{
UtAssertEx(FnRet == CFE_SUCCESS, UTASSERT_CASETYPE_TTF, FileName, LineNum,
"%s - Teardown failed (%s returned 0x%lx)", TestName, FnName, (long int)FnRet);
bool Result;

switch (CompareType)
{
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
Result = (ActualValue == ReferenceValue);
break;
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
Result = (ActualValue != ReferenceValue);
break;
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
Result = (ActualValue < ReferenceValue);
break;
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
Result = (ActualValue > ReferenceValue);
break;
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
Result = (ActualValue <= ReferenceValue);
break;
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
Result = (ActualValue >= ReferenceValue);
break;
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
Result = ActualValue;
if (!ReferenceValue)
{
/* Invert the result if reference is false */
Result = !Result;
}
break;
default: /* should never happen */
Result = false;
break;
}

return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, "%s%s (%ld) %s %s (%ld)", Desc, ActualText,
(long)ActualValue, CFE_UtAssert_GetOpText(CompareType), ReferenceText, (long)ReferenceValue);
}
2 changes: 1 addition & 1 deletion modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ void TestStartupErrorPaths(void)
/* This prep is necessary so GetAppId works */
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppType_CORE, NULL, &AppRecPtr, NULL);
CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY;
ASSERT(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 0));
CFE_UtAssert_SUCCESS(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 0));
}

void TestApps(void)
Expand Down
14 changes: 7 additions & 7 deletions modules/evs/ut-coverage/evs_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ void Test_Init(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false);

UT_EVS_DoGenericCheckEvents(CFE_EVS_TaskMain, &UT_EVS_EventBuf);
ASSERT_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]));
ASSERT_EQ(UT_EVS_EventBuf.EventID, CFE_EVS_ERR_MSGID_EID);
CFE_UtAssert_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]));
CFE_UtAssert_EQUAL(UT_EVS_EventBuf.EventID, CFE_EVS_ERR_MSGID_EID);

/* Test early initialization with a get reset area failure */
UT_InitData();
Expand Down Expand Up @@ -716,13 +716,13 @@ void Test_Format(void)
CFE_EVS_SendEvent(0, CFE_EVS_EventType_INFORMATION, "Short format check 1");

/* Note implementation initializes both short and long message */
ASSERT_EQ(UT_GetStubCount(UT_KEY(CFE_MSG_Init)), 2);
ASSERT_EQ(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)), 1);
ASSERT_TRUE(CFE_SB_MsgId_Equal(MsgData.MsgId, ShortFmtSnapshotData.MsgId));
ASSERT_TRUE(!CFE_SB_MsgId_Equal(MsgData.MsgId, LongFmtSnapshotData.MsgId));
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_MSG_Init)), 2);
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)), 1);
CFE_UtAssert_TRUE(CFE_SB_MsgId_Equal(MsgData.MsgId, ShortFmtSnapshotData.MsgId));
CFE_UtAssert_TRUE(!CFE_SB_MsgId_Equal(MsgData.MsgId, LongFmtSnapshotData.MsgId));

/* Confirm the right message was sent */
ASSERT_TRUE(MsgSend == MsgData.MsgPtr);
CFE_UtAssert_TRUE(MsgSend == MsgData.MsgPtr);

/* Test set event format mode command using a valid command to set long
* format, reports implicitly via event
Expand Down
Loading

0 comments on commit 9568c88

Please sign in to comment.