Skip to content

Commit

Permalink
Fix nasa#777, Use MSG APIs - Unit tests
Browse files Browse the repository at this point in the history
Updates the unit tests, unit test support, and
stubs to replace deprecated SB APIs with MSG APIs.
  • Loading branch information
skliper committed Nov 4, 2020
1 parent 6b453be commit 8514efa
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 1,427 deletions.
8 changes: 6 additions & 2 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2631,7 +2631,7 @@ void TestTask(void)
osal_id_t UT_ContextTask;
union
{
CFE_SB_Msg_t Msg;
CFE_MSG_Message_t Msg;
CFE_ES_NoArgsCmd_t NoArgsCmd;
CFE_ES_Restart_t RestartCmd;
CFE_ES_StartApp_t StartAppCmd;
Expand All @@ -2653,6 +2653,7 @@ void TestTask(void)
CFE_ES_TaskRecord_t *UtTaskRecPtr;
CFE_ES_CDS_RegRec_t *UtCDSRegRecPtr;
CFE_ES_MemPoolRecord_t *UtPoolRecPtr;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

UtPrintf("Begin Test Task");

Expand All @@ -2668,6 +2669,9 @@ void TestTask(void)
ES_ResetUnitTest();
/* this is needed so CFE_ES_GetAppId works */
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL);

/* Set up buffer for first cycle, pipe failure is on 2nd */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
CFE_ES_TaskMain();
UT_Report(__FILE__, __LINE__,
UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_COMMAND_PIPE]),
Expand Down Expand Up @@ -3968,7 +3972,7 @@ void TestPerf(void)
{
union
{
CFE_SB_Msg_t Msg;
CFE_MSG_Message_t Msg;
CFE_ES_StartPerfData_t PerfStartCmd;
CFE_ES_StopPerfData_t PerfStopCmd;
CFE_ES_SetPerfFilterMask_t PerfSetFilterMaskCmd;
Expand Down
70 changes: 43 additions & 27 deletions fsw/cfe-core/unit-test/evs_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ typedef struct

static UT_EVS_EventCapture_t UT_EVS_EventBuf;

/* MSG Init hook data */
typedef struct
{
CFE_MSG_Message_t *MsgPtr;
CFE_SB_MsgId_t MsgId;
CFE_MSG_Size_t Size;
} UT_EVS_MSGInitData_t;

/* Message init hook to stora last MsgId passed in */
static int32 UT_EVS_MSGInitHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
{
UT_EVS_MSGInitData_t *msgdataptr = UserObj;

msgdataptr->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *);
msgdataptr->MsgId = UT_Hook_GetArgValueByName(Context, "MsgId", CFE_SB_MsgId_t);
msgdataptr->Size = UT_Hook_GetArgValueByName(Context, "Size", CFE_MSG_Size_t);

return StubRetcode;
}

static void UT_EVS_DoDispatchCheckEvents_Impl(void *MsgPtr, uint32 MsgSize,
UT_TaskPipeDispatchId_t DispatchId, const UT_SoftwareBusSnapshot_Entry_t *SnapshotCfg,
UT_EVS_EventCapture_t *EventCapture)
Expand All @@ -212,7 +232,7 @@ static void UT_EVS_DoDispatchCheckEvents_Impl(void *MsgPtr, uint32 MsgSize,
SnapshotData.SnapshotBuffer = &EventCapture->EventID;

UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &SnapshotData);
UT_CallTaskPipe(CFE_EVS_ProcessCommandPacket, (CFE_SB_MsgPtr_t)MsgPtr, MsgSize, DispatchId);
UT_CallTaskPipe(CFE_EVS_ProcessCommandPacket, (CFE_MSG_Message_t *)MsgPtr, MsgSize, DispatchId);
EventCapture->Count += SnapshotData.Count;

/* be sure to clear the hook function since the SnapshotData is going out of scope */
Expand Down Expand Up @@ -279,6 +299,7 @@ void Test_Init(void)
{
CFE_EVS_BitMaskCmd_t bitmaskcmd;
CFE_EVS_AppNameBitMaskCmd_t appbitcmd;
CFE_SB_MsgId_t msgid = CFE_SB_INVALID_MSG_ID;

UtPrintf("Begin Test Init");

Expand All @@ -299,14 +320,15 @@ void Test_Init(void)
/* Test TaskMain with a command pipe read failure due to an
* invalid command packet
*/
UtPrintf("CFE_EVS_TaskMain - Test error reading command pipe, unrecognized msgid");
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetMsgId), 1, 0);

/* Set unexpected message ID */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false);

UT_EVS_DoGenericCheckEvents(CFE_EVS_TaskMain, &UT_EVS_EventBuf);
UT_Report(__FILE__, __LINE__,
UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]) &&
UT_EVS_EventBuf.EventID == CFE_EVS_ERR_MSGID_EID,
"CFE_EVS_TaskMain",
"Error reading command pipe");
ASSERT_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8]));
ASSERT_EQ(UT_EVS_EventBuf.EventID, CFE_EVS_ERR_MSGID_EID);

/* Test TaskMain with a register application failure */
UT_InitData();
Expand Down Expand Up @@ -907,6 +929,8 @@ void Test_Format(void)
};
EVS_AppData_t *AppDataPtr;
CFE_ES_ResourceID_t AppID;
UT_EVS_MSGInitData_t MsgData;
CFE_MSG_Message_t *MsgSend;

/* Get a local ref to the "current" AppData table entry */
EVS_GetCurrentContext(&AppDataPtr, &AppID);
Expand Down Expand Up @@ -954,24 +978,20 @@ void Test_Format(void)
"CFE_EVS_SetEventFormatModeCmd",
"Set event format mode command: short format");

/* Test event short format mode command was successful */
/*
* Send a test event and verify that the Long format event was NOT generated.
*/
UtPrintf("Test for short event sent when configured to do so ");
UT_InitData();
UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &ShortFmtSnapshotData);
UT_SetHookFunction(UT_KEY(CFE_MSG_Init), UT_EVS_MSGInitHook, &MsgData);
UT_SetDataBuffer(UT_KEY(CFE_SB_SendMsg), &MsgSend, sizeof(MsgSend), false);
CFE_EVS_SendEvent(0, CFE_EVS_EventType_INFORMATION, "Short format check 1");
UT_Report(__FILE__, __LINE__,
ShortFmtSnapshotData.Count == 1,
"CFE_EVS_SetEventFormatModeCmd",
"Short event format mode verification - short message sent");

UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &LongFmtSnapshotData);
CFE_EVS_SendEvent(0, CFE_EVS_EventType_INFORMATION, "Short format check 2");
UT_Report(__FILE__, __LINE__,
LongFmtSnapshotData.Count == 0,
"CFE_EVS_SetEventFormatModeCmd",
"Short event format mode verification - long message not sent");
/* 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_SendMsg)), 1);
ASSERT_TRUE(CFE_SB_MsgId_Equal(MsgData.MsgId, ShortFmtSnapshotData.MsgId));
ASSERT_TRUE(!CFE_SB_MsgId_Equal(MsgData.MsgId, LongFmtSnapshotData.MsgId));

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

/* Test set event format mode command using a valid command to set long
* format, reports implicitly via event
Expand Down Expand Up @@ -2644,7 +2664,7 @@ void Test_Misc(void)
{
union
{
CFE_SB_Msg_t msg;
CFE_MSG_Message_t msg;
CFE_EVS_NoArgsCmd_t cmd;
CFE_EVS_SetLogMode_t modecmd;
CFE_EVS_WriteLogDataFile_t writelogdatacmd;
Expand Down Expand Up @@ -2689,8 +2709,6 @@ void Test_Misc(void)

/* Test housekeeping report with log enabled */
UT_InitData();
CFE_SB_InitMsg((CFE_SB_Msg_t *) &CFE_EVS_GlobalData.EVS_TlmPkt, HK_SnapshotData.MsgId,
sizeof(CFE_EVS_GlobalData.EVS_TlmPkt), false);
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled = true;
HK_SnapshotData.Count = 0;
UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &HK_SnapshotData);
Expand All @@ -2717,8 +2735,6 @@ void Test_Misc(void)

/* Test housekeeping report with log disabled */
UT_InitData();
CFE_SB_InitMsg((CFE_SB_Msg_t *) &CFE_EVS_GlobalData.EVS_TlmPkt, HK_SnapshotData.MsgId,
sizeof(CFE_EVS_GlobalData.EVS_TlmPkt), false);
CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled = false;
HK_SnapshotData.Count = 0;
UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &HK_SnapshotData);
Expand Down
Loading

0 comments on commit 8514efa

Please sign in to comment.