From 4eba3c0a302d883549082fcbf93eb3f2f7e26a53 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 23 Sep 2020 10:36:59 -0400 Subject: [PATCH] Fix #903, Add CFE_SB_GetUserData padding check --- fsw/cfe-core/unit-test/sb_UT.c | 78 ++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 1e1901497..3ebb52163 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -3674,9 +3674,51 @@ void Test_CFE_SB_MsgHdrSize(void) void Test_CFE_SB_GetUserData(void) { CFE_SB_Msg_t msg; - uint8 *ExpAdrReturned; + uint8 *expected; bool hassec; CFE_MSG_Type_t type = CFE_MSG_Type_Invalid; + struct + { + CFE_SB_CmdHdr_t cmd; + uint8 payload; + } cmd_uint8; + struct + { + CFE_SB_CmdHdr_t cmd; + uint16 payload; + } cmd_uint16; + struct + { + CFE_SB_CmdHdr_t cmd; + uint32 payload; + } cmd_uint32; + struct + { + CFE_SB_CmdHdr_t cmd; + uint64 payload; + } cmd_uint64; + struct + { + CFE_SB_TlmHdr_t tlm; + uint8 payload; + } tlm_uint8; + struct + { + CFE_SB_TlmHdr_t tlm; + uint16 payload; + } tlm_uint16; + struct + { + CFE_SB_TlmHdr_t tlm; + uint32 payload; + } tlm_uint32; + struct + { + CFE_SB_TlmHdr_t tlm; + uint64 payload; + } tlm_uint64; + + /* No secondary */ hassec = false; @@ -3684,9 +3726,39 @@ void Test_CFE_SB_GetUserData(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); /* Expected return */ - ExpAdrReturned = (uint8 *)&msg + sizeof(CCSDS_SpacePacket_t); + expected = (uint8 *)&msg + sizeof(CCSDS_SpacePacket_t); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData(&msg), expected); + + /* Commands */ + hassec = true; + type = CFE_MSG_Type_Cmd; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&cmd_uint8), &(cmd_uint8.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&cmd_uint16), &(cmd_uint16.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&cmd_uint32), &(cmd_uint32.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&cmd_uint64), &(cmd_uint64.payload)); - ASSERT_TRUE(CFE_SB_GetUserData(&msg) == ExpAdrReturned); + /* Telemetry */ + type = CFE_MSG_Type_Tlm; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&tlm_uint8), &(tlm_uint8.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&tlm_uint16), &(tlm_uint16.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&tlm_uint32), &(tlm_uint32.payload)); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetHasSecondaryHeader), &hassec, sizeof(hassec), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &type, sizeof(type), false); + UtAssert_ADDRESS_EQ(CFE_SB_GetUserData((CFE_SB_Msg_t*)&tlm_uint64), &(tlm_uint64.payload)); } /* end Test_CFE_SB_GetUserData */