Skip to content

Commit

Permalink
Fix nasa#711, Unit test and alignment updates
Browse files Browse the repository at this point in the history
Software bus cmd/tlm types now aligned via union
Removed send with invalid msgid tests (can't set invalid msgid)
SB unit tests now pass with VER_2 defined
Backed out 64 bit alignment of messages
  • Loading branch information
skliper committed Aug 7, 2020
1 parent c020a90 commit 84c1fc7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
18 changes: 14 additions & 4 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,20 @@
** Type Definitions
*/

/* Old SB scope typedefs will eventually be deprecated, but high impact */
typedef CFE_MSG_Message_t CFE_SB_Msg_t; /**< \brief Old scope typedefs, old member names might not match */
typedef CFE_MSG_CommandHeader_t CFE_SB_CmdHdr_t; /**< \brief Old scope typedefs, old member names might not match */
typedef CFE_MSG_TelemetryHeader_t CFE_SB_TlmHdr_t; /**< \brief Old scope typedefs, old member names might not match */
/** \brief Software Bus generic message */
typedef CFE_MSG_Message_t CFE_SB_Msg_t;

/** \brief Aligned Software Bus command header */
typedef union {
CFE_MSG_CommandHeader_t Cmd;
CFE_SB_Msg_t BaseMsg;
} CFE_SB_CmdHdr_t;

/** \brief Aligned Software Bus telemetry header */
typedef union {
CFE_MSG_TelemetryHeader_t Tlm;
CFE_SB_Msg_t BaseMsg;
} CFE_SB_TlmHdr_t;

#define CFE_SB_CMD_HDR_SIZE (sizeof(CFE_SB_CmdHdr_t))/**< \brief Size of #CFE_SB_CmdHdr_t in bytes */
#define CFE_SB_TLM_HDR_SIZE (sizeof(CFE_SB_TlmHdr_t))/**< \brief Size of #CFE_SB_TlmHdr_t in bytes */
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/sb/cfe_sb_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr)
}
else if(type == CFE_MSG_Type_Cmd)
{
size = sizeof(CFE_MSG_CommandHeader_t);
size = sizeof(CFE_SB_CmdHdr_t);
}
else if(type == CFE_MSG_Type_Tlm)
{
size = sizeof(CFE_MSG_TelemetryHeader_t);
size = sizeof(CFE_SB_TlmHdr_t);
}

return size;
Expand Down
21 changes: 12 additions & 9 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ void Test_Unsubscribe_GetDestPtr(void)
void Test_SendMsg_API(void)
{
SB_UT_ADD_SUBTEST(Test_SendMsg_NullPtr);
SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId);
/* SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId); - can't set invalid msgid, TODO remove */
SB_UT_ADD_SUBTEST(Test_SendMsg_NoSubscribers);
SB_UT_ADD_SUBTEST(Test_SendMsg_MaxMsgSizePlusOne);
SB_UT_ADD_SUBTEST(Test_SendMsg_BasicSend);
Expand All @@ -2561,7 +2561,7 @@ void Test_SendMsg_API(void)
SB_UT_ADD_SUBTEST(Test_SendMsg_ZeroCopyReleasePtr);
SB_UT_ADD_SUBTEST(Test_SendMsg_DisabledDestination);
SB_UT_ADD_SUBTEST(Test_SendMsg_SendWithMetadata);
SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId_ZeroCopy);
/* SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId_ZeroCopy); - can't set invalid msgid, TODO remove */
SB_UT_ADD_SUBTEST(Test_SendMsg_MaxMsgSizePlusOne_ZeroCopy);
SB_UT_ADD_SUBTEST(Test_SendMsg_NoSubscribers_ZeroCopy);
} /* end Test_SendMsg_API */
Expand All @@ -2582,6 +2582,7 @@ void Test_SendMsg_NullPtr(void)
/*
** Test response to sending a message with an invalid ID
*/
/* TODO remove, this test is no longer valid since you can't set an invalid MSGID */
void Test_SendMsg_InvalidMsgId(void)
{
SB_UT_Test_Tlm_t TlmPkt;
Expand Down Expand Up @@ -3693,11 +3694,11 @@ void Test_CFE_SB_GetUserData_CmdNoSecHdr(void)
CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false);

ActualAdrReturned = CFE_SB_GetUserData(SBNoSecHdrPktPtr);
ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + 6;
ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + sizeof(CCSDS_SpacePacket_t);

UtAssert_True(ActualAdrReturned == ExpAdrReturned,
"Address of data for commands without secondary header is "
"packet address + 6\n PktAddr %p, Rtn %p, Exp %p",
"packet address + CCSDS header(s)\n PktAddr %p, Rtn %p, Exp %p",
(void *) SBNoSecHdrPktPtr, ActualAdrReturned, ExpAdrReturned);

} /* end Test_CFE_SB_GetUserData */
Expand Down Expand Up @@ -3848,7 +3849,8 @@ void Test_CFE_SB_SetGetUserDataLength_Cmd(void)
/* Init cmd pkt w/ sec hdr */
CFE_SB_InitMsg(SBCmdPtr, SB_UT_CMD_MID, sizeof(SB_UT_Test_Cmd_t), true);

Util_CFE_SB_SetGetUserDataLength(SBCmdPtr, sizeof(CFE_MSG_CommandSecondaryHeader_t));
/* Calculation for secondary header accounts for possible padding */
Util_CFE_SB_SetGetUserDataLength(SBCmdPtr, sizeof(CFE_SB_CmdHdr_t) - sizeof(CCSDS_PrimaryHeader_t));

} /* end Test_CFE_SB_SetGetUserDataLength */

Expand All @@ -3861,7 +3863,7 @@ void Test_CFE_SB_SetGetUserDataLength_CmdNoSecHdr(void)
CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_CMD_MID, sizeof(SBNoSecHdrPkt), true);
CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false);

Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, 0);
Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, sizeof(CCSDS_SpacePacket_t) - sizeof(CCSDS_PrimaryHeader_t));

} /* end Test_CFE_SB_SetGetUserDataLength */

Expand All @@ -3873,7 +3875,8 @@ void Test_CFE_SB_SetGetUserDataLength_Tlm(void)
/* Init tlm pkts w/ sec hdr */
CFE_SB_InitMsg(SBTlmPtr, SB_UT_TLM_MID, sizeof(SB_UT_Test_Tlm_t), true);

Util_CFE_SB_SetGetUserDataLength(SBTlmPtr, sizeof(CFE_MSG_TelemetrySecondaryHeader_t));
/* Calculation for secondary header accounts for possible padding */
Util_CFE_SB_SetGetUserDataLength(SBTlmPtr, sizeof(CFE_SB_TlmHdr_t) - sizeof(CCSDS_PrimaryHeader_t));

} /* end Test_CFE_SB_SetGetUserDataLength */

Expand All @@ -3886,7 +3889,7 @@ void Test_CFE_SB_SetGetUserDataLength_TlmNoSecHdr(void)
CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_TLM_MID, sizeof(SBNoSecHdrPkt), true);
CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false);

Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, 0);
Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, sizeof(CCSDS_SpacePacket_t) - sizeof(CCSDS_PrimaryHeader_t));

} /* end Test_CFE_SB_SetGetUserDataLength */

Expand Down Expand Up @@ -4173,7 +4176,7 @@ void Test_CFE_SB_ChecksumUtils_Cmd(void)
#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
ExpRtnFrmGet = 0x2f;
#else
ExpRtnFrmGet = 0x65;
ExpRtnFrmGet = 0x5D;
#endif
ASSERT_EQ(CFE_SB_GetChecksum(SBCmdPtr), ExpRtnFrmGet);

Expand Down
2 changes: 1 addition & 1 deletion modules/msg/mission_inc/default_cfe_msg_hdr_pri.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint64 LongLong; /**< \brief Force 64-bit alignment */
uint32 Align; /**< \brief Force 32-bit alignment */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

Expand Down
2 changes: 1 addition & 1 deletion modules/msg/mission_inc/default_cfe_msg_hdr_priext.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ typedef struct
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint64 LongLong; /**< \brief Force 64-bit alignment */
uint32 Align; /**< \brief Force 32-bit alignment */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

Expand Down

0 comments on commit 84c1fc7

Please sign in to comment.