Skip to content

Commit

Permalink
Fix #1988, consolidate repeated MSG stub setup in sb_UT
Browse files Browse the repository at this point in the history
Utilize the common setup/wrapper functions in ut_support.c whenever
possible MSG dispatching in the generic handler.
  • Loading branch information
jphickey committed Oct 6, 2021
1 parent 98f78e8 commit 60297e7
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 361 deletions.
21 changes: 21 additions & 0 deletions modules/core_private/ut-stubs/inc/ut_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,27 @@ void UT_ResetCDS(void);
/* Reset pool buffer array index */
void UT_ResetPoolBufferIndex(void);

/*****************************************************************************/
/**
** \brief Sets up stubs to follow the intended path through a dispatch call
**
** \par Description
** Configures the MSG stubs appropriately so the intended command handler
** is called when invoking a "TaskPipe" handler function.
**
** DispatchReq should point to the intended MsgId + command code to set up.
**
** If DispatchReq is NULL, then any existing stub config is cleared/reset.
**
** If ExpectFailureEvent is set true, then it sets a second stub registration
** for both MsgId and FcnCode to account for failure event reporting
**
** \returns
** This function does not return a value.
******************************************************************************/
void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MSG_Size_t MsgSize,
bool ExpectFailureEvent);

/*****************************************************************************/
/**
** \brief Send a message via the software bus
Expand Down
54 changes: 43 additions & 11 deletions modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ void UT_ResetPoolBufferIndex(void)
UT_SetDataBuffer(UT_KEY(CFE_ES_GetPoolBuf), &UT_CFE_ES_MemoryPool, sizeof(UT_CFE_ES_MemoryPool), false);
}

/*
** Sets up the MSG stubs in preparation to invoke a "TaskPipe" dispatch function
**
** This is part of the general UT_CallTaskPipe process, but split off to support use cases
** where the task pipe is reached through other means.
*/
void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MSG_Size_t MsgSize,
bool ExpectFailureEvent)
{
if (DispatchReq != NULL)
{
/* Set up for the typical task pipe related calls */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), (void *)&DispatchReq->MsgId, sizeof(DispatchReq->MsgId), true);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), true);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), (void *)&DispatchReq->CommandCode,
sizeof(DispatchReq->CommandCode), true);

/* If a failure event is being set up, also set for MsgId/FcnCode retrieval as part of failure event reporting
*/
if (ExpectFailureEvent)
{
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), (void *)&DispatchReq->MsgId, sizeof(DispatchReq->MsgId), true);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), (void *)&DispatchReq->CommandCode,
sizeof(DispatchReq->CommandCode), true);
}
}
else
{
/* Clear any stub config that may have been already set */
UT_ResetState(UT_KEY(CFE_MSG_GetMsgId));
UT_ResetState(UT_KEY(CFE_MSG_GetSize));
UT_ResetState(UT_KEY(CFE_MSG_GetFcnCode));
}
}

/*
** Calls the specified "task pipe" function
**
Expand All @@ -215,22 +250,19 @@ void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_Buffer_t *), CFE_MSG_Message_t
/* Copy message into aligned SB buffer */
memcpy(SBBuf.Bytes, MsgPtr, MsgSize);

/* Set up for the typical task pipe related calls */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &DispatchId.MsgId, sizeof(DispatchId.MsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &DispatchId.CommandCode, sizeof(DispatchId.CommandCode), false);

/* If 0 size passed in, set buffers for calls in the command length failure reporting */
if (MsgSize == 0)
{
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &DispatchId.MsgId, sizeof(DispatchId.MsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &DispatchId.CommandCode, sizeof(DispatchId.CommandCode), false);
}
/* Passing MsgSize == 0 indicates intent to perform a size validation failure */
UT_SetupBasicMsgDispatch(&DispatchId, MsgSize, (MsgSize == 0));

/*
* Finally, call the actual task pipe requested.
*/
TaskPipeFunc(&SBBuf.Buf);

/*
* UN-set the stub config, as some values may point to values on stack.
* This removes any pointers to stack values that may not have been consumed during the call
*/
UT_SetupBasicMsgDispatch(NULL, 0, false);
}

int32 UT_SoftwareBusSnapshotHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
Expand Down
Loading

0 comments on commit 60297e7

Please sign in to comment.