Skip to content

Commit 9568c88

Browse files
committed
Fix #1626, rename/clean CFE coverage assert macros
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.
1 parent da76015 commit 9568c88

File tree

18 files changed

+1661
-1372
lines changed

18 files changed

+1661
-1372
lines changed

modules/core_private/ut-stubs/inc/ut_support.h

Lines changed: 236 additions & 46 deletions
Large diffs are not rendered by default.

modules/core_private/ut-stubs/src/ut_support.c

Lines changed: 117 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -694,46 +694,135 @@ void UT_AddSubTest(void (*Test)(void), void (*Setup)(void), void (*Teardown)(voi
694694
UtTest_Add(Test, Setup, Teardown, strdup(CompleteTestName));
695695
}
696696

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

703-
void UT_ASSERT_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
704-
{
705-
UtAssertEx(FnRet == CFE_SUCCESS, UtAssert_GetContext(), FileName, LineNum,
706-
"%s - %s returned 0x%lx, expected CFE_SUCCESS", TestName, FnName, (long int)FnRet);
707-
}
701+
switch (CompareType)
702+
{
703+
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
704+
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
705+
OpText = "==";
706+
break;
707+
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
708+
OpText = "!=";
709+
break;
710+
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
711+
OpText = "<";
712+
break;
713+
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
714+
OpText = ">";
715+
break;
716+
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
717+
OpText = "<=";
718+
break;
719+
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
720+
OpText = ">=";
721+
break;
722+
default: /* should never happen */
723+
OpText = "??";
724+
break;
725+
}
708726

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

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

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

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

729-
void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
743+
bool CFE_UtAssert_GenericUnsignedCompare_Impl(uint32 ActualValue, CFE_UtAssert_Compare_t CompareType,
744+
uint32 ReferenceValue, const char *File, uint32 Line, const char *Desc,
745+
const char *ActualText, const char *ReferenceText)
730746
{
731-
UtAssertEx(UT_EventIsInHistory(EvtId), UtAssert_GetContext(), FileName, LineNum, "%s - sent event %s [%ld]",
732-
TestName, EvtName, (long int)EvtId);
747+
bool Result;
748+
749+
switch (CompareType)
750+
{
751+
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
752+
Result = (ActualValue == ReferenceValue);
753+
break;
754+
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
755+
Result = (ActualValue != ReferenceValue);
756+
break;
757+
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
758+
Result = (ActualValue < ReferenceValue);
759+
break;
760+
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
761+
Result = (ActualValue > ReferenceValue);
762+
break;
763+
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
764+
Result = (ActualValue <= ReferenceValue);
765+
break;
766+
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
767+
Result = (ActualValue >= ReferenceValue);
768+
break;
769+
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
770+
Result = ActualValue;
771+
if (!ReferenceValue)
772+
{
773+
/* Invert the result if reference is false */
774+
Result = !Result;
775+
}
776+
break;
777+
default: /* should never happen */
778+
Result = false;
779+
break;
780+
}
781+
782+
return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, "%s%s (0x%lx) %s %s (0x%lx)", Desc, ActualText,
783+
(unsigned long)ActualValue, CFE_UtAssert_GetOpText(CompareType), ReferenceText,
784+
(unsigned long)ReferenceValue);
733785
}
734786

735-
void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
787+
bool CFE_UtAssert_GenericSignedCompare_Impl(int32 ActualValue, CFE_UtAssert_Compare_t CompareType, int32 ReferenceValue,
788+
const char *File, uint32 Line, const char *Desc, const char *ActualText,
789+
const char *ReferenceText)
736790
{
737-
UtAssertEx(FnRet == CFE_SUCCESS, UTASSERT_CASETYPE_TTF, FileName, LineNum,
738-
"%s - Teardown failed (%s returned 0x%lx)", TestName, FnName, (long int)FnRet);
791+
bool Result;
792+
793+
switch (CompareType)
794+
{
795+
case CFE_UtAssert_Compare_EQ: /* actual equals reference value */
796+
Result = (ActualValue == ReferenceValue);
797+
break;
798+
case CFE_UtAssert_Compare_NEQ: /* actual does not non equal reference value */
799+
Result = (ActualValue != ReferenceValue);
800+
break;
801+
case CFE_UtAssert_Compare_LT: /* actual less than reference (exclusive) */
802+
Result = (ActualValue < ReferenceValue);
803+
break;
804+
case CFE_UtAssert_Compare_GT: /* actual greater than reference (exclusive) */
805+
Result = (ActualValue > ReferenceValue);
806+
break;
807+
case CFE_UtAssert_Compare_LTEQ: /* actual less than or equal to reference (inclusive) */
808+
Result = (ActualValue <= ReferenceValue);
809+
break;
810+
case CFE_UtAssert_Compare_GTEQ: /* actual greater than reference (inclusive) */
811+
Result = (ActualValue >= ReferenceValue);
812+
break;
813+
case CFE_UtAssert_Compare_BOOL: /* actual and reference are logical boolean values */
814+
Result = ActualValue;
815+
if (!ReferenceValue)
816+
{
817+
/* Invert the result if reference is false */
818+
Result = !Result;
819+
}
820+
break;
821+
default: /* should never happen */
822+
Result = false;
823+
break;
824+
}
825+
826+
return UtAssertEx(Result, UTASSERT_CASETYPE_FAILURE, File, Line, "%s%s (%ld) %s %s (%ld)", Desc, ActualText,
827+
(long)ActualValue, CFE_UtAssert_GetOpText(CompareType), ReferenceText, (long)ReferenceValue);
739828
}

modules/es/ut-coverage/es_UT.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ void TestStartupErrorPaths(void)
10301030
/* This prep is necessary so GetAppId works */
10311031
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppType_CORE, NULL, &AppRecPtr, NULL);
10321032
CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY;
1033-
ASSERT(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 0));
1033+
CFE_UtAssert_SUCCESS(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 0));
10341034
}
10351035

10361036
void TestApps(void)

modules/evs/ut-coverage/evs_UT.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ void Test_Init(void)
245245
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false);
246246

247247
UT_EVS_DoGenericCheckEvents(CFE_EVS_TaskMain, &UT_EVS_EventBuf);
248-
ASSERT_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]));
249-
ASSERT_EQ(UT_EVS_EventBuf.EventID, CFE_EVS_ERR_MSGID_EID);
248+
CFE_UtAssert_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]));
249+
CFE_UtAssert_EQUAL(UT_EVS_EventBuf.EventID, CFE_EVS_ERR_MSGID_EID);
250250

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

718718
/* Note implementation initializes both short and long message */
719-
ASSERT_EQ(UT_GetStubCount(UT_KEY(CFE_MSG_Init)), 2);
720-
ASSERT_EQ(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)), 1);
721-
ASSERT_TRUE(CFE_SB_MsgId_Equal(MsgData.MsgId, ShortFmtSnapshotData.MsgId));
722-
ASSERT_TRUE(!CFE_SB_MsgId_Equal(MsgData.MsgId, LongFmtSnapshotData.MsgId));
719+
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_MSG_Init)), 2);
720+
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)), 1);
721+
CFE_UtAssert_TRUE(CFE_SB_MsgId_Equal(MsgData.MsgId, ShortFmtSnapshotData.MsgId));
722+
CFE_UtAssert_TRUE(!CFE_SB_MsgId_Equal(MsgData.MsgId, LongFmtSnapshotData.MsgId));
723723

724724
/* Confirm the right message was sent */
725-
ASSERT_TRUE(MsgSend == MsgData.MsgPtr);
725+
CFE_UtAssert_TRUE(MsgSend == MsgData.MsgPtr);
726726

727727
/* Test set event format mode command using a valid command to set long
728728
* format, reports implicitly via event

0 commit comments

Comments
 (0)