Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Candidate: 2020-05-27 #71

Merged
merged 8 commits into from
Jun 10, 2020
Merged
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ sample_app is an example for how to build and link an application in cFS. See al

## Version History

### Development Build: 1.1.10
- Test cases now compare an expected event string with a string derived from the spec string and arguments that were output by the unit under test.
- Replace references to `ccsds.h` types with the `cfe_sb.h`-provided type.
- See <https://github.com/nasa/sample_app/pull/71>

### Development Build: 1.1.9

- Applies the CFE_SB_MsgIdToValue() and CFE_SB_ValueToMsgId() routines where compatibility with an integer MsgId is necessary - syslog prints, events, compile-time MID #define values.
Expand Down
4 changes: 2 additions & 2 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
break;

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_ReportHousekeeping((CCSDS_CommandPacket_t *)Msg);
SAMPLE_ReportHousekeeping((CFE_SB_CmdHdr_t *)Msg);
break;

default:
Expand Down Expand Up @@ -348,7 +348,7 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
int32 SAMPLE_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg )
{
int i;

Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void SAMPLE_AppMain(void);
int32 SAMPLE_AppInit(void);
void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
int32 SAMPLE_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg);
int32 SAMPLE_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg);
int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg);
int32 SAMPLE_Process(const SAMPLE_Process_t *Msg);
int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg);
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sample_app_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define SAMPLE_APP_MAJOR_VERSION 1
#define SAMPLE_APP_MINOR_VERSION 1
#define SAMPLE_APP_REVISION 9
#define SAMPLE_APP_REVISION 10
#define SAMPLE_APP_MISSION_REV 0


Expand Down
69 changes: 49 additions & 20 deletions unit-test/coveragetest/coveragetest_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,56 @@ typedef struct
{
uint16 ExpectedEvent;
uint32 MatchCount;
const char *ExpectedText;
} UT_CheckEvent_t;

/*
* An example hook function to check for a specific event.
*/
static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode,
uint32 CallCount, const UT_StubContext_t *Context)
uint32 CallCount, const UT_StubContext_t *Context, va_list va)
{
UT_CheckEvent_t *State = UserObj;
uint16 *EventIdPtr;
char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
uint16 EventId;
const char *Spec;

/*
* The CFE_EVS_SendEvent stub passes the EventID as the
* first context argument.
*/
if (Context->ArgCount > 0)
{
EventIdPtr = (uint16*)Context->ArgPtr[0];
if (*EventIdPtr == State->ExpectedEvent)
EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16);
if (EventId == State->ExpectedEvent)
{
++State->MatchCount;
/*
* Example of how to validate the full argument set.
* If reference text was supplied, also check against this.
*
* NOTE: While this can be done, use with discretion - This isn't really
* verifying that the FSW code unit generated the correct event text,
* rather it is validating what the system snprintf() library function
* produces when passed the format string and args.
*
* __This derived string is not an actual output of the unit under test__
*/
if (State->ExpectedText != NULL)
{
Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *);
if (Spec != NULL)
{
vsnprintf(TestText, sizeof(TestText), Spec, va);
if (strcmp(TestText,State->ExpectedText) == 0)
{
++State->MatchCount;
}
}
}
else
{
++State->MatchCount;
}
}
}

Expand All @@ -80,16 +109,16 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode,
* Helper function to set up for event checking
* This attaches the hook function to CFE_EVS_SendEvent
*/
static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent)
static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *ExpectedText)
{
memset(Evt, 0, sizeof(*Evt));
Evt->ExpectedEvent = ExpectedEvent;
UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt);
Evt->ExpectedText = ExpectedText;
UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt);
}




/*
**********************************************************************************
** TEST CASE FUNCTIONS
Expand Down Expand Up @@ -183,7 +212,7 @@ void Test_SAMPLE_AppMain(void)
*/
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_RcvMsg), 1, CFE_SB_PIPE_RD_ERR);
UT_CheckEvent_Setup(&EventTest, SAMPLE_PIPE_ERR_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_PIPE_ERR_EID, "SAMPLE APP: SB Pipe Read Error, App Will Exit");

/*
* Invoke again
Expand Down Expand Up @@ -249,7 +278,7 @@ void Test_SAMPLE_ProcessCommandPacket(void)
union
{
CFE_SB_Msg_t Base;
CCSDS_CommandPacket_t Cmd;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_Noop_t Noop;
SAMPLE_ResetCounters_t Reset;
SAMPLE_Process_t Process;
Expand All @@ -258,7 +287,7 @@ void Test_SAMPLE_ProcessCommandPacket(void)
UT_CheckEvent_t EventTest;

memset(&TestMsg, 0, sizeof(TestMsg));
UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffff");

/*
* The CFE_SB_GetMsgId() stub uses a data buffer to hold the
Expand Down Expand Up @@ -302,7 +331,7 @@ void Test_SAMPLE_ProcessGroundCommand(void)
union
{
CFE_SB_Msg_t Base;
CCSDS_CommandPacket_t Cmd;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_Noop_t Noop;
SAMPLE_ResetCounters_t Reset;
SAMPLE_Process_t Process;
Expand All @@ -323,14 +352,14 @@ void Test_SAMPLE_ProcessGroundCommand(void)
/* test dispatch of NOOP */
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_NOOP_CC);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Noop));
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL);

SAMPLE_ProcessGroundCommand(&TestMsg.Base);

/* test dispatch of RESET */
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_RESET_COUNTERS_CC);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Reset));
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, NULL);

SAMPLE_ProcessGroundCommand(&TestMsg.Base);

Expand All @@ -344,7 +373,7 @@ void Test_SAMPLE_ProcessGroundCommand(void)
SAMPLE_ProcessGroundCommand(&TestMsg.Base);

/* test an invalid CC */
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID, "Invalid ground command code: CC = 1000");
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, 1000);
SAMPLE_ProcessGroundCommand(&TestMsg.Base);

Expand All @@ -361,9 +390,9 @@ void Test_SAMPLE_ReportHousekeeping(void)
{
/*
* Test Case For:
* void SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
* void SAMPLE_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg )
*/
CCSDS_CommandPacket_t CmdMsg;
CFE_SB_CmdHdr_t CmdMsg;
SAMPLE_HkTlm_t HkTelemetryMsg;

memset(&CmdMsg, 0, sizeof(CmdMsg));
Expand Down Expand Up @@ -426,7 +455,7 @@ void Test_SAMPLE_NoopCmd(void)
memset(&TestMsg, 0, sizeof(TestMsg));

/* test dispatch of NOOP */
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL);

UT_TEST_FUNCTION_RC(SAMPLE_Noop(&TestMsg), CFE_SUCCESS);

Expand All @@ -449,7 +478,7 @@ void Test_SAMPLE_ResetCounters(void)

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

UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, "SAMPLE: RESET command");

UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS);

Expand Down Expand Up @@ -517,7 +546,7 @@ void Test_SAMPLE_VerifyCmdLength(void)
* test a match case
*/
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg));
UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID);
UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID, "Invalid Msg length: ID = 0xFFFF, CC = 0, Len = 18, Expected = 8");

SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg));

Expand Down