From 5c388e312f4ac1041700cf821409f1c8c60345d8 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 24 Aug 2021 14:09:51 -0400 Subject: [PATCH] Fix #1829, confirm CFE_SB_PEND_FOREVER flag 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. --- modules/cfe_testcase/src/sb_sendrecv_test.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/cfe_testcase/src/sb_sendrecv_test.c b/modules/cfe_testcase/src/sb_sendrecv_test.c index 22607ceb2..f25837e23 100644 --- a/modules/cfe_testcase/src/sb_sendrecv_test.c +++ b/modules/cfe_testcase/src/sb_sendrecv_test.c @@ -142,8 +142,11 @@ 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); @@ -151,7 +154,7 @@ void TestBasicTransmitRecv(void) 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); @@ -159,7 +162,7 @@ void TestBasicTransmitRecv(void) 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); @@ -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); /* @@ -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"); -} \ No newline at end of file +}