Skip to content

Commit

Permalink
WIP nasa#110 - needs unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Nov 18, 2020
1 parent 0d11d9e commit c53b65e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 65 deletions.
43 changes: 22 additions & 21 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ SAMPLE_APP_Data_t SAMPLE_APP_Data;
void SAMPLE_APP_Main(void)
{
int32 status;
CFE_SB_Buffer_t *SBBufPtr;

/*
** Register the app with Executive services
Expand Down Expand Up @@ -82,7 +83,7 @@ void SAMPLE_APP_Main(void)
CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID);

/* Pend on receipt of command packet */
status = CFE_SB_RcvMsg(&SAMPLE_APP_Data.MsgPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER);
status = CFE_SB_RcvMsg(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER);

/*
** Performance Log Entry Stamp
Expand All @@ -91,7 +92,7 @@ void SAMPLE_APP_Main(void)

if (status == CFE_SUCCESS)
{
SAMPLE_APP_ProcessCommandPacket(SAMPLE_APP_Data.MsgPtr);
SAMPLE_APP_ProcessCommandPacket(SBBufPtr);
}
else
{
Expand Down Expand Up @@ -168,7 +169,7 @@ int32 SAMPLE_APP_Init(void)
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_MSG_Init(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkTlm));
CFE_MSG_Init(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkTlm));

/*
** Create Software Bus message pipe.
Expand Down Expand Up @@ -232,20 +233,20 @@ int32 SAMPLE_APP_Init(void)
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId);

switch (MsgId)
{
case SAMPLE_APP_CMD_MID:
SAMPLE_APP_ProcessGroundCommand(MsgPtr);
SAMPLE_APP_ProcessGroundCommand(SBBufPtr);
break;

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_APP_ReportHousekeeping((CFE_SB_CmdHdr_t *)MsgPtr);
SAMPLE_APP_ReportHousekeeping((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;

default:
Expand All @@ -263,37 +264,37 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
/* SAMPLE_APP_ProcessGroundCommand() -- SAMPLE ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(MsgPtr, &CommandCode);
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);

/*
** Process "known" SAMPLE app ground commands
*/
switch (CommandCode)
{
case SAMPLE_APP_NOOP_CC:
if (SAMPLE_APP_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_APP_Noop_t)))
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t)))
{
SAMPLE_APP_Noop((SAMPLE_APP_Noop_t *)MsgPtr);
SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr);
}

break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_APP_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_APP_ResetCounters_t)))
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t)))
{
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCounters_t *)MsgPtr);
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr);
}

break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_APP_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_APP_Process_t)))
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t)))
{
SAMPLE_APP_Process((SAMPLE_APP_Process_t *)MsgPtr);
SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr);
}

break;
Expand All @@ -318,7 +319,7 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg)
{
int i;

Expand All @@ -331,8 +332,8 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);
CFE_SB_SendMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);
CFE_SB_TimeStampMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg);
CFE_SB_TransmitMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg, true);

/*
** Manage any pending table loads, validations, etc.
Expand All @@ -351,7 +352,7 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/* SAMPLE_APP_Noop -- SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg)
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
{

SAMPLE_APP_Data.CmdCounter++;
Expand All @@ -371,7 +372,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg)
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg)
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
{

SAMPLE_APP_Data.CmdCounter = 0;
Expand All @@ -390,7 +391,7 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg)
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg)
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)
{
int32 status;
SAMPLE_APP_Table_t *TblPtr;
Expand Down
13 changes: 6 additions & 7 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ typedef struct
** Operational data (not reported in housekeeping)...
*/
CFE_SB_PipeId_t CommandPipe;
CFE_MSG_Message_t *MsgPtr;

/*
** Initialization data (not reported in housekeeping)...
Expand All @@ -104,12 +103,12 @@ typedef struct
*/
void SAMPLE_APP_Main(void);
int32 SAMPLE_APP_Init(void);
void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr);
void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr);
int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg);
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg);
int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg);
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr);
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr);
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg);
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg);
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg);
void SAMPLE_APP_GetCrc(const char *TableName);

int32 SAMPLE_APP_TblValidationFunc(void *TblData);
Expand Down
15 changes: 7 additions & 8 deletions fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@
*/
typedef struct
{
uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE];

CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */
} SAMPLE_APP_NoArgsCmd_t;

/*
** The following commands all share the "NoArgs" format
**
** They are each given their own type name matching the command name, which_open_mode
** They are each given their own type name matching the command name, which
** allows them to change independently in the future without changing the prototype
** of the handler function
*/
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_Noop_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ResetCounters_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_Process_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_NoopCmd_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ResetCountersCmd_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ProcessCmd_t;

/*************************************************************************/
/*
Expand All @@ -73,8 +72,8 @@ typedef struct

typedef struct
{
CFE_SB_TlmHdr_t TlmHeader;
SAMPLE_APP_HkTlm_Payload_t Payload;
CFE_MSG_TelemetryHeader_t TlmHeader; /**< \brief Telemetry header */
SAMPLE_APP_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */
} SAMPLE_APP_HkTlm_t;


Expand Down
54 changes: 25 additions & 29 deletions unit-test/coveragetest/coveragetest_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,8 @@ void Test_SAMPLE_APP_ProcessCommandPacket(void)
/* a buffer large enough for any command message */
union
{
CFE_MSG_Message_t Base;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_APP_Noop_t Noop;
SAMPLE_APP_ResetCounters_t Reset;
SAMPLE_APP_Process_t Process;
CFE_SB_Buffer_t SBBuf;
SAMPLE_APP_NoopCmd_t Noop;
} TestMsg;
CFE_SB_MsgId_t TestMsgId;
CFE_MSG_FcnCode_t FcnCode;
Expand All @@ -297,20 +294,20 @@ void Test_SAMPLE_APP_ProcessCommandPacket(void)
*/
TestMsgId = SAMPLE_APP_CMD_MID;
FcnCode = SAMPLE_APP_NOOP_CC;
MsgSize = sizeof(SAMPLE_APP_Noop_t);
MsgSize = sizeof(TestMsg.Noop);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.Base);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.SBBuf);

TestMsgId = SAMPLE_APP_SEND_HK_MID;
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.Base);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.SBBuf);

/* invalid message id */
TestMsgId = CFE_SB_INVALID_MSG_ID;
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.Base);
SAMPLE_APP_ProcessCommandPacket(&TestMsg.SBBuff);

/*
* Confirm that the event was generated only _once_
Expand All @@ -331,11 +328,10 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
/* a buffer large enough for any command message */
union
{
CFE_MSG_Message_t Base;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_APP_Noop_t Noop;
SAMPLE_APP_ResetCounters_t Reset;
SAMPLE_APP_Process_t Process;
CFE_SB_Buffer_t SBBuf;
SAMPLE_APP_NoopCmd_t Noop;
SAMPLE_APP_ResetCountersCmd_t Reset;
SAMPLE_APP_ProcessCmd_t Process;
} TestMsg;
UT_CheckEvent_t EventTest;

Expand All @@ -357,7 +353,7 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);
UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_COMMANDNOP_INF_EID, NULL);

SAMPLE_APP_ProcessGroundCommand(&TestMsg.Base);
SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf);

UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMANDNOP_INF_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
Expand All @@ -369,7 +365,7 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);
UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_COMMANDRST_INF_EID, NULL);

SAMPLE_APP_ProcessGroundCommand(&TestMsg.Base);
SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf);

UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMANDRST_INF_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
Expand All @@ -383,13 +379,13 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);

SAMPLE_APP_ProcessGroundCommand(&TestMsg.Base);
SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf);

/* test an invalid CC */
FcnCode = 1000;
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_COMMAND_ERR_EID, "Invalid ground command code: CC = %d");
SAMPLE_APP_ProcessGroundCommand(&TestMsg.Base);
SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf);

/*
* Confirm that the event was generated only _once_
Expand All @@ -412,17 +408,17 @@ void Test_SAMPLE_APP_ReportHousekeeping(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);

/* Set up to capture send message address */
UT_SetDataBuffer(UT_KEY(CFE_SB_SendMsg), &MsgSend, sizeof(MsgSend), false);
UT_SetDataBuffer(UT_KEY(CFE_SB_TransmitMsg), &MsgSend, sizeof(MsgSend), false);

/* Set up to capture timestamp message address */
UT_SetDataBuffer(UT_KEY(CFE_SB_TimeStampMsg), &MsgTimestamp, sizeof(MsgTimestamp), false);

/* Call unit under test, NULL pointer confirms command access is through APIs */
SAMPLE_APP_ProcessCommandPacket((CFE_MSG_Message_t *)NULL);
SAMPLE_APP_ProcessCommandPacket((CFE_SB_Buffer_t *)NULL);

/* Confirm message sent*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_SendMsg)) == 1, "CFE_SB_SendMsg() called once");
UtAssert_True(MsgSend == &SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg, "CFE_SB_SendMsg() address matches expected");
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)) == 1, "CFE_SB_TransmitMsg() called once");
UtAssert_True(MsgSend == &SAMPLE_APP_Data.HkTlm.TlmHeader.Msg, "CFE_SB_TransmitMsg() address matches expected");

/* Confirm timestamp msg address */
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_TimeStampMsg)) == 1, "CFE_SB_TimeStampMsg() called once");
Expand All @@ -440,8 +436,8 @@ void Test_SAMPLE_APP_NoopCmd(void)
* Test Case For:
* void SAMPLE_APP_NoopCmd( const SAMPLE_APP_Noop_t *Msg )
*/
SAMPLE_APP_Noop_t TestMsg;
UT_CheckEvent_t EventTest;
SAMPLE_APP_NoopCmd_t TestMsg;
UT_CheckEvent_t EventTest;

memset(&TestMsg, 0, sizeof(TestMsg));

Expand All @@ -463,8 +459,8 @@ void Test_SAMPLE_APP_ResetCounters(void)
* Test Case For:
* void SAMPLE_APP_ResetCounters( const SAMPLE_APP_ResetCounters_t *Msg )
*/
SAMPLE_APP_ResetCounters_t TestMsg;
UT_CheckEvent_t EventTest;
SAMPLE_APP_ResetCountersCmd_t TestMsg;
UT_CheckEvent_t EventTest;

memset(&TestMsg, 0, sizeof(TestMsg));

Expand All @@ -485,9 +481,9 @@ void Test_SAMPLE_APP_ProcessCC(void)
* Test Case For:
* void SAMPLE_APP_ProcessCC( const SAMPLE_APP_Process_t *Msg )
*/
SAMPLE_APP_Process_t TestMsg;
SAMPLE_APP_Table_t TestTblData;
void * TblPtr = &TestTblData;
SAMPLE_APP_ProcessCmd_t TestMsg;
SAMPLE_APP_Table_t TestTblData;
void * TblPtr = &TestTblData;

memset(&TestTblData, 0, sizeof(TestTblData));
memset(&TestMsg, 0, sizeof(TestMsg));
Expand Down

0 comments on commit c53b65e

Please sign in to comment.