Skip to content

Commit

Permalink
Fix #1949, update msgid testcase to match implementation
Browse files Browse the repository at this point in the history
Updates the test case for "CFE_MSG_SetMsgId()" to write a value that
is outside the set of storable values for MsgId.  This test has a
caveat that it is somewhat implementation-dependent, but by passing
a MsgId value with all bits set, at least one of those bits is
likely not correlated with a real header bit.
  • Loading branch information
jphickey committed Sep 14, 2021
1 parent 64a6a59 commit 587d1f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion modules/cfe_testcase/src/message_id_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ void TestMsgId(void)
UtAssert_UINT32_EQ(msgid, expectedmsgid);

UtAssert_INT32_EQ(CFE_MSG_SetMsgId(NULL, msgid), CFE_MSG_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_INVALID_MSG_ID), CFE_MSG_BAD_ARGUMENT);

/*
* The purpose of this test is to attempt to set a MsgId beyond the set of values that can
* be stored in the MSG header. However the criteria for being "storable" depends on the
* actual MSG implementation, and may be different in other implementations. Currently both
* "v1" and "v2" implementations do define a specific highest MsgId value, but another
* implementation might not have a highest number concept at all.
*
* By passing the value of -1, when converted to a an unsigned value (either 16 or 32 bit)
* it should translate to a MsgId value with all bits being set. In theory, at least some of
* those bits will be not mappable to the packet header bits, and it should therefore elicit
* the CFE_MSG_BAD_ARGUMENT response.
*/
UtAssert_INT32_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(-1)), CFE_MSG_BAD_ARGUMENT);

UtAssert_INT32_EQ(CFE_MSG_GetMsgId(NULL, &msgid), CFE_MSG_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&msg, NULL), CFE_MSG_BAD_ARGUMENT);
Expand Down
5 changes: 5 additions & 0 deletions modules/core_api/fsw/inc/cfe_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ CFE_Status_t CFE_MSG_GetMsgId(const CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t *M
* This API only sets the bits in the header that make up the message ID.
* No other values in the header are modified.
*
* The user should ensure that this function is only called with a valid
* MsgId parameter value. If called with an invalid value, the results
* are implementation-defined. The implementation may or may not return
* the error code #CFE_MSG_BAD_ARGUMENT in this case.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message @nonnull.
* \param[in] MsgId Message id
*
Expand Down

0 comments on commit 587d1f2

Please sign in to comment.