Skip to content

Commit

Permalink
Fix nasa#1905, Improve SB coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Aug 30, 2021
1 parent 5e41330 commit 213b35d
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion modules/sb/ut-coverage/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,9 @@ void Test_Subscribe_MaxMsgIdCount(void)
CFE_UtAssert_SETUP(CFE_SB_CreatePipe(&PipeId1, PipeDepth, "TestPipe1"));
CFE_UtAssert_SETUP(CFE_SB_CreatePipe(&PipeId2, PipeDepth, "TestPipe2"));

/* For code coverage set PeakMsgIdsInUse so it won't always increment */
CFE_SB_Global.StatTlmMsg.Payload.PeakMsgIdsInUse = 1;

for (i = 0; i < CFE_PLATFORM_SB_MAX_MSG_IDS + 1; i++)
{
if (i < CFE_PLATFORM_SB_MAX_MSG_IDS)
Expand Down Expand Up @@ -3317,9 +3320,18 @@ void Test_TransmitMsg_GetPoolBufErr(void)
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(&TlmPkt.Hdr.Msg, true), CFE_SB_BUF_ALOC_ERR);

CFE_UtAssert_EVENTCOUNT(3);

CFE_UtAssert_EVENTSENT(CFE_SB_GET_BUF_ERR_EID);

/* Repeat buf descriptor allocation failed with event denied */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_MEM_BLOCK_SIZE);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_TaskID_ToIndex), 1, -1);
UtAssert_INT32_EQ(CFE_SB_TransmitMsg(&TlmPkt.Hdr.Msg, true), CFE_SB_BUF_ALOC_ERR);

/* Confirm no additional events sent */
CFE_UtAssert_EVENTCOUNT(3);

CFE_UtAssert_TEARDOWN(CFE_SB_DeletePipe(PipeId));

} /* end Test_TransmitMsg_GetPoolBufErr */
Expand Down Expand Up @@ -3710,6 +3722,26 @@ static void SB_UT_PipeIdModifyHandler(void *UserObj, UT_EntryKey_t FuncKey, cons
PipeDscPtr->PipeId = CFE_SB_INVALID_PIPE;
}

/* Special handler to hit OS_QueueGet error casses */
static void SB_UT_QueueGetHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
size_t **data = (size_t **)UT_Hook_GetArgValueByName(Context, "data", void *);
size_t *size_copied = UT_Hook_GetArgValueByName(Context, "size_copied", size_t *);
int32 status = OS_SUCCESS;

*data = UserObj;

if (*data == NULL)
{
*size_copied = sizeof(CFE_SB_BufferD_t *);
}
else
{
*size_copied = *((size_t *)UserObj);
}
UT_Stub_SetReturnValue(FuncKey, status);
}

/*
** Test receiving a message from the software bus with an invalid pipe ID
*/
Expand Down Expand Up @@ -3825,6 +3857,7 @@ void Test_ReceiveBuffer_PipeReadError(void)
CFE_SB_Buffer_t *SBBufPtr;
CFE_SB_PipeId_t PipeId;
uint32 PipeDepth = 10;
size_t Data = 1;

CFE_UtAssert_SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "RcvTestPipe"));
UT_SetDeferredRetcode(UT_KEY(OS_QueueGet), 1, OS_ERROR);
Expand All @@ -3834,6 +3867,13 @@ void Test_ReceiveBuffer_PipeReadError(void)

CFE_UtAssert_EVENTSENT(CFE_SB_Q_RD_ERR_EID);

/* Set handler to exercise error conditions for OS_QueueGet */
UT_SetHandlerFunction(UT_KEY(OS_QueueGet), SB_UT_QueueGetHandler, &Data);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&SBBufPtr, PipeId, CFE_SB_PEND_FOREVER), CFE_SB_PIPE_RD_ERR);
UT_SetHandlerFunction(UT_KEY(OS_QueueGet), SB_UT_QueueGetHandler, NULL);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&SBBufPtr, PipeId, CFE_SB_PEND_FOREVER), CFE_SB_PIPE_RD_ERR);
UT_SetHandlerFunction(UT_KEY(OS_QueueGet), NULL, NULL);

CFE_UtAssert_TEARDOWN(CFE_SB_DeletePipe(PipeId));

} /* end Test_ReceiveBuffer_PipeReadError */
Expand Down Expand Up @@ -4568,6 +4608,8 @@ void Test_SB_TransmitMsgPaths_IgnoreOpt(void)
int32 PipeDepth = 2;
CFE_MSG_Type_t Type = CFE_MSG_Type_Tlm;
CFE_MSG_Size_t Size = sizeof(TlmPkt);
CFE_SB_PipeD_t *PipeDscPtr;
CFE_ES_AppId_t AppId;

/* Setup Test skipping sending to a pipe when the pipe option is set to ignore */
MsgId = SB_UT_TLM_MID;
Expand All @@ -4581,6 +4623,23 @@ void Test_SB_TransmitMsgPaths_IgnoreOpt(void)

/* Test skipping this pipe and the send should pass */
CFE_UtAssert_SUCCESS(CFE_SB_TransmitMsg(&TlmPkt.Hdr.Msg, true));
UtAssert_STUB_COUNT(OS_QueuePut, 0);

/* Set up and send again without matching ApId and it should transmit */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &Type, sizeof(Type), false);
PipeDscPtr = CFE_SB_LocatePipeDescByID(PipeId);
AppId = PipeDscPtr->AppId;
PipeDscPtr->AppId = CFE_ES_APPID_UNDEFINED;

/* Also hit case where not the peak depth */
PipeDscPtr->PeakQueueDepth += 2;
CFE_UtAssert_SUCCESS(CFE_SB_TransmitMsg(&TlmPkt.Hdr.Msg, true));
UtAssert_STUB_COUNT(OS_QueuePut, 1);

/* Set AppId back so it can be deleted */
PipeDscPtr->AppId = AppId;

CFE_UtAssert_TEARDOWN(CFE_SB_SetPipeOpts(PipeId, 0));
CFE_UtAssert_TEARDOWN(CFE_SB_DeletePipe(PipeId));
Expand Down

0 comments on commit 213b35d

Please sign in to comment.