Skip to content

Commit

Permalink
Partial nasa#596, scrub all UT_Report calls, ES module
Browse files Browse the repository at this point in the history
Scrub through all UT reporting calls in es_UT.c and replace
with preferred macro where possible.

- All calls to check status/return code are replaced with macro
  that logs all arguments and return value
- All calls that involved multiple conditions AND'ed together
  are replaced with individual asserts on each condition.
  • Loading branch information
jphickey committed Jun 16, 2021
1 parent a16c78e commit 204d2a9
Show file tree
Hide file tree
Showing 3 changed files with 666 additions and 1,156 deletions.
32 changes: 30 additions & 2 deletions modules/core_private/ut-stubs/inc/ut_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ bool UT_EventIsInHistory(uint16 EventIDToSearchFor);
******************************************************************************/
uint32 UT_SyslogIsInHistory(const char *LogMsgToSearchFor);

/**
* Macro to aid in checking if a printf message was generated during a test
*/
#define CFE_UtAssert_SyslogIsInHistory(str) \
UtAssert_True(UT_SyslogIsInHistory(str), "%s syslog generated (%s)", #str, str)

/*****************************************************************************/
/**
** \brief Search the printf history for a specified message template
Expand All @@ -522,6 +528,12 @@ uint32 UT_SyslogIsInHistory(const char *LogMsgToSearchFor);
******************************************************************************/
uint32 UT_PrintfIsInHistory(const char *MsgToSearchFor);

/**
* Macro to aid in checking if a printf message was generated during a test
*/
#define CFE_UtAssert_PrintfIsInHistory(str) \
UtAssert_True(UT_PrintfIsInHistory(str), "%s printf generated (%s)", #str, str)

/*****************************************************************************/
/**
** \brief Return number of events issued
Expand Down Expand Up @@ -700,7 +712,8 @@ void UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int
#define EVTCNT(EXP) (UT_EVTCNT_impl(__FILE__, __LINE__, __func__, (EXP)))

/** \brief Function to be called by the EVTSENT() macro */
void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId);
void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, bool invert, const char *EvtName,
int32 EvtId);

/*****************************************************************************/
/**
Expand All @@ -716,7 +729,8 @@ void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, co
** \sa #START, #SETUP, #ASSERT, #ASSERT_EQ, #ASSERT_TRUE, #EVTCNT, #REPORT, #TEARDOWN
**
******************************************************************************/
#define EVTSENT(EVT) (UT_EVTSENT_impl(__FILE__, __LINE__, __func__, (#EVT), (EVT)))
#define EVTSENT(EVT) (UT_EVTSENT_impl(__FILE__, __LINE__, __func__, false, (#EVT), (EVT)))
#define EVTNOTSENT(EVT) (UT_EVTSENT_impl(__FILE__, __LINE__, __func__, true, (#EVT), (EVT)))

/** \brief Function to be called by the TEARDOWN() macro */
void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet);
Expand All @@ -737,4 +751,18 @@ void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, c
******************************************************************************/
#define TEARDOWN(FN) (UT_TEARDOWN_impl(__FILE__, __LINE__, __func__, (#FN), (FN)))

/**
* \brief Macro for logging calls to a "void" function
*
* A macro that invokes a function with no return value. This should be used when
* no actual condition/result to check for/assert on, but the call should still be
* logged to the output to record the fact that the function was invoked.
*/
#define CFE_UtAssert_VOIDCALL(func) \
do \
{ \
func; \
UtAssert(true, #func, __FILE__, __LINE__); \
} while (0)

#endif /* UT_SUPPORT_H */
18 changes: 15 additions & 3 deletions modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,22 @@ void UT_EVTCNT_impl(const char *FileName, int LineNum, const char *TestName, int
TestName, (long int)CntSent, (long int)CntExp);
}

void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, const char *EvtName, int32 EvtId)
void UT_EVTSENT_impl(const char *FileName, int LineNum, const char *TestName, bool invert, const char *EvtName,
int32 EvtId)
{
UtAssertEx(UT_EventIsInHistory(EvtId), UtAssert_GetContext(), FileName, LineNum, "%s - sent event %s [%ld]",
TestName, EvtName, (long int)EvtId);
bool result = UT_EventIsInHistory(EvtId);
const char *text;
if (invert)
{
text = "did not send";
result = !result;
}
else
{
text = "sent";
}
UtAssertEx(result, UtAssert_GetContext(), FileName, LineNum, "%s - %s event %s [%ld]", text, TestName, EvtName,
(long int)EvtId);
}

void UT_TEARDOWN_impl(const char *FileName, int LineNum, const char *TestName, const char *FnName, int32 FnRet)
Expand Down
Loading

0 comments on commit 204d2a9

Please sign in to comment.