From 587d1f2b74d8c8b301cf8f7fb9b69600e5d97a8a Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 14 Sep 2021 09:08:07 -0400 Subject: [PATCH] Fix #1949, update msgid testcase to match implementation 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. --- modules/cfe_testcase/src/message_id_test.c | 15 ++++++++++++++- modules/core_api/fsw/inc/cfe_msg.h | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/cfe_testcase/src/message_id_test.c b/modules/cfe_testcase/src/message_id_test.c index 6561aea8e..235d1cf8d 100644 --- a/modules/cfe_testcase/src/message_id_test.c +++ b/modules/cfe_testcase/src/message_id_test.c @@ -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); diff --git a/modules/core_api/fsw/inc/cfe_msg.h b/modules/core_api/fsw/inc/cfe_msg.h index b8f5b6348..41e8c19eb 100644 --- a/modules/core_api/fsw/inc/cfe_msg.h +++ b/modules/core_api/fsw/inc/cfe_msg.h @@ -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 *