diff --git a/CHANGELOG.md b/CHANGELOG.md index d59533b..4b16d91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Development Build: 1.3.0-rc4+dev65 +- bring sample_app fully into compliance +- Rename CommandCode variable to FcnCode +- Add check for success of CFE_TBL_Load() during Initialization +- See , , and + ## Development Build: v1.3.0-rc4+dev56 - Apply consistent Event ID names to common events - Remove component-specific cFE header #includes diff --git a/CMakeLists.txt b/CMakeLists.txt index d84eea4..de47fce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,14 @@ project(CFE_SAMPLE_APP C) +set(APP_SRC_FILES + fsw/src/sample_app.c + fsw/src/sample_app_cmds.c + fsw/src/sample_app_dispatch.c + fsw/src/sample_app_utils.c +) + # Create the app module -add_cfe_app(sample_app fsw/src/sample_app.c - fsw/src/sample_app_cmds.c - fsw/src/sample_app_utils.c) +add_cfe_app(sample_app ${APP_SRC_FILES}) target_include_directories(sample_app PUBLIC fsw/inc) # Include the public API from sample_lib to demonstrate how diff --git a/config/default_sample_app_fcncodes.h b/config/default_sample_app_fcncodes.h index aec457f..b701c1c 100644 --- a/config/default_sample_app_fcncodes.h +++ b/config/default_sample_app_fcncodes.h @@ -38,5 +38,6 @@ #define SAMPLE_APP_NOOP_CC 0 #define SAMPLE_APP_RESET_COUNTERS_CC 1 #define SAMPLE_APP_PROCESS_CC 2 +#define SAMPLE_APP_DISPLAY_PARAM_CC 3 #endif diff --git a/config/default_sample_app_interface_cfg.h b/config/default_sample_app_interface_cfg.h new file mode 100644 index 0000000..aac83dd --- /dev/null +++ b/config/default_sample_app_interface_cfg.h @@ -0,0 +1,44 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * SAMPLE_APP Application Public Definitions + * + * This provides default values for configurable items that affect + * the interface(s) of this module. This includes the CMD/TLM message + * interface, tables definitions, and any other data products that + * serve to exchange information with other entities. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_INTERFACE_CFG_H +#define SAMPLE_APP_INTERFACE_CFG_H + +/** + * \brief Length of string buffer in the Display Value command + * + * The Display Value command offers an example of how to use command + * parameters of different types. This macro controls the length + * of the string parameter. + */ +#define SAMPLE_APP_STRING_VAL_LEN 10 + +#endif diff --git a/config/default_sample_app_internal_cfg.h b/config/default_sample_app_internal_cfg.h index 32862ae..25d753f 100644 --- a/config/default_sample_app_internal_cfg.h +++ b/config/default_sample_app_internal_cfg.h @@ -35,7 +35,7 @@ /***********************************************************************/ #define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ -#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Table(s) */ +#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Example Table(s) */ #define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 diff --git a/config/default_sample_app_mission_cfg.h b/config/default_sample_app_mission_cfg.h index 93d3307..9c5d166 100644 --- a/config/default_sample_app_mission_cfg.h +++ b/config/default_sample_app_mission_cfg.h @@ -31,6 +31,6 @@ #ifndef SAMPLE_APP_MISSION_CFG_H #define SAMPLE_APP_MISSION_CFG_H -/* Placeholder - SAMPLE_APP currently has no mission-scope config options */ +#include "sample_app_interface_cfg.h" #endif diff --git a/config/default_sample_app_msgdefs.h b/config/default_sample_app_msgdefs.h index 7ea7b82..1e4d10e 100644 --- a/config/default_sample_app_msgdefs.h +++ b/config/default_sample_app_msgdefs.h @@ -29,12 +29,19 @@ #include "common_types.h" #include "sample_app_fcncodes.h" +typedef struct SAMPLE_APP_DisplayParam_Payload +{ + uint32 ValU32; /**< 32 bit unsigned integer value */ + int16 ValI16; /**< 16 bit signed integer value */ + char ValStr[SAMPLE_APP_STRING_VAL_LEN]; /**< An example string */ +} SAMPLE_APP_DisplayParam_Payload_t; + /*************************************************************************/ /* ** Type definition (Sample App housekeeping) */ -typedef struct +typedef struct SAMPLE_APP_HkTlm_Payload { uint8 CommandErrorCounter; uint8 CommandCounter; diff --git a/config/default_sample_app_msgstruct.h b/config/default_sample_app_msgstruct.h index 90d1a47..03327c9 100644 --- a/config/default_sample_app_msgstruct.h +++ b/config/default_sample_app_msgstruct.h @@ -60,6 +60,12 @@ typedef struct CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ } SAMPLE_APP_ProcessCmd_t; +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ + SAMPLE_APP_DisplayParam_Payload_t Payload; +} SAMPLE_APP_DisplayParamCmd_t; + /*************************************************************************/ /* ** Type definition (Sample App housekeeping) diff --git a/config/default_sample_app_tbldefs.h b/config/default_sample_app_tbldefs.h index 7338708..d478f00 100644 --- a/config/default_sample_app_tbldefs.h +++ b/config/default_sample_app_tbldefs.h @@ -40,6 +40,6 @@ typedef struct { uint16 Int1; uint16 Int2; -} SAMPLE_APP_Table_t; +} SAMPLE_APP_ExampleTable_t; #endif diff --git a/fsw/inc/sample_app_eventids.h b/fsw/inc/sample_app_eventids.h index fdbe613..06406d8 100644 --- a/fsw/inc/sample_app_eventids.h +++ b/fsw/inc/sample_app_eventids.h @@ -33,5 +33,6 @@ #define SAMPLE_APP_MID_ERR_EID 5 #define SAMPLE_APP_CMD_LEN_ERR_EID 6 #define SAMPLE_APP_PIPE_ERR_EID 7 +#define SAMPLE_APP_VALUE_INF_EID 8 #endif /* SAMPLE_APP_EVENTS_H */ diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index d2abb76..b3b7e8a 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -24,14 +24,13 @@ /* ** Include Files: */ -#include - #include "sample_app.h" #include "sample_app_cmds.h" #include "sample_app_utils.h" #include "sample_app_eventids.h" -#include "sample_app_version.h" +#include "sample_app_dispatch.h" #include "sample_app_tbl.h" +#include "sample_app_version.h" /* ** global data @@ -84,7 +83,7 @@ void SAMPLE_APP_Main(void) if (status == CFE_SUCCESS) { - SAMPLE_APP_ProcessCommandPacket(SBBufPtr); + SAMPLE_APP_TaskPipe(SBBufPtr); } else { @@ -173,18 +172,19 @@ int32 SAMPLE_APP_Init(void) { CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status); } + } if (status == CFE_SUCCESS) { /* - ** Register Table(s) + ** Register Example Table(s) */ - status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_t), + status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "ExampleTable", sizeof(SAMPLE_APP_ExampleTable_t), CFE_TBL_OPT_DEFAULT, SAMPLE_APP_TblValidationFunc); if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Registering Table, RC = 0x%08lX\n", (unsigned long)status); + CFE_ES_WriteToSysLog("Sample App: Error Registering Example Table, RC = 0x%08lX\n", (unsigned long)status); } else { @@ -197,114 +197,3 @@ int32 SAMPLE_APP_Init(void) return status; } - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This routine will process any packet that is received on the Sample */ -/* App command pipe. */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); - - switch (CFE_SB_MsgIdToValue(MsgId)) - { - case SAMPLE_APP_CMD_MID: - SAMPLE_APP_ProcessGroundCommand(SBBufPtr); - break; - - case SAMPLE_APP_SEND_HK_MID: - SAMPLE_APP_ReportHousekeeping((CFE_MSG_CommandHeader_t *)SBBufPtr); - break; - - default: - CFE_EVS_SendEvent(SAMPLE_APP_MID_ERR_EID, CFE_EVS_EventType_ERROR, - "SAMPLE: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId)); - break; - } -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Process Ground Commands */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_MSG_FcnCode_t CommandCode = 0; - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - - /* - ** Process "known" Sample App ground commands - */ - switch (CommandCode) - { - case SAMPLE_APP_NOOP_CC: - if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t))) - { - SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr); - } - break; - - case SAMPLE_APP_RESET_COUNTERS_CC: - if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t))) - { - SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr); - } - break; - - case SAMPLE_APP_PROCESS_CC: - if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t))) - { - SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr); - } - break; - - /* default case already found during FC vs length test */ - default: - CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid ground command code: CC = %d", - CommandCode); - break; - } -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function is triggered in response to a task telemetry request */ -/* from the housekeeping task. This function will gather the App's */ -/* telemetry, packetize it and send it to the housekeeping task via */ -/* the software bus. */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg) -{ - int i; - - /* - ** Get command execution counters... - */ - SAMPLE_APP_Data.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter; - SAMPLE_APP_Data.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter; - - /* - ** Send housekeeping telemetry packet... - */ - CFE_SB_TimeStampMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader)); - CFE_SB_TransmitMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), true); - - /* - ** Manage any pending table loads, validations, etc. - */ - for (i = 0; i < SAMPLE_APP_NUMBER_OF_TABLES; i++) - { - CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]); - } - - return CFE_SUCCESS; -} diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index d0d7e6a..321d1d8 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -90,8 +90,5 @@ extern SAMPLE_APP_Data_t SAMPLE_APP_Data; */ void SAMPLE_APP_Main(void); int32 SAMPLE_APP_Init(void); -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); #endif /* SAMPLE_APP_H */ diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index fc635d5..e30fe32 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -26,6 +26,7 @@ */ #include "sample_app.h" #include "sample_app_cmds.h" +#include "sample_app_msgids.h" #include "sample_app_eventids.h" #include "sample_app_version.h" #include "sample_app_tbl.h" @@ -35,12 +36,47 @@ /* The sample_lib module provides the SAMPLE_Function() prototype */ #include "sample_lib.h" +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function is triggered in response to a task telemetry request */ +/* from the housekeeping task. This function will gather the Apps */ +/* telemetry, packetize it and send it to the housekeeping task via */ +/* the software bus */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t SAMPLE_APP_SendHkCmd(const SAMPLE_APP_SendHkCmd_t *Msg) +{ + int i; + + /* + ** Get command execution counters... + */ + SAMPLE_APP_Data.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter; + SAMPLE_APP_Data.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter; + + /* + ** Send housekeeping telemetry packet... + */ + CFE_SB_TimeStampMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader)); + CFE_SB_TransmitMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), true); + + /* + ** Manage any pending table loads, validations, etc. + */ + for (i = 0; i < SAMPLE_APP_NUMBER_OF_TABLES; i++) + { + CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]); + } + + return CFE_SUCCESS; +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ /* SAMPLE NOOP commands */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) +CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg) { SAMPLE_APP_Data.CmdCounter++; @@ -57,7 +93,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) /* part of the task telemetry. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) +CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg) { SAMPLE_APP_Data.CmdCounter = 0; SAMPLE_APP_Data.ErrCounter = 0; @@ -73,15 +109,16 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) /* This function Process Ground Station Command */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) +CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) { - int32 status; - SAMPLE_APP_Table_t *TblPtr; - const char * TableName = "SAMPLE_APP.SampleAppTable"; + int32 status; + void * TblAddr; + SAMPLE_APP_ExampleTable_t *TblPtr; + const char * TableName = "SAMPLE_APP.ExampleTable"; - /* Sample Use of Table */ + /* Sample Use of Example Table */ - status = CFE_TBL_GetAddress((void *)&TblPtr, SAMPLE_APP_Data.TblHandles[0]); + status = CFE_TBL_GetAddress(&TblAddr, SAMPLE_APP_Data.TblHandles[0]); if (status < CFE_SUCCESS) { @@ -89,7 +126,8 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) return status; } - CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); + TblPtr = TblAddr; + CFE_ES_WriteToSysLog("Sample App: Example Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); SAMPLE_APP_GetCrc(TableName); @@ -105,3 +143,17 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) return CFE_SUCCESS; } + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* A simple example command that displays a passed-in value */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +CFE_Status_t SAMPLE_APP_DisplayParamCmd(const SAMPLE_APP_DisplayParamCmd_t *Msg) +{ + CFE_EVS_SendEvent(SAMPLE_APP_VALUE_INF_EID, CFE_EVS_EventType_INFORMATION, + "SAMPLE_APP: ValU32=%lu, ValI16=%d, ValStr=%s", (unsigned long)Msg->Payload.ValU32, + (int)Msg->Payload.ValI16, Msg->Payload.ValStr); + + return CFE_SUCCESS; +} diff --git a/fsw/src/sample_app_cmds.h b/fsw/src/sample_app_cmds.h index 7b899e9..8b99259 100644 --- a/fsw/src/sample_app_cmds.h +++ b/fsw/src/sample_app_cmds.h @@ -27,10 +27,13 @@ /* ** Required header files. */ -#include "sample_app.h" +#include "cfe_error.h" +#include "sample_app_msg.h" -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); +CFE_Status_t SAMPLE_APP_SendHkCmd(const SAMPLE_APP_SendHkCmd_t *Msg); +CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg); +CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg); +CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg); +CFE_Status_t SAMPLE_APP_DisplayParamCmd(const SAMPLE_APP_DisplayParamCmd_t *Msg); -#endif /* SAMPLE_APP_CMDS_H */ \ No newline at end of file +#endif /* SAMPLE_APP_CMDS_H */ diff --git a/fsw/src/sample_app_dispatch.c b/fsw/src/sample_app_dispatch.c new file mode 100644 index 0000000..4928cb7 --- /dev/null +++ b/fsw/src/sample_app_dispatch.c @@ -0,0 +1,149 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * This file contains the source code for the Sample App. + */ + +/* +** Include Files: +*/ +#include "sample_app.h" +#include "sample_app_dispatch.h" +#include "sample_app_cmds.h" +#include "sample_app_eventids.h" +#include "sample_app_msgids.h" +#include "sample_app_msg.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Verify command packet length */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +bool SAMPLE_APP_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + size_t ActualLength = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t FcnCode = 0; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length. + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + CFE_EVS_SendEvent(SAMPLE_APP_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + + result = false; + + SAMPLE_APP_Data.ErrCounter++; + } + + return result; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* SAMPLE ground commands */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +void SAMPLE_APP_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_MSG_FcnCode_t CommandCode = 0; + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + + /* + ** Process SAMPLE app ground commands + */ + switch (CommandCode) + { + case SAMPLE_APP_NOOP_CC: + if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t))) + { + SAMPLE_APP_NoopCmd((const SAMPLE_APP_NoopCmd_t *)SBBufPtr); + } + break; + + case SAMPLE_APP_RESET_COUNTERS_CC: + if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t))) + { + SAMPLE_APP_ResetCountersCmd((const SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr); + } + break; + + case SAMPLE_APP_PROCESS_CC: + if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t))) + { + SAMPLE_APP_ProcessCmd((const SAMPLE_APP_ProcessCmd_t *)SBBufPtr); + } + break; + + case SAMPLE_APP_DISPLAY_PARAM_CC: + if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_DisplayParamCmd_t))) + { + SAMPLE_APP_DisplayParamCmd((const SAMPLE_APP_DisplayParamCmd_t *)SBBufPtr); + } + break; + + /* default case already found during FC vs length test */ + default: + CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid ground command code: CC = %d", + CommandCode); + break; + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This routine will process any packet that is received on the SAMPLE */ +/* command pipe. */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_APP_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); + + switch (CFE_SB_MsgIdToValue(MsgId)) + { + case SAMPLE_APP_CMD_MID: + SAMPLE_APP_ProcessGroundCommand(SBBufPtr); + break; + + case SAMPLE_APP_SEND_HK_MID: + SAMPLE_APP_SendHkCmd((const SAMPLE_APP_SendHkCmd_t *)SBBufPtr); + break; + + default: + CFE_EVS_SendEvent(SAMPLE_APP_MID_ERR_EID, CFE_EVS_EventType_ERROR, + "SAMPLE: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId)); + break; + } +} diff --git a/fsw/src/sample_app_dispatch.h b/fsw/src/sample_app_dispatch.h new file mode 100644 index 0000000..b3289e8 --- /dev/null +++ b/fsw/src/sample_app_dispatch.h @@ -0,0 +1,38 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Main header file for the SAMPLE application + */ + +#ifndef SAMPLE_APP_DISPATCH_H +#define SAMPLE_APP_DISPATCH_H + +/* +** Required header files. +*/ +#include "cfe.h" +#include "sample_app_msg.h" + +void SAMPLE_APP_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); +void SAMPLE_APP_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr); +bool SAMPLE_APP_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); + +#endif /* SAMPLE_APP_DISPATCH_H */ diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c index a316dcf..0de14ea 100644 --- a/fsw/src/sample_app_utils.c +++ b/fsw/src/sample_app_utils.c @@ -29,53 +29,18 @@ #include "sample_app_tbl.h" #include "sample_app_utils.h" -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Verify command packet length */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - size_t ActualLength = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t FcnCode = 0; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length. - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - CFE_EVS_SendEvent(SAMPLE_APP_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - - result = false; - - SAMPLE_APP_Data.ErrCounter++; - } - - return result; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* Verify contents of First Table buffer contents */ +/* Verify contents of First Example Table buffer contents */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_APP_TblValidationFunc(void *TblData) { - int32 ReturnCode = CFE_SUCCESS; - SAMPLE_APP_Table_t *TblDataPtr = (SAMPLE_APP_Table_t *)TblData; + int32 ReturnCode = CFE_SUCCESS; + SAMPLE_APP_ExampleTable_t *TblDataPtr = (SAMPLE_APP_ExampleTable_t *)TblData; /* - ** Sample Table Validation + ** Sample Example Table Validation */ if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX) { @@ -100,7 +65,7 @@ void SAMPLE_APP_GetCrc(const char *TableName) status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info"); + CFE_ES_WriteToSysLog("Sample App: Error Getting Example Table Info"); } else { diff --git a/fsw/src/sample_app_utils.h b/fsw/src/sample_app_utils.h index 369f050..873962d 100644 --- a/fsw/src/sample_app_utils.h +++ b/fsw/src/sample_app_utils.h @@ -29,7 +29,6 @@ */ #include "sample_app.h" -bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); int32 SAMPLE_APP_TblValidationFunc(void *TblData); void SAMPLE_APP_GetCrc(const char *TableName); diff --git a/fsw/src/sample_app_version.h b/fsw/src/sample_app_version.h index b29b42d..4498804 100644 --- a/fsw/src/sample_app_version.h +++ b/fsw/src/sample_app_version.h @@ -27,7 +27,7 @@ /* Development Build Macro Definitions */ -#define SAMPLE_APP_BUILD_NUMBER 56 /*!< Development Build: Number of commits since baseline */ +#define SAMPLE_APP_BUILD_NUMBER 65 /*!< Development Build: Number of commits since baseline */ #define SAMPLE_APP_BUILD_BASELINE \ "v1.3.0-rc4" /*!< Development Build: git tag that is the base for the current development */ diff --git a/fsw/tables/sample_app_tbl.c b/fsw/tables/sample_app_tbl.c index c380534..c36c412 100644 --- a/fsw/tables/sample_app_tbl.c +++ b/fsw/tables/sample_app_tbl.c @@ -23,13 +23,13 @@ ** The following is an example of the declaration statement that defines the desired ** contents of the table image. */ -SAMPLE_APP_Table_t SampleAppTable = {1, 2}; +SAMPLE_APP_ExampleTable_t ExampleTable = {1, 2}; /* ** The macro below identifies: ** 1) the data structure type to use as the table image format -** 2) the name of the table to be placed into the cFE Table File Header +** 2) the name of the table to be placed into the cFE Example Table File Header ** 3) a brief description of the contents of the file image ** 4) the desired name of the table image binary file that is cFE compatible */ -CFE_TBL_FILEDEF(SampleAppTable, SAMPLE_APP.SampleAppTable, Table Utility Test Table, sample_app_tbl.tbl) +CFE_TBL_FILEDEF(ExampleTable, SAMPLE_APP.ExampleTable, Table Utility Test Table, sample_app_tbl.tbl) diff --git a/mission_build.cmake b/mission_build.cmake index 9b7d460..1cbd57f 100644 --- a/mission_build.cmake +++ b/mission_build.cmake @@ -11,6 +11,7 @@ # The list of header files that control the SAMPLE_APP configuration set(SAMPLE_APP_MISSION_CONFIG_FILE_LIST sample_app_fcncodes.h + sample_app_interface_cfg.h sample_app_mission_cfg.h sample_app_perfids.h sample_app_msg.h @@ -24,6 +25,7 @@ set(SAMPLE_APP_MISSION_CONFIG_FILE_LIST if (CFE_EDS_ENABLED_BUILD) # In an EDS-based build, these files come generated from the EDS tool + set(SAMPLE_APP_CFGFILE_SRC_sample_app_interface_cfg "sample_app_eds_designparameters.h") set(SAMPLE_APP_CFGFILE_SRC_sample_app_tbldefs "sample_app_eds_typedefs.h") set(SAMPLE_APP_CFGFILE_SRC_sample_app_tblstruct "sample_app_eds_typedefs.h") set(SAMPLE_APP_CFGFILE_SRC_sample_app_msgdefs "sample_app_eds_typedefs.h") diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 224c97d..28c052e 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -7,38 +7,63 @@ # ################################################################## -# # # NOTE on the subdirectory structures here: # # - "inc" provides local header files shared between the coveragetest, # wrappers, and overrides source code units # - "coveragetest" contains source code for the actual unit test cases -# The primary objective is to get line/path coverage on the FSW +# The primary objective is to get line/path coverage on the FSW # code units. # - + # Use the UT assert public API, and allow direct # inclusion of source files that are normally private -include_directories(${PROJECT_SOURCE_DIR}/fsw/src) +include_directories(../fsw/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) -# Add a coverage test executable called "sample_app-ALL" that -# covers all of the functions in sample_app. -# -# Also note in a more complex app/lib the coverage test can also -# be broken down into smaller units (in which case one should use -# a unique suffix other than "ALL" for each unit). For example, -# OSAL implements a separate coverage test per source unit. -add_cfe_coverage_test(sample_app ALL - "coveragetest/coveragetest_sample_app.c" - "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app.c" - "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_cmds.c" - "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_utils.c" +add_cfe_coverage_stubs(sample_app + stubs/sample_app_global_stubs.c + stubs/sample_app_stubs.c + stubs/sample_app_cmds_stubs.c + stubs/sample_app_dispatch_stubs.c + stubs/sample_app_utils_stubs.c +) + +add_library(sample_app_ut_common STATIC + common/eventcheck.c + common/setup.c ) +target_include_directories(sample_app_ut_common PUBLIC common) +target_link_libraries(sample_app_ut_common core_api ut_assert) + + +# Generate a dedicated "testrunner" executable for each test file +# Accomplish this by cycling through all the app's source files, there must be +# a *_tests file for each +foreach(SRCFILE ${APP_SRC_FILES}) + + # Get the base sourcefile name as a module name without path or the + # extension, this will be used as the base name of the unit test file. + get_filename_component(UNIT_NAME "${SRCFILE}" NAME_WE) + + # Use the module name to make the test name by adding _tests to the end + set(TESTS_NAME "coveragetest_${UNIT_NAME}") + + # Make the test sourcefile name with unit test path and extension + set(TESTS_SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/coveragetest/${TESTS_NAME}.c") + + # Create the coverage test executable + add_cfe_coverage_test(sample_app "${UNIT_NAME}" "${TESTS_SOURCE_FILE}" "../${SRCFILE}") + add_cfe_coverage_dependency(sample_app "${UNIT_NAME}" sample_app) + target_link_libraries(coverage-sample_app-${UNIT_NAME}-testrunner coverage-sample_app-stubs sample_app_ut_common) + +endforeach() + + + # The sample_app uses library functions provided by sample_lib so must be linked -# with the sample_lib stub library (this is mainly just an example of how this +# with the sample_lib stub library (this is mainly just an example of how this # can be done). -add_cfe_coverage_dependency(sample_app ALL sample_lib) - +add_cfe_coverage_dependency(sample_app sample_app_cmds sample_lib) diff --git a/unit-test/common/eventcheck.c b/unit-test/common/eventcheck.c new file mode 100644 index 0000000..5bb23ee --- /dev/null +++ b/unit-test/common/eventcheck.c @@ -0,0 +1,128 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** File: coveragetest_sample_app.c +** +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ +#include "common_types.h" +#include "cfe_evs.h" + +#include "eventcheck.h" + +#include "utassert.h" +#include "uttest.h" +#include "utstubs.h" + +/* + * 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, + va_list va) +{ + UT_CheckEvent_t *State = UserObj; + uint16 EventId; + const char * Spec; + + /* + * The CFE_EVS_SendEvent stub passes the EventID as the + * first context argument. + */ + if (Context->ArgCount > 0) + { + EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16); + if (EventId == State->ExpectedEvent) + { + if (State->ExpectedFormat != NULL) + { + Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *); + if (Spec != NULL) + { + /* + * Example of how to validate the full argument set. + * ------------------------------------------------ + * + * If really desired one can call something like: + * + * char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; + * vsnprintf(TestText, sizeof(TestText), Spec, va); + * + * And then compare the output (TestText) to the expected fully-rendered string. + * + * 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 type of check has been demonstrated to make tests very fragile, + * because it is influenced by many factors outside the control of the + * test case. + * + * __This derived string is not an actual output of the unit under test__ + */ + if (strcmp(Spec, State->ExpectedFormat) == 0) + { + ++State->MatchCount; + } + } + } + else + { + ++State->MatchCount; + } + } + } + + return 0; +} + +/* + * Helper function to set up for event checking + * This attaches the hook function to CFE_EVS_SendEvent + */ +void UT_CheckEvent_Setup_Impl(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *EventName, + const char *ExpectedFormat) +{ + if (ExpectedFormat == NULL) + { + UtPrintf("CheckEvent will match: %s(%u)", EventName, ExpectedEvent); + } + else + { + UtPrintf("CheckEvent will match: %s(%u), \"%s\"", EventName, ExpectedEvent, ExpectedFormat); + } + memset(Evt, 0, sizeof(*Evt)); + Evt->ExpectedEvent = ExpectedEvent; + Evt->ExpectedFormat = ExpectedFormat; + UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); +} diff --git a/unit-test/common/eventcheck.h b/unit-test/common/eventcheck.h new file mode 100644 index 0000000..07168aa --- /dev/null +++ b/unit-test/common/eventcheck.h @@ -0,0 +1,64 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +#ifndef EVENTCHECK_H +#define EVENTCHECK_H + +#include "common_types.h" +#include "cfe_evs.h" + +#include "utassert.h" +#include "uttest.h" +#include "utstubs.h" + +/* + * Unit test check event hook information + */ +typedef struct +{ + uint16 ExpectedEvent; + uint32 MatchCount; + const char *ExpectedFormat; +} UT_CheckEvent_t; + +/* Macro to get expected event name */ +#define UT_CHECKEVENT_SETUP(Evt, ExpectedEvent, ExpectedFormat) \ + UT_CheckEvent_Setup_Impl(Evt, ExpectedEvent, #ExpectedEvent, ExpectedFormat) + +/* + * Helper function to set up for event checking + * This attaches the hook function to CFE_EVS_SendEvent + */ +void UT_CheckEvent_Setup_Impl(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *EventName, + const char *ExpectedFormat); + +#endif diff --git a/unit-test/common/setup.c b/unit-test/common/setup.c new file mode 100644 index 0000000..9d6011e --- /dev/null +++ b/unit-test/common/setup.c @@ -0,0 +1,55 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ +#include "common_types.h" + +#include "setup.h" + +#include "utassert.h" +#include "uttest.h" +#include "utstubs.h" + +/* + * Setup function prior to every test + */ +void Sample_UT_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Teardown function after every test + */ +void Sample_UT_TearDown(void) {} diff --git a/unit-test/common/setup.h b/unit-test/common/setup.h new file mode 100644 index 0000000..a1ed825 --- /dev/null +++ b/unit-test/common/setup.h @@ -0,0 +1,45 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +#ifndef SETUP_H +#define SETUP_H + +#include "common_types.h" + +#include "utassert.h" +#include "uttest.h" +#include "utstubs.h" + +void Sample_UT_Setup(void); +void Sample_UT_TearDown(void); + +#endif diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 272476b..294cf71 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -37,104 +37,6 @@ */ #include "sample_lib.h" /* For SAMPLE_LIB_Function */ #include "sample_app_coveragetest_common.h" -#include "ut_sample_app.h" - -/* - * Unit test check event hook information - */ -typedef struct -{ - uint16 ExpectedEvent; - uint32 MatchCount; - const char *ExpectedFormat; -} 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, - va_list va) -{ - UT_CheckEvent_t *State = UserObj; - uint16 EventId; - const char * Spec; - - /* - * The CFE_EVS_SendEvent stub passes the EventID as the - * first context argument. - */ - if (Context->ArgCount > 0) - { - EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16); - if (EventId == State->ExpectedEvent) - { - if (State->ExpectedFormat != NULL) - { - Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *); - if (Spec != NULL) - { - /* - * Example of how to validate the full argument set. - * ------------------------------------------------ - * - * If really desired one can call something like: - * - * char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - * vsnprintf(TestText, sizeof(TestText), Spec, va); - * - * And then compare the output (TestText) to the expected fully-rendered string. - * - * 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 type of check has been demonstrated to make tests very fragile, - * because it is influenced by many factors outside the control of the - * test case. - * - * __This derived string is not an actual output of the unit under test__ - */ - if (strcmp(Spec, State->ExpectedFormat) == 0) - { - ++State->MatchCount; - } - } - } - else - { - ++State->MatchCount; - } - } - } - - return 0; -} - -/* Macro to get expected event name */ -#define UT_CHECKEVENT_SETUP(Evt, ExpectedEvent, ExpectedFormat) \ - UT_CheckEvent_Setup_Impl(Evt, ExpectedEvent, #ExpectedEvent, ExpectedFormat) - -/* - * Helper function to set up for event checking - * This attaches the hook function to CFE_EVS_SendEvent - */ -static void UT_CheckEvent_Setup_Impl(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *EventName, - const char *ExpectedFormat) -{ - if (ExpectedFormat == NULL) - { - UtPrintf("CheckEvent will match: %s(%u)", EventName, ExpectedEvent); - } - else - { - UtPrintf("CheckEvent will match: %s(%u), \"%s\"", EventName, ExpectedEvent, ExpectedFormat); - } - memset(Evt, 0, sizeof(*Evt)); - Evt->ExpectedEvent = ExpectedEvent; - Evt->ExpectedFormat = ExpectedFormat; - UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); -} /* ********************************************************************************** @@ -272,362 +174,6 @@ void Test_SAMPLE_APP_Init(void) UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 5); } -void Test_SAMPLE_APP_ProcessCommandPacket(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_ProcessCommandPacket - */ - /* a buffer large enough for any command message */ - union - { - CFE_SB_Buffer_t SBBuf; - SAMPLE_APP_NoopCmd_t Noop; - } TestMsg; - CFE_SB_MsgId_t TestMsgId; - CFE_MSG_FcnCode_t FcnCode; - size_t MsgSize; - UT_CheckEvent_t EventTest; - - memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_MID_ERR_EID, "SAMPLE: invalid command packet,MID = 0x%x"); - - /* - * The CFE_MSG_GetMsgId() stub uses a data buffer to hold the - * message ID values to return. - */ - TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID); - FcnCode = SAMPLE_APP_NOOP_CC; - 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.SBBuf); - - TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - 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.SBBuf); - - /* - * Confirm that the event was generated only _once_ - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); -} - -void Test_SAMPLE_APP_ProcessGroundCommand(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_ProcessGroundCommand - */ - CFE_MSG_FcnCode_t FcnCode; - size_t Size; - - /* a buffer large enough for any command message */ - union - { - 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; - - memset(&TestMsg, 0, sizeof(TestMsg)); - - /* - * call with each of the supported command codes - * The CFE_MSG_GetFcnCode stub allows the code to be - * set to whatever is needed. There is no return - * value here and the actual implementation of these - * commands have separate test cases, so this just - * needs to exercise the "switch" statement. - */ - - /* test dispatch of NOOP */ - FcnCode = SAMPLE_APP_NOOP_CC; - Size = sizeof(TestMsg.Noop); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_NOOP_INF_EID, NULL); - - SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); - - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); - - /* test dispatch of RESET */ - FcnCode = SAMPLE_APP_RESET_COUNTERS_CC; - Size = sizeof(TestMsg.Reset); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_RESET_INF_EID, NULL); - - SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); - - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); - - /* test dispatch of PROCESS */ - /* note this will end up calling SAMPLE_APP_Process(), and as such it needs to - * avoid dereferencing a table which does not exist. */ - FcnCode = SAMPLE_APP_PROCESS_CC; - Size = sizeof(TestMsg.Process); - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); - 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.SBBuf); - - /* test an invalid CC */ - FcnCode = 1000; - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CC_ERR_EID, "Invalid ground command code: CC = %d"); - SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); - - /* - * Confirm that the event was generated only _once_ - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); -} - -void Test_SAMPLE_APP_ReportHousekeeping(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg ) - */ - CFE_MSG_Message_t *MsgSend; - CFE_MSG_Message_t *MsgTimestamp; - CFE_SB_MsgId_t MsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID); - - /* Set message id to return so SAMPLE_APP_Housekeeping will be called */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); - - /* Set up to capture send message address */ - 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_SB_Buffer_t *)NULL); - - /* Confirm message sent*/ - UtAssert_STUB_COUNT(CFE_SB_TransmitMsg, 1); - UtAssert_ADDRESS_EQ(MsgSend, &SAMPLE_APP_Data.HkTlm); - - /* Confirm timestamp msg address */ - UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 1); - UtAssert_ADDRESS_EQ(MsgTimestamp, &SAMPLE_APP_Data.HkTlm); - - /* - * Confirm that the CFE_TBL_Manage() call was done - */ - UtAssert_STUB_COUNT(CFE_TBL_Manage, 1); -} - -void Test_SAMPLE_APP_NoopCmd(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_NoopCmd( const SAMPLE_APP_Noop_t *Msg ) - */ - SAMPLE_APP_NoopCmd_t TestMsg; - UT_CheckEvent_t EventTest; - - memset(&TestMsg, 0, sizeof(TestMsg)); - - /* test dispatch of NOOP */ - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_NOOP_INF_EID, NULL); - - UtAssert_INT32_EQ(SAMPLE_APP_Noop(&TestMsg), CFE_SUCCESS); - - /* - * Confirm that the event was generated - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); -} - -void Test_SAMPLE_APP_ResetCounters(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_ResetCounters( const SAMPLE_APP_ResetCounters_t *Msg ) - */ - SAMPLE_APP_ResetCountersCmd_t TestMsg; - UT_CheckEvent_t EventTest; - - memset(&TestMsg, 0, sizeof(TestMsg)); - - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_RESET_INF_EID, "SAMPLE: RESET command"); - - UtAssert_INT32_EQ(SAMPLE_APP_ResetCounters(&TestMsg), CFE_SUCCESS); - - /* - * Confirm that the event was generated - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); -} - -void Test_SAMPLE_APP_ProcessCC(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_ProcessCC( const SAMPLE_APP_Process_t *Msg ) - */ - SAMPLE_APP_ProcessCmd_t TestMsg; - SAMPLE_APP_Table_t TestTblData; - void * TblPtr = &TestTblData; - - memset(&TestTblData, 0, sizeof(TestTblData)); - memset(&TestMsg, 0, sizeof(TestMsg)); - - /* Provide some table data for the SAMPLE_APP_Process() function to use */ - TestTblData.Int1 = 40; - TestTblData.Int2 = 50; - UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); - UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_SUCCESS); - - /* - * Successful operation results in two calls to CFE_ES_WriteToSysLog() - one - * in this function reporting the table values, and one through - * SAMPLE_APP_GetCrc(). - */ - UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2); - - /* - * Confirm that the CFE_TBL_GetAddress() call was done - */ - UtAssert_STUB_COUNT(CFE_TBL_GetAddress, 1); - - /* - * Confirm that the SAMPLE_LIB_Function() call was done - * NOTE: This stub is provided by the sample_lib library - */ - UtAssert_STUB_COUNT(SAMPLE_LIB_Function, 1); - - /* - * Configure the CFE_TBL_GetAddress function to return an error. - * Exercise the error return path. - * Error at this point should add only one additional call to - * CFE_ES_WriteToSysLog() through the CFE_TBL_GetAddress() error path. - */ - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); - UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED); - UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 3); - - /* - * Configure CFE_TBL_ReleaseAddress() to return an error, exercising the - * error return path. - * Confirm three additional calls to CFE_ES_WriteToSysLog() - one - * reporting the table values, one through SAMPLE_APP_GetCrc() and one - * through the CFE_TBL_ReleaseAddress() error path. - */ - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_SUCCESS); - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), CFE_TBL_ERR_NO_ACCESS); - UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_TBL_ERR_NO_ACCESS); - UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 6); -} - -void Test_SAMPLE_APP_VerifyCmdLength(void) -{ - /* - * Test Case For: - * bool SAMPLE_APP_VerifyCmdLength - */ - UT_CheckEvent_t EventTest; - size_t size = 1; - CFE_MSG_FcnCode_t fcncode = 2; - CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(3); - - /* - * test a match case - */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CMD_LEN_ERR_EID, - "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u"); - - SAMPLE_APP_VerifyCmdLength(NULL, size); - - /* - * Confirm that the event was NOT generated - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 0); - - /* - * test a mismatch case - */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &fcncode, sizeof(fcncode), false); - SAMPLE_APP_VerifyCmdLength(NULL, size + 1); - - /* - * Confirm that the event WAS generated - */ - UtAssert_UINT32_EQ(EventTest.MatchCount, 1); -} - -void Test_SAMPLE_APP_TblValidationFunc(void) -{ - /* - * Test Case For: - * int32 SAMPLE_APP_TblValidationFunc( void *TblData ) - */ - SAMPLE_APP_Table_t TestTblData; - - memset(&TestTblData, 0, sizeof(TestTblData)); - - /* nominal case (0) should succeed */ - UtAssert_INT32_EQ(SAMPLE_APP_TblValidationFunc(&TestTblData), CFE_SUCCESS); - - /* error case should return SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE */ - TestTblData.Int1 = 1 + SAMPLE_APP_TBL_ELEMENT_1_MAX; - UtAssert_INT32_EQ(SAMPLE_APP_TblValidationFunc(&TestTblData), SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE); -} - -void Test_SAMPLE_APP_GetCrc(void) -{ - /* - * Test Case For: - * void SAMPLE_APP_GetCrc( const char *TableName ) - */ - - /* - * The only branch point here is CFE_TBL_GetInfo() - * - * Either way this function just does a write to syslog, - * and it is the same in both cases, just with - * a different message. This could actually verify - * the message using a hook function, if desired. - */ - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetInfo), CFE_TBL_ERR_INVALID_NAME); - SAMPLE_APP_GetCrc("UT"); - UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); - - UT_ClearDefaultReturnValue(UT_KEY(CFE_TBL_GetInfo)); - SAMPLE_APP_GetCrc("UT"); - UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2); -} - -/* - * Setup function prior to every test - */ -void Sample_UT_Setup(void) -{ - UT_ResetState(0); -} - -/* - * Teardown function after every test - */ -void Sample_UT_TearDown(void) {} - /* * Register the test cases to execute with the unit test tool */ @@ -635,13 +181,4 @@ void UtTest_Setup(void) { ADD_TEST(SAMPLE_APP_Main); ADD_TEST(SAMPLE_APP_Init); - ADD_TEST(SAMPLE_APP_ProcessCommandPacket); - ADD_TEST(SAMPLE_APP_ProcessGroundCommand); - ADD_TEST(SAMPLE_APP_ReportHousekeeping); - ADD_TEST(SAMPLE_APP_NoopCmd); - ADD_TEST(SAMPLE_APP_ResetCounters); - ADD_TEST(SAMPLE_APP_ProcessCC); - ADD_TEST(SAMPLE_APP_VerifyCmdLength); - ADD_TEST(SAMPLE_APP_TblValidationFunc); - ADD_TEST(SAMPLE_APP_GetCrc); } diff --git a/unit-test/coveragetest/coveragetest_sample_app_cmds.c b/unit-test/coveragetest/coveragetest_sample_app_cmds.c new file mode 100644 index 0000000..036dbc0 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_cmds.c @@ -0,0 +1,219 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** File: coveragetest_sample_app.c +** +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ + +#include "sample_lib.h" /* For SAMPLE_LIB_Function */ +#include "sample_app_coveragetest_common.h" +#include "sample_app.h" +#include "sample_app_dispatch.h" +#include "sample_app_cmds.h" + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ + +void Test_SAMPLE_APP_ReportHousekeeping(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg ) + */ + CFE_MSG_Message_t *MsgSend; + CFE_MSG_Message_t *MsgTimestamp; + + /* Set up to capture send message address */ + 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_SendHkCmd(NULL); + + /* Confirm message sent*/ + UtAssert_STUB_COUNT(CFE_SB_TransmitMsg, 1); + UtAssert_ADDRESS_EQ(MsgSend, &SAMPLE_APP_Data.HkTlm); + + /* Confirm timestamp msg address */ + UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 1); + UtAssert_ADDRESS_EQ(MsgTimestamp, &SAMPLE_APP_Data.HkTlm); + + /* + * Confirm that the CFE_TBL_Manage() call was done + */ + UtAssert_STUB_COUNT(CFE_TBL_Manage, 1); +} + +void Test_SAMPLE_APP_NoopCmd(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_NoopCmd( const SAMPLE_APP_Noop_t *Msg ) + */ + SAMPLE_APP_NoopCmd_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* test dispatch of NOOP */ + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_NOOP_INF_EID, NULL); + + UtAssert_INT32_EQ(SAMPLE_APP_NoopCmd(&TestMsg), CFE_SUCCESS); + + /* + * Confirm that the event was generated + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +void Test_SAMPLE_APP_ResetCountersCmd(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_ResetCounters( const SAMPLE_APP_ResetCounters_t *Msg ) + */ + SAMPLE_APP_ResetCountersCmd_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_RESET_INF_EID, "SAMPLE: RESET command"); + + UtAssert_INT32_EQ(SAMPLE_APP_ResetCountersCmd(&TestMsg), CFE_SUCCESS); + + /* + * Confirm that the event was generated + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +void Test_SAMPLE_APP_ProcessCmd(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_ProcessCmd( const SAMPLE_APP_ProcessCmd_t *Msg ) + */ + SAMPLE_APP_ProcessCmd_t TestMsg; + SAMPLE_APP_ExampleTable_t TestTblData; + void * TblPtr = &TestTblData; + + memset(&TestTblData, 0, sizeof(TestTblData)); + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* Provide some table data for the SAMPLE_APP_Process() function to use */ + TestTblData.Int1 = 40; + TestTblData.Int2 = 50; + UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); + UtAssert_INT32_EQ(SAMPLE_APP_ProcessCmd(&TestMsg), CFE_SUCCESS); + + /* + * This only needs to account for the call to CFE_ES_WriteToSysLog() directly + * invoked by the unit under test. Note that in this build environment, the + * SAMPLE_APP_GetCrc() function is a stub. + */ + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); + + /* + * Confirm that the CFE_TBL_GetAddress() call was done + */ + UtAssert_STUB_COUNT(CFE_TBL_GetAddress, 1); + + /* + * Confirm that the SAMPLE_LIB_Function() call was done + * NOTE: This stub is provided by the sample_lib library + */ + UtAssert_STUB_COUNT(SAMPLE_LIB_Function, 1); + + /* + * Configure the CFE_TBL_GetAddress function to return an error. + * Exercise the error return path. + * Error at this point should add only one additional call to + * CFE_ES_WriteToSysLog() through the CFE_TBL_GetAddress() error path. + */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); + UtAssert_INT32_EQ(SAMPLE_APP_ProcessCmd(&TestMsg), CFE_TBL_ERR_UNREGISTERED); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2); + + /* + * Configure CFE_TBL_ReleaseAddress() to return an error, exercising the + * error return path. + * Confirm two additional calls to CFE_ES_WriteToSysLog() - one + * reporting the table values, and one through the CFE_TBL_ReleaseAddress() + * error path. + */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), CFE_TBL_ERR_NO_ACCESS); + UtAssert_INT32_EQ(SAMPLE_APP_ProcessCmd(&TestMsg), CFE_TBL_ERR_NO_ACCESS); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 4); +} + +void Test_SAMPLE_APP_DisplayParamCmd(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_DisplayParamCmd( const SAMPLE_APP_DisplayParamCmd_t *Msg ) + */ + SAMPLE_APP_DisplayParamCmd_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_VALUE_INF_EID, "SAMPLE_APP: ValU32=%lu, ValI16=%d, ValStr=%s"); + TestMsg.Payload.ValU32 = 10; + TestMsg.Payload.ValI16 = -4; + snprintf(TestMsg.Payload.ValStr, sizeof(TestMsg.Payload.ValStr), "Hello"); + + UtAssert_INT32_EQ(SAMPLE_APP_DisplayParamCmd(&TestMsg), CFE_SUCCESS); + /* + * Confirm that the event was generated + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_APP_ReportHousekeeping); + ADD_TEST(SAMPLE_APP_NoopCmd); + ADD_TEST(SAMPLE_APP_ResetCountersCmd); + ADD_TEST(SAMPLE_APP_ProcessCmd); + ADD_TEST(SAMPLE_APP_DisplayParamCmd); +} diff --git a/unit-test/coveragetest/coveragetest_sample_app_dispatch.c b/unit-test/coveragetest/coveragetest_sample_app_dispatch.c new file mode 100644 index 0000000..a968286 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_dispatch.c @@ -0,0 +1,280 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** Purpose: +** Coverage Unit Test cases for the SAMPLE Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the SAMPLE application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ + +#include "sample_app_coveragetest_common.h" +#include "sample_app.h" +#include "sample_app_dispatch.h" +#include "sample_app_cmds.h" + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ + +void Test_SAMPLE_APP_TaskPipe(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_TaskPipe + */ + /* a buffer large enough for any command message */ + union + { + CFE_SB_Buffer_t SBBuf; + SAMPLE_APP_NoopCmd_t Noop; + } TestMsg; + CFE_SB_MsgId_t TestMsgId; + CFE_MSG_FcnCode_t FcnCode; + size_t MsgSize; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_MID_ERR_EID, "SAMPLE: invalid command packet,MID = 0x%x"); + + /* + * The CFE_MSG_GetMsgId() stub uses a data buffer to hold the + * message ID values to return. + */ + TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID); + FcnCode = SAMPLE_APP_NOOP_CC; + 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_TaskPipe(&TestMsg.SBBuf); + + TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); + SAMPLE_APP_TaskPipe(&TestMsg.SBBuf); + + /* invalid message id */ + TestMsgId = CFE_SB_INVALID_MSG_ID; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); + SAMPLE_APP_TaskPipe(&TestMsg.SBBuf); + + /* + * Confirm that the event was generated only _once_ + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +void Test_SAMPLE_APP_ProcessGroundCommand(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_ProcessGroundCommand + */ + CFE_MSG_FcnCode_t FcnCode; + size_t Size; + CFE_SB_MsgId_t MsgId = CFE_SB_ValueToMsgId(1); + + /* a buffer large enough for any command message */ + union + { + CFE_SB_Buffer_t SBBuf; + SAMPLE_APP_NoopCmd_t Noop; + SAMPLE_APP_ResetCountersCmd_t Reset; + SAMPLE_APP_ProcessCmd_t Process; + SAMPLE_APP_DisplayParamCmd_t DisplayParam; + } TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CMD_LEN_ERR_EID, + "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u"); + + /* + * call with each of the supported command codes + * The CFE_MSG_GetFcnCode stub allows the code to be + * set to whatever is needed. There is no return + * value here and the actual implementation of these + * commands have separate test cases, so this just + * needs to exercise the "switch" statement. + */ + + /* test dispatch of NOOP */ + FcnCode = SAMPLE_APP_NOOP_CC; + Size = sizeof(TestMsg.Noop); + 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.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_NoopCmd, 1); + + FcnCode = SAMPLE_APP_NOOP_CC; + Size = sizeof(TestMsg.Noop) - 1; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + + SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_NoopCmd, 1); + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); + + /* test dispatch of RESET */ + FcnCode = SAMPLE_APP_RESET_COUNTERS_CC; + Size = sizeof(TestMsg.Reset); + 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.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_ResetCountersCmd, 1); + + FcnCode = SAMPLE_APP_RESET_COUNTERS_CC; + Size = sizeof(TestMsg.Reset) - 1; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + + SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_ResetCountersCmd, 1); + UtAssert_UINT32_EQ(EventTest.MatchCount, 2); + + /* test dispatch of PROCESS */ + /* note this will end up calling SAMPLE_APP_Process(), and as such it needs to + * avoid dereferencing a table which does not exist. */ + FcnCode = SAMPLE_APP_PROCESS_CC; + Size = sizeof(TestMsg.Process); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); + 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.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_ProcessCmd, 1); + + FcnCode = SAMPLE_APP_PROCESS_CC; + Size = sizeof(TestMsg.Process) - 1; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + + SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_ProcessCmd, 1); + UtAssert_UINT32_EQ(EventTest.MatchCount, 3); + + /* test dispatch of DISPLAY_PARAM */ + FcnCode = SAMPLE_APP_DISPLAY_PARAM_CC; + Size = sizeof(TestMsg.DisplayParam); + 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.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_DisplayParamCmd, 1); + + FcnCode = SAMPLE_APP_DISPLAY_PARAM_CC; + Size = sizeof(TestMsg.DisplayParam) - 1; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); + + SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); + + UtAssert_STUB_COUNT(SAMPLE_APP_DisplayParamCmd, 1); + UtAssert_UINT32_EQ(EventTest.MatchCount, 4); + + /* test an invalid CC */ + FcnCode = 1000; + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CC_ERR_EID, "Invalid ground command code: CC = %d"); + SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); + + /* + * Confirm that the event was generated only _once_ + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +void Test_SAMPLE_APP_VerifyCmdLength(void) +{ + /* + * Test Case For: + * bool SAMPLE_APP_VerifyCmdLength + */ + UT_CheckEvent_t EventTest; + size_t size = 1; + CFE_MSG_FcnCode_t fcncode = 2; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(3); + + /* + * test a match case + */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CMD_LEN_ERR_EID, + "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u"); + + SAMPLE_APP_VerifyCmdLength(NULL, size); + + /* + * Confirm that the event was NOT generated + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 0); + + /* + * test a mismatch case + */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &fcncode, sizeof(fcncode), false); + SAMPLE_APP_VerifyCmdLength(NULL, size + 1); + + /* + * Confirm that the event WAS generated + */ + UtAssert_UINT32_EQ(EventTest.MatchCount, 1); +} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_APP_TaskPipe); + ADD_TEST(SAMPLE_APP_ProcessGroundCommand); + ADD_TEST(SAMPLE_APP_VerifyCmdLength); +} diff --git a/unit-test/coveragetest/coveragetest_sample_app_utils.c b/unit-test/coveragetest/coveragetest_sample_app_utils.c new file mode 100644 index 0000000..72b32e2 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_utils.c @@ -0,0 +1,97 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** File: coveragetest_sample_app.c +** +** Purpose: +** Coverage Unit Test cases for the Sample Application +** +** Notes: +** This implements various test cases to exercise all code +** paths through all functions defined in the Sample application. +** +** It is primarily focused at providing examples of the various +** stub configurations, hook functions, and wrapper calls that +** are often needed when coercing certain code paths through +** complex functions. +*/ + +/* + * Includes + */ +#include "sample_lib.h" /* For SAMPLE_LIB_Function */ +#include "sample_app_coveragetest_common.h" + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ + +void Test_SAMPLE_APP_TblValidationFunc(void) +{ + /* + * Test Case For: + * int32 SAMPLE_APP_TblValidationFunc( void *TblData ) + */ + SAMPLE_APP_ExampleTable_t TestTblData; + + memset(&TestTblData, 0, sizeof(TestTblData)); + + /* nominal case (0) should succeed */ + UtAssert_INT32_EQ(SAMPLE_APP_TblValidationFunc(&TestTblData), CFE_SUCCESS); + + /* error case should return SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE */ + TestTblData.Int1 = 1 + SAMPLE_APP_TBL_ELEMENT_1_MAX; + UtAssert_INT32_EQ(SAMPLE_APP_TblValidationFunc(&TestTblData), SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE); +} + +void Test_SAMPLE_APP_GetCrc(void) +{ + /* + * Test Case For: + * void SAMPLE_APP_GetCrc( const char *TableName ) + */ + + /* + * The only branch point here is CFE_TBL_GetInfo() + * + * Either way this function just does a write to syslog, + * and it is the same in both cases, just with + * a different message. This could actually verify + * the message using a hook function, if desired. + */ + + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetInfo), CFE_TBL_ERR_INVALID_NAME); + SAMPLE_APP_GetCrc("UT"); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); + + UT_ClearDefaultReturnValue(UT_KEY(CFE_TBL_GetInfo)); + SAMPLE_APP_GetCrc("UT"); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2); +} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_APP_TblValidationFunc); + ADD_TEST(SAMPLE_APP_GetCrc); +} diff --git a/unit-test/coveragetest/sample_app_coveragetest_common.h b/unit-test/coveragetest/sample_app_coveragetest_common.h index e571cb5..792ee5b 100644 --- a/unit-test/coveragetest/sample_app_coveragetest_common.h +++ b/unit-test/coveragetest/sample_app_coveragetest_common.h @@ -33,11 +33,17 @@ #include "uttest.h" #include "utstubs.h" +#include "setup.h" +#include "eventcheck.h" + #include "cfe.h" #include "sample_app_eventids.h" #include "sample_app.h" +#include "sample_app_dispatch.h" #include "sample_app_cmds.h" #include "sample_app_utils.h" +#include "sample_app_msgids.h" +#include "sample_app_msg.h" #include "sample_app_tbl.h" /* @@ -45,14 +51,4 @@ */ #define ADD_TEST(test) UtTest_Add((Test_##test), Sample_UT_Setup, Sample_UT_TearDown, #test) -/* - * Setup function prior to every test - */ -void Sample_UT_Setup(void); - -/* - * Teardown function after every test - */ -void Sample_UT_TearDown(void); - #endif /* SAMPLE_APP_COVERAGETEST_COMMON_H */ diff --git a/unit-test/stubs/sample_app_cmds_stubs.c b/unit-test/stubs/sample_app_cmds_stubs.c new file mode 100644 index 0000000..bfa80ce --- /dev/null +++ b/unit-test/stubs/sample_app_cmds_stubs.c @@ -0,0 +1,106 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in sample_app_cmds header + */ + +#include "sample_app_cmds.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_DisplayParamCmd() + * ---------------------------------------------------- + */ +CFE_Status_t SAMPLE_APP_DisplayParamCmd(const SAMPLE_APP_DisplayParamCmd_t *Msg) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_DisplayParamCmd, CFE_Status_t); + + UT_GenStub_AddParam(SAMPLE_APP_DisplayParamCmd, const SAMPLE_APP_DisplayParamCmd_t *, Msg); + + UT_GenStub_Execute(SAMPLE_APP_DisplayParamCmd, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_DisplayParamCmd, CFE_Status_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_NoopCmd() + * ---------------------------------------------------- + */ +CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_NoopCmd, CFE_Status_t); + + UT_GenStub_AddParam(SAMPLE_APP_NoopCmd, const SAMPLE_APP_NoopCmd_t *, Msg); + + UT_GenStub_Execute(SAMPLE_APP_NoopCmd, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_NoopCmd, CFE_Status_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_ProcessCmd() + * ---------------------------------------------------- + */ +CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_ProcessCmd, CFE_Status_t); + + UT_GenStub_AddParam(SAMPLE_APP_ProcessCmd, const SAMPLE_APP_ProcessCmd_t *, Msg); + + UT_GenStub_Execute(SAMPLE_APP_ProcessCmd, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_ProcessCmd, CFE_Status_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_ResetCountersCmd() + * ---------------------------------------------------- + */ +CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_ResetCountersCmd, CFE_Status_t); + + UT_GenStub_AddParam(SAMPLE_APP_ResetCountersCmd, const SAMPLE_APP_ResetCountersCmd_t *, Msg); + + UT_GenStub_Execute(SAMPLE_APP_ResetCountersCmd, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_ResetCountersCmd, CFE_Status_t); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_SendHkCmd() + * ---------------------------------------------------- + */ +CFE_Status_t SAMPLE_APP_SendHkCmd(const SAMPLE_APP_SendHkCmd_t *Msg) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_SendHkCmd, CFE_Status_t); + + UT_GenStub_AddParam(SAMPLE_APP_SendHkCmd, const SAMPLE_APP_SendHkCmd_t *, Msg); + + UT_GenStub_Execute(SAMPLE_APP_SendHkCmd, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_SendHkCmd, CFE_Status_t); +} diff --git a/unit-test/stubs/sample_app_dispatch_stubs.c b/unit-test/stubs/sample_app_dispatch_stubs.c new file mode 100644 index 0000000..7d956f4 --- /dev/null +++ b/unit-test/stubs/sample_app_dispatch_stubs.c @@ -0,0 +1,67 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in sample_app_dispatch header + */ + +#include "sample_app_dispatch.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_ProcessGroundCommand() + * ---------------------------------------------------- + */ +void SAMPLE_APP_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr) +{ + UT_GenStub_AddParam(SAMPLE_APP_ProcessGroundCommand, const CFE_SB_Buffer_t *, SBBufPtr); + + UT_GenStub_Execute(SAMPLE_APP_ProcessGroundCommand, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_TaskPipe() + * ---------------------------------------------------- + */ +void SAMPLE_APP_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + UT_GenStub_AddParam(SAMPLE_APP_TaskPipe, const CFE_SB_Buffer_t *, SBBufPtr); + + UT_GenStub_Execute(SAMPLE_APP_TaskPipe, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_VerifyCmdLength() + * ---------------------------------------------------- + */ +bool SAMPLE_APP_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_VerifyCmdLength, bool); + + UT_GenStub_AddParam(SAMPLE_APP_VerifyCmdLength, const CFE_MSG_Message_t *, MsgPtr); + UT_GenStub_AddParam(SAMPLE_APP_VerifyCmdLength, size_t, ExpectedLength); + + UT_GenStub_Execute(SAMPLE_APP_VerifyCmdLength, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_VerifyCmdLength, bool); +} diff --git a/unit-test/stubs/sample_app_global_stubs.c b/unit-test/stubs/sample_app_global_stubs.c new file mode 100644 index 0000000..c80a9d0 --- /dev/null +++ b/unit-test/stubs/sample_app_global_stubs.c @@ -0,0 +1,27 @@ +/************************************************************************ + * NASA Docket No. GSC-18,920-1, and identified as “Core Flight + * System (cFS) Health & Safety (HS) Application version 2.4.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +#include "sample_app.h" + +/* UT includes */ +#include "uttest.h" +#include "utassert.h" +#include "utstubs.h" + +SAMPLE_APP_Data_t SAMPLE_APP_Data; diff --git a/unit-test/inc/ut_sample_app.h b/unit-test/stubs/sample_app_stubs.c similarity index 58% rename from unit-test/inc/ut_sample_app.h rename to unit-test/stubs/sample_app_stubs.c index 858ef29..4001c1b 100644 --- a/unit-test/inc/ut_sample_app.h +++ b/unit-test/stubs/sample_app_stubs.c @@ -19,32 +19,33 @@ /** * @file * - * - * Purpose: - * Extra scaffolding functions for the sample_app unit test - * - * Notes: - * This is an extra UT-specific extern declaration - * to obtain access to an internal data structure - * - * UT often needs to modify internal data structures in ways that - * actual applications never would (bypassing the normal API) in - * order to exercise or set up for off-nominal cases. + * Auto-Generated stub implementations for functions defined in sample_app header */ -#ifndef UT_SAMPLE_APP_H -#define UT_SAMPLE_APP_H +#include "sample_app.h" +#include "utgenstub.h" /* - * Necessary to include these here to get the definition of the - * "SAMPLE_APP_Data_t" typedef. + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_Init() + * ---------------------------------------------------- */ -#include "sample_app_eventids.h" -#include "sample_app.h" +int32 SAMPLE_APP_Init(void) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_Init, int32); + + UT_GenStub_Execute(SAMPLE_APP_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_Init, int32); +} /* - * Allow UT access to the global "SAMPLE_APP_Data" object. + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_Main() + * ---------------------------------------------------- */ -extern SAMPLE_APP_Data_t SAMPLE_APP_Data; +void SAMPLE_APP_Main(void) +{ -#endif /* UT_SAMPLE_APP_H */ + UT_GenStub_Execute(SAMPLE_APP_Main, Basic, NULL); +} diff --git a/unit-test/stubs/sample_app_utils_stubs.c b/unit-test/stubs/sample_app_utils_stubs.c new file mode 100644 index 0000000..346a29a --- /dev/null +++ b/unit-test/stubs/sample_app_utils_stubs.c @@ -0,0 +1,54 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in sample_app_utils header + */ + +#include "sample_app_utils.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_GetCrc() + * ---------------------------------------------------- + */ +void SAMPLE_APP_GetCrc(const char *TableName) +{ + UT_GenStub_AddParam(SAMPLE_APP_GetCrc, const char *, TableName); + + UT_GenStub_Execute(SAMPLE_APP_GetCrc, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for SAMPLE_APP_TblValidationFunc() + * ---------------------------------------------------- + */ +int32 SAMPLE_APP_TblValidationFunc(void *TblData) +{ + UT_GenStub_SetupReturnBuffer(SAMPLE_APP_TblValidationFunc, int32); + + UT_GenStub_AddParam(SAMPLE_APP_TblValidationFunc, void *, TblData); + + UT_GenStub_Execute(SAMPLE_APP_TblValidationFunc, Basic, NULL); + + return UT_GenStub_GetReturnValue(SAMPLE_APP_TblValidationFunc, int32); +}