Skip to content

Commit

Permalink
migrated to ut_support
Browse files Browse the repository at this point in the history
  • Loading branch information
CDKnightNASA committed Apr 23, 2020
1 parent 39f9d3a commit dffc309
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 159 deletions.
172 changes: 19 additions & 153 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,134 +42,6 @@

static char cMsg[UT_MAX_MESSAGE_LENGTH];

int32 TestStat;

static inline void STARTBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start Block", TestName, FileName, LineNum);
UT_Text();
#endif /* VERBOSE */
}
#define STARTBLOCK() STARTBLOCK_impl(__FILE__, __LINE__, __func__)

static inline void START_impl(const char *FileName, int LineNum, const char *TestName)
{
TestStat = CFE_PASS;

#ifdef VERBOSE
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start", TestName, FileName, LineNum);
UT_Text();
#endif /* VERBOSE */
}
#define START() START_impl(__FILE__, __LINE__, __func__)

static inline void REPORT_impl(const char *FileName, int LineNum, const char *TestName)
{
UT_Report(FileName, LineNum, TestStat, TestName, "Report");
}
#define REPORT() REPORT_impl(__FILE__, __LINE__, __func__)

static inline bool SETUP_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet)
{
if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Setup failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define SETUP(FN) SETUP_impl(__FILE__, __LINE__, __func__, (#FN), (FN))

static inline bool ASSERT_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet)
{
if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define ASSERT(FN) ASSERT_impl(__FILE__, __LINE__, __func__, (#FN), (FN))

static inline bool ASSERT_EQ_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet, const char *ExpName, int32 Exp)
{
if(FnRet != Exp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s [%ld] != %s[%ld])",
TestName, FileName, LineNum, FnName, (long int)FnRet, ExpName, (long int)Exp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define ASSERT_EQ(FN,EXP) ASSERT_EQ_impl(__FILE__, __LINE__, __func__, (#FN), (FN), (#EXP), (EXP))

static inline bool EVTCNT_impl(const char *FileName, int LineNum, const char *TestName,
int32 CntExp)
{
int32 CntSent = UT_GetNumEventsSent();
if(CntSent != CntExp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event count (sent: %ld != expected: %ld)",
TestName, FileName, LineNum, (long int)CntSent, (long int)CntExp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define EVTCNT(EXP) EVTCNT_impl(__FILE__, __LINE__, __func__, (EXP))

static inline bool EVTSENT_impl(const char *FileName, int LineNum, const char *TestName,
const char *EvtName, int32 EvtId)
{
if(UT_EventIsInHistory(EvtId))
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event not sent (%s [%ld])",
TestName, FileName, LineNum, EvtName, (long int)EvtId);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define EVTSENT(EVT) EVTSENT_impl(__FILE__, __LINE__, __func__, (#EVT), (EVT))

static inline bool TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet)
{
if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Teardown failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}
#define TEARDOWN(FN) TEARDOWN_impl(__FILE__, __LINE__, __func__, (#FN), (FN))

static inline void ENDBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) End Block", TestName, FileName, LineNum);
UT_Text();
#endif /* VERBOSE */
}
#define ENDBLOCK() ENDBLOCK_impl(__FILE__, __LINE__, __func__)

/*
** Functions
*/
Expand Down Expand Up @@ -206,7 +78,7 @@ void UtTest_Setup(void)
*/
void Test_SB_Macros(void)
{
STARTBLOCK();
STARTBLOCK();

Test_SB_CCSDSPriHdr_Macros();
Test_SB_CCSDSSecHdr_Macros();
Expand Down Expand Up @@ -5456,30 +5328,24 @@ void Test_Unsubscribe_InvalParam(void)

/* Get the caller's Application ID */
ASSERT(CFE_ES_GetAppID(&CallerId));
if (TestStat == CFE_PASS)
{
/* Perform test using a bad scope value */
ASSERT_EQ(CFE_SB_UnsubscribeFull(0, TestPipe, CFE_SB_LOCAL + 1,
CallerId), CFE_SB_BAD_ARGUMENT);
}

if (TestStat == CFE_PASS)
{
/* Perform test using an invalid pipe ID for branch path coverage.
* This situation cannot happen in normal circumstances since the
* bad pipe ID is caught by CFE_SB_GetPipeIdx() before it gets to
* CFE_SB_ValidatePipeId()
*/
SavedPipeId = CFE_SB.PipeTbl[0].PipeId;
CFE_SB.PipeTbl[0].PipeId = CFE_PLATFORM_SB_MAX_PIPES;
CFE_SB.PipeTbl[0].InUse = 1;
ASSERT_EQ(CFE_SB_Unsubscribe(0, CFE_PLATFORM_SB_MAX_PIPES), CFE_SB_BAD_ARGUMENT);

/* We must restore the old value so CFE_SB_DeletePipe() works */
CFE_SB.PipeTbl[0].PipeId = SavedPipeId;

EVTCNT(4);
}

/* Perform test using a bad scope value */
ASSERT_EQ(CFE_SB_UnsubscribeFull(0, TestPipe, CFE_SB_LOCAL + 1, CallerId), CFE_SB_BAD_ARGUMENT);

/* Perform test using an invalid pipe ID for branch path coverage.
* This situation cannot happen in normal circumstances since the
* bad pipe ID is caught by CFE_SB_GetPipeIdx() before it gets to
* CFE_SB_ValidatePipeId()
*/
SavedPipeId = CFE_SB.PipeTbl[0].PipeId;
CFE_SB.PipeTbl[0].PipeId = CFE_PLATFORM_SB_MAX_PIPES;
CFE_SB.PipeTbl[0].InUse = 1;
ASSERT_EQ(CFE_SB_Unsubscribe(0, CFE_PLATFORM_SB_MAX_PIPES), CFE_SB_BAD_ARGUMENT);

/* We must restore the old value so CFE_SB_DeletePipe() works */
CFE_SB.PipeTbl[0].PipeId = SavedPipeId;

EVTCNT(4);

EVTSENT(CFE_SB_UNSUB_ARG_ERR_EID);

Expand Down
6 changes: 0 additions & 6 deletions fsw/cfe-core/unit-test/sb_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
#include "common_types.h"
#include "ut_support.h"

/*
** Macro definitions
*/
#define CFE_FAIL 0
#define CFE_PASS 1

/*
** Structures
*/
Expand Down
126 changes: 126 additions & 0 deletions fsw/cfe-core/unit-test/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,129 @@ uint32 UT_PrintfIsInHistory(const char *MsgToSearchFor)
return UT_GetMessageCount(MsgToSearchFor, &UT_PrintfBuffer, UT_StrCmpFormatStr);
}

int32 TestStat;

void UT_STARTBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
char cMsg[UT_MAX_MESSAGE_LENGTH];
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start Block", TestName, FileName, LineNum);
UT_Text(cMsg);
#endif /* VERBOSE */
}

void UT_START_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
char cMsg[UT_MAX_MESSAGE_LENGTH];
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Start", TestName, FileName, LineNum);
UT_Text(cMsg);
#endif /* VERBOSE */

TestStat = CFE_PASS;
}

void UT_REPORT_impl(const char *FileName, int LineNum, const char *TestName)
{
UT_Report(FileName, LineNum, TestStat, TestName, "Report");
}

bool UT_SETUP_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Setup failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_ASSERT_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_ASSERT_EQ_impl(const char *FileName, int LineNum, const char *TestName,
const char *FnName, int32 FnRet, const char *ExpName, int32 Exp)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != Exp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Assert failed (%s [%ld] != %s[%ld])",
TestName, FileName, LineNum, FnName, (long int)FnRet, ExpName, (long int)Exp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int32 CntExp)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

int32 CntSent = UT_GetNumEventsSent();
if(CntSent != CntExp)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event count (sent: %ld != expected: %ld)",
TestName, FileName, LineNum, (long int)CntSent, (long int)CntExp);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(!UT_EventIsInHistory(EvtId))
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Event not sent (%s [%ld])",
TestName, FileName, LineNum, EvtName, (long int)EvtId);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

bool UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
{
char cMsg[UT_MAX_MESSAGE_LENGTH];

if(FnRet != CFE_SUCCESS)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) Teardown failed (%s returned %ld)",
TestName, FileName, LineNum, FnName, (long int)FnRet);
UT_Text(cMsg);
TestStat = CFE_FAIL;
return false;
}
return true;
}

void UT_ENDBLOCK_impl(const char *FileName, int LineNum, const char *TestName)
{
#ifdef VERBOSE
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, "%s (%s:%d) End Block", TestName, FileName, LineNum);
UT_Text();
#endif /* VERBOSE */
}
Loading

0 comments on commit dffc309

Please sign in to comment.