Skip to content

Commit

Permalink
Fix nasa#1829, confirm CFE_SB_PEND_FOREVER flag
Browse files Browse the repository at this point in the history
Use the CFE_SB_PEND_FOREVER flag on a few of the calls to CFE_SB_ReceiveBuffer
to confirm that this works as expected.  Previously only CFE_SB_POLL and
a nonzero timeout were used.

Note this can only be used when it is known/expected that the message
queue is not empty.  If there is any possiblility that the queue is empty,
then this cannot be used or else the test may block.  This also means that
if the test fails, it may fail by blocking and never finishing the test
rather than an actual FAIL testcase.
  • Loading branch information
jphickey committed Aug 24, 2021
1 parent ea38fd2 commit 5c388e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/cfe_testcase/src/sb_sendrecv_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,27 @@ void TestBasicTransmitRecv(void)
/*
* Note, the CFE_SB_TransmitMsg ignores the "IncrementSequence" flag for commands.
* Thus, all the sequence numbers should come back with the original value set (11)
*
* Note this also utilizes the CFE_SB_PEND_FOREVER flag - if working correctly,
* there should be a message in the queue, so it should not block.
*/
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_UtAssert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x0c0ffee);
UtAssert_UINT32_EQ(Seq1, 11);

UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_UtAssert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x1c0ffee);
UtAssert_UINT32_EQ(Seq1, 11);

UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_UtAssert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
Expand All @@ -168,6 +171,7 @@ void TestBasicTransmitRecv(void)
UtAssert_UINT32_EQ(Seq1, 11);

/* Final should not be in the pipe, should have been rejected due to MsgLim */
/* Must not use CFE_SB_PEND_FOREVER here, as this will cause the test to block */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, 100), CFE_SB_TIME_OUT);

/*
Expand Down Expand Up @@ -372,4 +376,4 @@ void SBSendRecvTestSetup(void)
UtTest_Add(TestBasicTransmitRecv, NULL, NULL, "Test Basic Transmit/Receive");
UtTest_Add(TestZeroCopyTransmitRecv, NULL, NULL, "Test Zero Copy Transmit/Receive");
UtTest_Add(TestMiscMessageUtils, NULL, NULL, "Test Miscellaneous Message Utility APIs");
}
}

0 comments on commit 5c388e3

Please sign in to comment.