diff --git a/CHANGELOG.md b/CHANGELOG.md index bfbc057..1024d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # Changelog +## Development Build: equuleus-rc1+dev36 +- updating sample_app to use new versioning system +- See + +## Development Build: v1.3.0-rc4+dev69 +- define msgids via topicids +- See + +## Development Build: v1.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 +- Refactor SAMPLE_APP_Init/Process to remove multiple returns +- Add test for missing branch in SAMPLE_APP_Process() +- Zero out global data structure during initialization +- Move cmds and utils into separate files +- organize source files according to current patterns +- See , , , , , , and + +## Development Build: v1.3.0-rc4+dev39 +- update cmake recipe +- See + ## Development Build: v1.3.0-rc4+dev35 - Remove redundant comments - Create CHANGELOG.md diff --git a/CMakeLists.txt b/CMakeLists.txt index b3dd1a9..0eb9caf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,31 @@ project(CFE_SAMPLE_APP C) -include_directories(fsw/mission_inc) -include_directories(fsw/platform_inc) - -# Create the app module -add_cfe_app(sample_app +set(APP_SRC_FILES fsw/src/sample_app.c - fsw/src/sample_app_dispatch.c + fsw/src/sample_app_cmds.c + fsw/src/sample_app_utils.c ) +if (CFE_EDS_ENABLED_BUILD) + list(APPEND APP_SRC_FILES + fsw/src/sample_app_eds_dispatch.c + ) +else() + list(APPEND APP_SRC_FILES + fsw/src/sample_app_dispatch.c + ) +endif() + +# Create the app module +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 # to call library-provided functions add_cfe_app_dependency(sample_app sample_lib scriptengine) # Add table -add_cfe_tables(sampleAppTable fsw/tables/sample_app_tbl.c) +add_cfe_tables(sample_app fsw/tables/sample_app_tbl.c) # If UT is enabled, then add the tests from the subdirectory # Note that this is an app, and therefore does not provide diff --git a/arch_build.cmake b/arch_build.cmake new file mode 100644 index 0000000..c526397 --- /dev/null +++ b/arch_build.cmake @@ -0,0 +1,33 @@ +########################################################### +# +# SAMPLE_APP platform build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# The list of header files that control the SAMPLE_APP configuration +set(SAMPLE_APP_PLATFORM_CONFIG_FILE_LIST + sample_app_internal_cfg.h + sample_app_platform_cfg.h + sample_app_perfids.h + sample_app_msgids.h +) + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(SAMPLE_APP_CFGFILE ${SAMPLE_APP_PLATFORM_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${SAMPLE_APP_CFGFILE}" NAME_WE) + if (DEFINED SAMPLE_APP_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE GENERATED_FILE "${SAMPLE_APP_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${SAMPLE_APP_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${SAMPLE_APP_CFGFILE}" + ${DEFAULT_SOURCE} + ) +endforeach() diff --git a/config/default_sample_app_fcncodes.h b/config/default_sample_app_fcncodes.h new file mode 100644 index 0000000..b701c1c --- /dev/null +++ b/config/default_sample_app_fcncodes.h @@ -0,0 +1,43 @@ +/************************************************************************ + * 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 + * Specification for the SAMPLE_APP command function codes + * + * @note + * This file should be strictly limited to the command/function code (CC) + * macro definitions. Other definitions such as enums, typedefs, or other + * macros should be placed in the msgdefs.h or msg.h files. + */ +#ifndef SAMPLE_APP_FCNCODES_H +#define SAMPLE_APP_FCNCODES_H + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/* +** Sample App command codes +*/ +#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 new file mode 100644 index 0000000..25d753f --- /dev/null +++ b/config/default_sample_app_internal_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 Private Config Definitions + * + * This provides default values for configurable items that are internal + * to this module and do NOT affect the interface(s) of this module. Changes + * to items in this file only affect the local module and will be transparent + * to external entities that are using the public interface(s). + * + * @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_INTERNAL_CFG_H +#define SAMPLE_APP_INTERNAL_CFG_H + +/***********************************************************************/ +#define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ + +#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Example Table(s) */ + +#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 + +#define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 + +#endif diff --git a/config/default_sample_app_mission_cfg.h b/config/default_sample_app_mission_cfg.h new file mode 100644 index 0000000..9c5d166 --- /dev/null +++ b/config/default_sample_app_mission_cfg.h @@ -0,0 +1,36 @@ +/************************************************************************ + * 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 Mission Configuration Header File + * + * This is a compatibility header for the "mission_cfg.h" file that has + * traditionally provided public config definitions for each CFS app. + * + * @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_MISSION_CFG_H +#define SAMPLE_APP_MISSION_CFG_H + +#include "sample_app_interface_cfg.h" + +#endif diff --git a/config/default_sample_app_msg.h b/config/default_sample_app_msg.h new file mode 100644 index 0000000..1d94e43 --- /dev/null +++ b/config/default_sample_app_msg.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 + * Specification for the SAMPLE_APP command and telemetry + * message data types. + * + * This is a compatibility header for the "sample_app_msg.h" file that has + * traditionally provided the message definitions for cFS apps. + * + * @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_MSG_H +#define SAMPLE_APP_MSG_H + +#include "sample_app_mission_cfg.h" +#include "sample_app_msgdefs.h" +#include "sample_app_msgstruct.h" + +#endif diff --git a/config/default_sample_app_msgdefs.h b/config/default_sample_app_msgdefs.h new file mode 100644 index 0000000..1e4d10e --- /dev/null +++ b/config/default_sample_app_msgdefs.h @@ -0,0 +1,51 @@ +/************************************************************************ + * 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 + * Specification for the SAMPLE_APP command and telemetry + * message constant definitions. + * + * For SAMPLE_APP this is only the function/command code definitions + */ +#ifndef SAMPLE_APP_MSGDEFS_H +#define SAMPLE_APP_MSGDEFS_H + +#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 SAMPLE_APP_HkTlm_Payload +{ + uint8 CommandErrorCounter; + uint8 CommandCounter; + uint8 spare[2]; +} SAMPLE_APP_HkTlm_Payload_t; + +#endif diff --git a/fsw/platform_inc/sample_app_msgids.h b/config/default_sample_app_msgids.h similarity index 67% rename from fsw/platform_inc/sample_app_msgids.h rename to config/default_sample_app_msgids.h index 9f6d598..d3c0c16 100644 --- a/fsw/platform_inc/sample_app_msgids.h +++ b/config/default_sample_app_msgids.h @@ -18,19 +18,16 @@ /** * @file - * - * Define Sample App Message IDs - * - * \note The Sample App assumes default configuration which uses V1 of message id implementation + * SAMPLE_APP Application Message IDs */ - #ifndef SAMPLE_APP_MSGIDS_H #define SAMPLE_APP_MSGIDS_H -#include "cfe_msgids.h" +#include "cfe_core_api_base_msgids.h" +#include "sample_app_topicids.h" -#define SAMPLE_APP_CMD_MID CFE_PLATFORM_CMD_TOPICID_TO_MID(CFE_MISSION_SAMPLE_APP_CMD_TOPICID) -#define SAMPLE_APP_SEND_HK_MID CFE_PLATFORM_CMD_TOPICID_TO_MID(CFE_MISSION_SAMPLE_APP_SEND_HK_TOPICID) -#define SAMPLE_APP_HK_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MID(CFE_MISSION_SAMPLE_APP_HK_TLM_TOPICID) +#define SAMPLE_APP_CMD_MID CFE_PLATFORM_CMD_TOPICID_TO_MIDV(CFE_MISSION_SAMPLE_APP_CMD_TOPICID) +#define SAMPLE_APP_SEND_HK_MID CFE_PLATFORM_CMD_TOPICID_TO_MIDV(CFE_MISSION_SAMPLE_APP_SEND_HK_TOPICID) +#define SAMPLE_APP_HK_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MIDV(CFE_MISSION_SAMPLE_APP_HK_TLM_TOPICID) -#endif /* SAMPLE_APP_MSGIDS_H */ +#endif diff --git a/config/default_sample_app_msgstruct.h b/config/default_sample_app_msgstruct.h new file mode 100644 index 0000000..03327c9 --- /dev/null +++ b/config/default_sample_app_msgstruct.h @@ -0,0 +1,85 @@ +/************************************************************************ + * 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 + * Specification for the SAMPLE_APP command and telemetry + * message data types. + * + * @note + * Constants and enumerated types related to these message structures + * are defined in sample_app_msgdefs.h. + */ +#ifndef SAMPLE_APP_MSGSTRUCT_H +#define SAMPLE_APP_MSGSTRUCT_H + +/************************************************************************ + * Includes + ************************************************************************/ + +#include "sample_app_mission_cfg.h" +#include "sample_app_msgdefs.h" +#include "cfe_msg_hdr.h" + +/*************************************************************************/ + +/* +** The following commands all share the "NoArgs" format +** +** They are each given their own type name matching the command name, which +** allows them to change independently in the future without changing the prototype +** of the handler function +*/ +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_NoopCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_ResetCountersCmd_t; + +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) +*/ + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_SendHkCmd_t; + +typedef struct +{ + CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry header */ + SAMPLE_APP_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */ +} SAMPLE_APP_HkTlm_t; + +#endif /* SAMPLE_APP_MSGSTRUCT_H */ diff --git a/fsw/mission_inc/sample_app_perfids.h b/config/default_sample_app_perfids.h similarity index 93% rename from fsw/mission_inc/sample_app_perfids.h rename to config/default_sample_app_perfids.h index d87ea64..5c83334 100644 --- a/fsw/mission_inc/sample_app_perfids.h +++ b/config/default_sample_app_perfids.h @@ -18,13 +18,11 @@ /** * @file - * - * Define Sample App Performance IDs + * Define TO Lab Performance IDs */ - #ifndef SAMPLE_APP_PERFIDS_H #define SAMPLE_APP_PERFIDS_H #define SAMPLE_APP_PERF_ID 91 -#endif /* SAMPLE_APP_PERFIDS_H */ +#endif diff --git a/config/default_sample_app_platform_cfg.h b/config/default_sample_app_platform_cfg.h new file mode 100644 index 0000000..d62a136 --- /dev/null +++ b/config/default_sample_app_platform_cfg.h @@ -0,0 +1,41 @@ +/************************************************************************ + * 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 Platform Configuration Header File + * + * This is a compatibility header for the "platform_cfg.h" file that has + * traditionally provided both public and private config definitions + * for each CFS app. + * + * These definitions are now provided in two separate files, one for + * the public/mission scope and one for internal scope. + * + * @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_PLATFORM_CFG_H +#define SAMPLE_APP_PLATFORM_CFG_H + +#include "sample_app_mission_cfg.h" +#include "sample_app_internal_cfg.h" + +#endif diff --git a/config/default_sample_app_tbl.h b/config/default_sample_app_tbl.h new file mode 100644 index 0000000..f62b974 --- /dev/null +++ b/config/default_sample_app_tbl.h @@ -0,0 +1,36 @@ +/************************************************************************ + * 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 + * Specification for the SAMPLE_APP table structures + * + * @note + * Constants and enumerated types related to these table structures + * are defined in sample_app_tbldefs.h. + */ +#ifndef SAMPLE_APP_TBL_H +#define SAMPLE_APP_TBL_H + +#include "sample_app_tbldefs.h" +#include "sample_app_tblstruct.h" + +/* Define filenames of default data images for tables */ +#define SAMPLE_APP_TABLE_FILE "/cf/sample_app_tbl.tbl" + +#endif diff --git a/config/default_sample_app_tbldefs.h b/config/default_sample_app_tbldefs.h new file mode 100644 index 0000000..d478f00 --- /dev/null +++ b/config/default_sample_app_tbldefs.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. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP table related + * constant definitions. + * + * @note + * These Macro definitions have been put in this file (instead of + * sample_app_tbl.h). DO NOT PUT ANY TYPEDEFS OR + * STRUCTURE DEFINITIONS IN THIS FILE! + * ADD THEM TO sample_app_tbl.h IF NEEDED! + */ +#ifndef SAMPLE_APP_TBLDEFS_H +#define SAMPLE_APP_TBLDEFS_H + +#include "common_types.h" +#include "sample_app_mission_cfg.h" + +/* +** Example Table structure +*/ +typedef struct +{ + uint16 Int1; + uint16 Int2; +} SAMPLE_APP_ExampleTable_t; + +#endif diff --git a/config/default_sample_app_tblstruct.h b/config/default_sample_app_tblstruct.h new file mode 100644 index 0000000..3cd7882 --- /dev/null +++ b/config/default_sample_app_tblstruct.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. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP table structures + * + * Provides default definitions for SAMPLE_APP table structures + * + * @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_TBLSTRUCT_H +#define SAMPLE_APP_TBLSTRUCT_H + +/************************************************************************* + * Includes + *************************************************************************/ +#include "sample_app_tbldefs.h" + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/************************************************************************* + * Type Definitions + *************************************************************************/ + +#endif diff --git a/fsw/src/sample_app_msg.h b/config/default_sample_app_topicids.h similarity index 77% rename from fsw/src/sample_app_msg.h rename to config/default_sample_app_topicids.h index 71f982a..c78676e 100644 --- a/fsw/src/sample_app_msg.h +++ b/config/default_sample_app_topicids.h @@ -18,21 +18,13 @@ /** * @file - * - * Define SAMPLE App Messages and info + * SAMPLE_APP Application Topic IDs */ +#ifndef SAMPLE_APP_TOPICIDS_H +#define SAMPLE_APP_TOPICIDS_H -#ifndef SAMPLE_APP_MSG_H -#define SAMPLE_APP_MSG_H - -/* - * EDS-defined function codes (*_CC) - */ -#include "sample_app_eds_cc.h" - -/* - * EDS-defined message data types - */ -#include "sample_app_eds_typedefs.h" +#define CFE_MISSION_SAMPLE_APP_CMD_TOPICID 0x82 +#define CFE_MISSION_SAMPLE_APP_SEND_HK_TOPICID 0x83 +#define CFE_MISSION_SAMPLE_APP_HK_TLM_TOPICID 0x83 -#endif /* SAMPLE_APP_MSG_H */ +#endif diff --git a/eds/sample_app.xml b/eds/sample_app.xml index 69ce153..bef70e6 100644 --- a/eds/sample_app.xml +++ b/eds/sample_app.xml @@ -39,6 +39,16 @@ + + + + + + + + + + @@ -46,6 +56,9 @@ + + + @@ -73,18 +86,27 @@ - + + + + + + + + + + - - + + @@ -104,7 +126,7 @@ - + diff --git a/fsw/src/sample_app_events.h b/fsw/inc/sample_app_eventids.h similarity index 73% rename from fsw/src/sample_app_events.h rename to fsw/inc/sample_app_eventids.h index 46e7aaf..06406d8 100644 --- a/fsw/src/sample_app_events.h +++ b/fsw/inc/sample_app_eventids.h @@ -19,19 +19,20 @@ /** * @file * - * Define SAMPLE App Events IDs + * Define Sample App Events IDs */ #ifndef SAMPLE_APP_EVENTS_H #define SAMPLE_APP_EVENTS_H -#define SAMPLE_APP_RESERVED_EID 0 -#define SAMPLE_APP_STARTUP_INF_EID 1 -#define SAMPLE_APP_COMMAND_ERR_EID 2 -#define SAMPLE_APP_COMMANDNOP_INF_EID 3 -#define SAMPLE_APP_COMMANDRST_INF_EID 4 -#define SAMPLE_APP_INVALID_MSGID_ERR_EID 5 -#define SAMPLE_APP_LEN_ERR_EID 6 -#define SAMPLE_APP_PIPE_ERR_EID 7 +#define SAMPLE_APP_RESERVED_EID 0 +#define SAMPLE_APP_INIT_INF_EID 1 +#define SAMPLE_APP_CC_ERR_EID 2 +#define SAMPLE_APP_NOOP_INF_EID 3 +#define SAMPLE_APP_RESET_INF_EID 4 +#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 b1c632b..869c34c 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -24,17 +24,13 @@ /* ** Include Files: */ -#include "sample_app_events.h" -#include "sample_app_version.h" #include "sample_app.h" -#include "sample_app_table.h" - -#include "cfe_mission_eds_parameters.h" -#include "scriptengine.h" - -/* The sample_lib module provides the SAMPLE_LIB_Function() prototype */ -#include -#include "sample_lib.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" +#include "sample_app_eventids.h" +#include "sample_app_dispatch.h" +#include "sample_app_tbl.h" +#include "sample_app_version.h" /* ** global data @@ -57,7 +53,7 @@ void SAMPLE_APP_Main(void) CFE_ES_PerfLogEntry(SAMPLE_APP_PERF_ID); /* - ** Perform application specific initialization + ** Perform application-specific initialization ** If the Initialization fails, set the RunStatus to ** CFE_ES_RunStatus_APP_ERROR and the App will not enter the RunLoop */ @@ -68,7 +64,7 @@ void SAMPLE_APP_Main(void) } /* - ** SAMPLE Runloop + ** Sample App Runloop */ while (CFE_ES_RunLoop(&SAMPLE_APP_Data.RunStatus) == true) { @@ -87,7 +83,7 @@ void SAMPLE_APP_Main(void) if (status == CFE_SUCCESS) { - SAMPLE_APP_ProcessCommandPacket(SBBufPtr); + SAMPLE_APP_TaskPipe(SBBufPtr); } else { @@ -114,14 +110,12 @@ void SAMPLE_APP_Main(void) int32 SAMPLE_APP_Init(void) { int32 status; + char VersionString[SAMPLE_APP_CFG_MAX_VERSION_STR_LEN]; - SAMPLE_APP_Data.RunStatus = CFE_ES_RunStatus_APP_RUN; + /* Zero out the global data structure */ + memset(&SAMPLE_APP_Data, 0, sizeof(SAMPLE_APP_Data)); - /* - ** Initialize app command execution counters - */ - SAMPLE_APP_Data.CmdCounter = 0; - SAMPLE_APP_Data.ErrCounter = 0; + SAMPLE_APP_Data.RunStatus = CFE_ES_RunStatus_APP_RUN; /* ** Initialize app configuration data @@ -138,233 +132,74 @@ int32 SAMPLE_APP_Init(void) if (status != CFE_SUCCESS) { CFE_ES_WriteToSysLog("Sample App: Error Registering Events, RC = 0x%08lX\n", (unsigned long)status); - return status; - } - - /* - ** Initialize housekeeping packet (clear user data area). - */ - CFE_MSG_Init(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(SAMPLE_APP_HK_TLM_MID), - sizeof(SAMPLE_APP_Data.HkTlm)); - - /* - ** Create Software Bus message pipe. - */ - status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName); - if (status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", (unsigned long)status); - return status; - } - - /* - ** Subscribe to Housekeeping request commands - */ - status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID), SAMPLE_APP_Data.CommandPipe); - if (status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", (unsigned long)status); - return status; } - - /* - ** Subscribe to ground command packets - */ - status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID), SAMPLE_APP_Data.CommandPipe); - if (status != CFE_SUCCESS) + else { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status); + /* + ** Initialize housekeeping packet (clear user data area). + */ + CFE_MSG_Init(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(SAMPLE_APP_HK_TLM_MID), + sizeof(SAMPLE_APP_Data.HkTlm)); - return status; + /* + ** Create Software Bus message pipe. + */ + status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", (unsigned long)status); + } } - /* - ** Register Table(s) - */ - status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_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); - - return status; - } - else + if (status == CFE_SUCCESS) { - status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); + /* + ** Subscribe to Housekeeping request commands + */ + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID), SAMPLE_APP_Data.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", (unsigned long)status); + } } - SCRIPTENGINE_LoadFile("./cf/handler.lua"); - - CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE App Initialized.%s", - SAMPLE_APP_VERSION_STRING); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* 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 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -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++) + if (status == CFE_SUCCESS) { - CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]); - } - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* SAMPLE NOOP commands */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) -{ - SAMPLE_APP_Data.CmdCounter++; - - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", - SAMPLE_APP_VERSION); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function resets all the global counter variables that are */ -/* part of the task telemetry. */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) -{ - SAMPLE_APP_Data.CmdCounter = 0; - SAMPLE_APP_Data.ErrCounter = 0; - - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function Process Ground Station Command */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) -{ - int32 status; - SAMPLE_APP_Table_t *TblPtr; - const char * TableName = "SAMPLE_APP.SampleAppTable"; - - /* Sample Use of Table */ - - status = CFE_TBL_GetAddress((void *)&TblPtr, SAMPLE_APP_Data.TblHandles[0]); + /* + ** Subscribe to ground command packets + */ + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID), SAMPLE_APP_Data.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status); + } - if (status < CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)status); - return status; } - CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); - - SAMPLE_APP_GetCrc(TableName); - - status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]); - if (status != CFE_SUCCESS) + if (status == CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)status); - return status; - } - - /* Invoke a function provided by SAMPLE_APP_LIB */ - SAMPLE_LIB_Function(); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* A simple example command that displays a passed-in value */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -int32 SAMPLE_APP_DoExample(const SAMPLE_APP_DoExampleCmd_t *Msg) -{ - CFE_ES_WriteToSysLog("%s: Command Value=%u", __func__, (unsigned int)Msg->Payload.Value); + /* + ** Register Example Table(s) + */ + 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 Example Table, RC = 0x%08lX\n", (unsigned long)status); + } + else + { + status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); + } - /* JPHFIX: Lua bindings need update to allow proper "const" objects */ - SCRIPTENGINE_CallFunctionArg("TestFunc2", (void*)&Msg->Payload, - EDS_INDEX(SAMPLE_APP), SAMPLE_APP_DoExample_Payload_DATADICTIONARY); + CFE_Config_GetVersionString(VersionString, SAMPLE_APP_CFG_MAX_VERSION_STR_LEN, "Sample App", + SAMPLE_APP_VERSION, SAMPLE_APP_BUILD_CODENAME, SAMPLE_APP_LAST_OFFICIAL); - return CFE_SUCCESS; -} + SCRIPTENGINE_LoadFile("./cf/handler.lua"); -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Verify contents of First Table buffer contents */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_TblValidationFunc(void *TblData) -{ - int32 ReturnCode = CFE_SUCCESS; - SAMPLE_APP_Table_t *TblDataPtr = (SAMPLE_APP_Table_t *)TblData; - - /* - ** Sample Table Validation - */ - if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX) - { - /* First element is out of range, return an appropriate error code */ - ReturnCode = SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE; + CFE_EVS_SendEvent(SAMPLE_APP_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "Sample App Initialized.%s", + VersionString); } - return ReturnCode; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Output CRC */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_APP_GetCrc(const char *TableName) -{ - int32 status; - uint32 Crc; - CFE_TBL_Info_t TblInfoPtr; - - status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); - if (status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info"); - } - else - { - Crc = TblInfoPtr.Crc; - CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc); - } + return status; } diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index e2e8170..c2cac81 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -19,7 +19,7 @@ /** * @file * - * Main header file for the SAMPLE application + * Main header file for the Sample application */ #ifndef SAMPLE_APP_H @@ -29,26 +29,15 @@ ** Required header files. */ #include "cfe.h" -#include "cfe_error.h" -#include "cfe_evs.h" -#include "cfe_sb.h" -#include "cfe_es.h" +#include "cfe_config.h" + +#include "sample_app_mission_cfg.h" +#include "sample_app_platform_cfg.h" #include "sample_app_perfids.h" #include "sample_app_msgids.h" #include "sample_app_msg.h" -/***********************************************************************/ -#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 filenames of default data images for tables */ -#define SAMPLE_APP_TABLE_FILE "/cf/sample_app_tbl.tbl" - -#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 - -#define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 /************************************************************************ ** Type Definitions *************************************************************************/ @@ -88,9 +77,11 @@ typedef struct CFE_TBL_Handle_t TblHandles[SAMPLE_APP_NUMBER_OF_TABLES]; } SAMPLE_APP_Data_t; +/* +** Global data structure +*/ extern SAMPLE_APP_Data_t SAMPLE_APP_Data; - /****************************************************************************/ /* ** Local function prototypes. @@ -100,14 +91,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); -int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg); -int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg); -int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg); -int32 SAMPLE_APP_DoExample(const SAMPLE_APP_DoExampleCmd_t *Msg); -int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg); -void SAMPLE_APP_GetCrc(const char *TableName); - -int32 SAMPLE_APP_TblValidationFunc(void *TblData); #endif /* SAMPLE_APP_H */ diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c new file mode 100644 index 0000000..6ccc2f4 --- /dev/null +++ b/fsw/src/sample_app_cmds.c @@ -0,0 +1,177 @@ +/************************************************************************ + * 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 Ground Command-handling functions + */ + +/* +** Include Files: +*/ +#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" +#include "sample_app_utils.h" +#include "sample_app_msg.h" + +/* 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 */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg) +{ + SAMPLE_APP_Data.CmdCounter++; + + CFE_EVS_SendEvent(SAMPLE_APP_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", + SAMPLE_APP_VERSION); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function resets all the global counter variables that are */ +/* part of the task telemetry. */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg) +{ + SAMPLE_APP_Data.CmdCounter = 0; + SAMPLE_APP_Data.ErrCounter = 0; + + CFE_EVS_SendEvent(SAMPLE_APP_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function Process Ground Station Command */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) +{ + int32 status; + void * TblAddr; + SAMPLE_APP_ExampleTable_t *TblPtr; + const char * TableName = "SAMPLE_APP.ExampleTable"; + + /* Sample Use of Example Table */ + + status = CFE_TBL_GetAddress(&TblAddr, SAMPLE_APP_Data.TblHandles[0]); + + if (status < CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)status); + return status; + } + + TblPtr = TblAddr; + CFE_ES_WriteToSysLog("Sample App: Example Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); + + SAMPLE_APP_GetCrc(TableName); + + status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)status); + return status; + } + + /* Invoke a function provided by SAMPLE_APP_LIB */ + SAMPLE_LIB_Function(); + + 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; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* A simple example command that displays a passed-in value */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +CFE_Status_t SAMPLE_APP_DoExample(const SAMPLE_APP_DoExampleCmd_t *Msg) +{ + CFE_ES_WriteToSysLog("%s: Command Value=%u", __func__, (unsigned int)Msg->Payload.Value); + + /* JPHFIX: Lua bindings need update to allow proper "const" objects */ + SCRIPTENGINE_CallFunctionArg("TestFunc2", (void*)&Msg->Payload, + EDS_INDEX(SAMPLE_APP), SAMPLE_APP_DoExample_Payload_DATADICTIONARY); + + return CFE_SUCCESS; +} + + diff --git a/fsw/src/sample_app_cmds.h b/fsw/src/sample_app_cmds.h new file mode 100644 index 0000000..63df4d7 --- /dev/null +++ b/fsw/src/sample_app_cmds.h @@ -0,0 +1,41 @@ +/************************************************************************ + * 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 prototypes for the Sample App Ground Command-handling functions + */ + +#ifndef SAMPLE_APP_CMDS_H +#define SAMPLE_APP_CMDS_H + +/* +** Required header files. +*/ +#include "cfe_error.h" +#include "sample_app_msg.h" + +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); +CFE_Status_t SAMPLE_APP_DoExample(const SAMPLE_APP_DoExampleCmd_t *Msg); + + +#endif /* SAMPLE_APP_CMDS_H */ diff --git a/fsw/src/sample_app_dispatch.c b/fsw/src/sample_app_dispatch.c index 93794e1..a7c7a69 100644 --- a/fsw/src/sample_app_dispatch.c +++ b/fsw/src/sample_app_dispatch.c @@ -1,66 +1,42 @@ -/******************************************************************************* -** -** GSC-18128-1, "Core Flight Executive Version 6.7" -** -** Copyright (c) 2006-2019 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.c -** -** Purpose: -** This file contains the source code for the Sample App. -** -*******************************************************************************/ +/************************************************************************ + * 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_events.h" #include "sample_app.h" - -#include "sample_app_eds_dispatcher.h" -#include "sample_app_eds_dictionary.h" - -/* - * Define a lookup table for SAMPLE app command codes - */ -static const SAMPLE_APP_Application_Component_Telecommand_DispatchTable_t SAMPLE_TC_DISPATCH_TABLE = -{ - .CMD = - { - .NoopCmd_indication = SAMPLE_APP_Noop, - .ResetCountersCmd_indication = SAMPLE_APP_ResetCounters, - .ProcessCmd_indication = SAMPLE_APP_Process, - .DoExampleCmd_indication = SAMPLE_APP_DoExample - }, - .SEND_HK = - { - .indication = SAMPLE_APP_ReportHousekeeping - } -}; +#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" /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: SAMPLE_APP_ProcessCommandPacket */ /* */ -/* Purpose: */ -/* This routine will process any packet that is received on the SAMPLE */ -/* command pipe. */ +/* Verify command packet length */ /* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +bool SAMPLE_APP_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) { CFE_Status_t Status; CFE_SB_MsgId_t MsgId; @@ -95,5 +71,4 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) "SAMPLE: Invalid ground command code: CC = %d", (int)MsgFc); } } - } diff --git a/fsw/platform_inc/sample_app_table.h b/fsw/src/sample_app_dispatch.h similarity index 68% rename from fsw/platform_inc/sample_app_table.h rename to fsw/src/sample_app_dispatch.h index 57db4f8..b3289e8 100644 --- a/fsw/platform_inc/sample_app_table.h +++ b/fsw/src/sample_app_dispatch.h @@ -19,21 +19,20 @@ /** * @file * - * Define sample app table + * Main header file for the SAMPLE application */ -#ifndef SAMPLE_APP_TABLE_H -#define SAMPLE_APP_TABLE_H - -#include "sample_app_eds_typedefs.h" +#ifndef SAMPLE_APP_DISPATCH_H +#define SAMPLE_APP_DISPATCH_H /* - * The EDS defines the table type name as "SampleAppTable" so it matches - * the runtime table name, but the source code refers to the type - * as SAMPLE_APP_Table_t - * - * This discrepancy can be worked around with a typedef for now - */ -typedef SAMPLE_APP_SampleAppTable_t SAMPLE_APP_Table_t; +** 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_TABLE_H */ +#endif /* SAMPLE_APP_DISPATCH_H */ diff --git a/fsw/src/sample_app_eds_dispatch.c b/fsw/src/sample_app_eds_dispatch.c new file mode 100644 index 0000000..345c30d --- /dev/null +++ b/fsw/src/sample_app_eds_dispatch.c @@ -0,0 +1,95 @@ +/************************************************************************ + * 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" + +#include "sample_app_eds_dispatcher.h" +#include "sample_app_eds_dictionary.h" + +/* + * Define a lookup table for SAMPLE app command codes + */ +/* clang-format off */ +static const EdsDispatchTable_SAMPLE_APP_Application_CFE_SB_Telecommand_t SAMPLE_TC_DISPATCH_TABLE = { + .CMD = { + .NoopCmd_indication = SAMPLE_APP_Noop, + .ResetCountersCmd_indication = SAMPLE_APP_ResetCounters, + .ProcessCmd_indication = SAMPLE_APP_Process, + .DisplayParamCmd_indication = SAMPLE_APP_DisplayParamCmd, + .DoExampleCmd_indication = SAMPLE_APP_DoExample + }, + .SEND_HK = { + .indication = SAMPLE_APP_SendHkCmd + } +}; +/* clang-format on */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* 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_Status_t Status; + CFE_SB_MsgId_t MsgId; + CFE_MSG_Size_t MsgSize; + CFE_MSG_FcnCode_t MsgFc; + + Status = EdsDispatch_SAMPLE_APP_Application_Telecommand(SBBufPtr, &SAMPLE_TC_DISPATCH_TABLE); + + if (Status != CFE_SUCCESS) + { + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); + CFE_MSG_GetSize(&SBBufPtr->Msg, &MsgSize); + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &MsgFc); + ++SAMPLE_APP_Data.ErrCounter; + + if (Status == CFE_STATUS_UNKNOWN_MSG_ID) + { + 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)); + } + else if (Status == CFE_STATUS_WRONG_MSG_LENGTH) + { + CFE_EVS_SendEvent(SAMPLE_APP_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)MsgFc, (unsigned int)MsgSize); + } + else + { + CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, + "SAMPLE: Invalid ground command code: CC = %d", (int)MsgFc); + } + } +} diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c new file mode 100644 index 0000000..0de14ea --- /dev/null +++ b/fsw/src/sample_app_utils.c @@ -0,0 +1,75 @@ +/************************************************************************ + * 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 utility functions + */ + +/* +** Include Files: +*/ +#include "sample_app.h" +#include "sample_app_eventids.h" +#include "sample_app_tbl.h" +#include "sample_app_utils.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Verify contents of First Example Table buffer contents */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_APP_TblValidationFunc(void *TblData) +{ + int32 ReturnCode = CFE_SUCCESS; + SAMPLE_APP_ExampleTable_t *TblDataPtr = (SAMPLE_APP_ExampleTable_t *)TblData; + + /* + ** Sample Example Table Validation + */ + if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX) + { + /* First element is out of range, return an appropriate error code */ + ReturnCode = SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE; + } + + return ReturnCode; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Output CRC */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_APP_GetCrc(const char *TableName) +{ + int32 status; + uint32 Crc; + CFE_TBL_Info_t TblInfoPtr; + + status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Getting Example Table Info"); + } + else + { + Crc = TblInfoPtr.Crc; + CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc); + } +} diff --git a/fsw/src/sample_app_utils.h b/fsw/src/sample_app_utils.h new file mode 100644 index 0000000..873962d --- /dev/null +++ b/fsw/src/sample_app_utils.h @@ -0,0 +1,35 @@ +/************************************************************************ + * 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 prototypes for the Sample App utility functions + */ + +#ifndef SAMPLE_APP_UTILS_H +#define SAMPLE_APP_UTILS_H + +/* +** Required header files. +*/ +#include "sample_app.h" + +int32 SAMPLE_APP_TblValidationFunc(void *TblData); +void SAMPLE_APP_GetCrc(const char *TableName); + +#endif /* SAMPLE_APP_UTILS_H */ \ No newline at end of file diff --git a/fsw/src/sample_app_version.h b/fsw/src/sample_app_version.h index 12d75bf..fd9349b 100644 --- a/fsw/src/sample_app_version.h +++ b/fsw/src/sample_app_version.h @@ -27,16 +27,22 @@ /* Development Build Macro Definitions */ -#define SAMPLE_APP_BUILD_NUMBER 35 /*!< 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 */ +#define SAMPLE_APP_BUILD_NUMBER 36 /*!< Development Build: Number of commits since baseline */ +#define SAMPLE_APP_BUILD_BASELINE "equuleus-rc1" /*!< Development Build: git tag that is the base for the current development */ +#define SAMPLE_APP_BUILD_DEV_CYCLE "equuleus-rc2" /**< @brief Development: Release name for current development cycle */ +#define SAMPLE_APP_BUILD_CODENAME "Equuleus" /**< @brief: Development: Code name for the current build */ /* * Version Macros, see \ref cfsversions for definitions. */ #define SAMPLE_APP_MAJOR_VERSION 1 /*!< @brief Major version number. */ #define SAMPLE_APP_MINOR_VERSION 1 /*!< @brief Minor version number. */ -#define SAMPLE_APP_REVISION 99 /*!< @brief Revision version number. Value of 99 indicates a development version.*/ +#define SAMPLE_APP_REVISION 0 /*!< @brief Revision version number. Value of 0 indicates a development version.*/ + +/** + * @brief Last official release. + */ +#define SAMPLE_APP_LAST_OFFICIAL "v1.1.0" /*! * @brief Mission revision. @@ -57,12 +63,12 @@ */ #define SAMPLE_APP_VERSION SAMPLE_APP_BUILD_BASELINE "+dev" SAMPLE_APP_STR(SAMPLE_APP_BUILD_NUMBER) -/*! @brief Development Build Version String. - * @details Reports the current development build's baseline, number, and name. Also includes a note about the latest - * official version. @n See @ref cfsversions for format differences between development and release versions. +/** + * @brief Max Version String length. + * + * Maximum length that an OSAL version string can be. + * */ -#define SAMPLE_APP_VERSION_STRING \ - " Sample App DEVELOPMENT BUILD " SAMPLE_APP_VERSION \ - ", Last Official Release: v1.1.0" /* For full support please use this version */ +#define SAMPLE_APP_CFG_MAX_VERSION_STR_LEN 256 #endif /* SAMPLE_APP_VERSION_H */ diff --git a/fsw/tables/sample_app_tbl.c b/fsw/tables/sample_app_tbl.c index 435409d..c36c412 100644 --- a/fsw/tables/sample_app_tbl.c +++ b/fsw/tables/sample_app_tbl.c @@ -17,19 +17,19 @@ ************************************************************************/ #include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */ -#include "sample_app_table.h" +#include "sample_app_tbl.h" /* ** 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 new file mode 100644 index 0000000..7c156c6 --- /dev/null +++ b/mission_build.cmake @@ -0,0 +1,52 @@ +########################################################### +# +# SAMPLE_APP mission build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# 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 + sample_app_msgdefs.h + sample_app_msgstruct.h + sample_app_tbl.h + sample_app_tbldefs.h + sample_app_tblstruct.h + sample_app_topicids.h +) + +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") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_msgstruct "sample_app_eds_typedefs.h") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_fcncodes "sample_app_eds_cc.h") + +endif(CFE_EDS_ENABLED_BUILD) + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(SAMPLE_APP_CFGFILE ${SAMPLE_APP_MISSION_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${SAMPLE_APP_CFGFILE}" NAME_WE) + if (DEFINED SAMPLE_APP_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE GENERATED_FILE "${SAMPLE_APP_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${SAMPLE_APP_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${SAMPLE_APP_CFGFILE}" + ${DEFAULT_SOURCE} + ) +endforeach() diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 3200470..28c052e 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -7,7 +7,6 @@ # ################################################################## -# # # NOTE on the subdirectory structures here: # @@ -20,24 +19,51 @@ # 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_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 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_dispatch.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 # 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 06b37fc..294cf71 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -20,11 +20,11 @@ ** File: coveragetest_sample_app.c ** ** Purpose: -** Coverage Unit Test cases for the SAMPLE Application +** 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. +** 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 @@ -35,107 +35,8 @@ /* * Includes */ - #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); -} /* ********************************************************************************** @@ -273,175 +174,6 @@ void Test_SAMPLE_APP_Init(void) UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 5); } -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_ReportHousekeeping(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_COMMANDNOP_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_COMMANDRST_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); - - /* - * 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 - */ - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); - UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED); -} - -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 */ @@ -449,10 +181,4 @@ void UtTest_Setup(void) { ADD_TEST(SAMPLE_APP_Main); ADD_TEST(SAMPLE_APP_Init); - ADD_TEST(SAMPLE_APP_ReportHousekeeping); - ADD_TEST(SAMPLE_APP_NoopCmd); - ADD_TEST(SAMPLE_APP_ResetCounters); - ADD_TEST(SAMPLE_APP_ProcessCC); - 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_eds_dispatch.c b/unit-test/coveragetest/coveragetest_sample_app_eds_dispatch.c new file mode 100644 index 0000000..1f06fa9 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_eds_dispatch.c @@ -0,0 +1,62 @@ +/************************************************************************ + * 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 + */ +} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_APP_TaskPipe); +} 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 134e2ca..792ee5b 100644 --- a/unit-test/coveragetest/sample_app_coveragetest_common.h +++ b/unit-test/coveragetest/sample_app_coveragetest_common.h @@ -33,24 +33,22 @@ #include "uttest.h" #include "utstubs.h" +#include "setup.h" +#include "eventcheck.h" + #include "cfe.h" -#include "sample_app_events.h" +#include "sample_app_eventids.h" #include "sample_app.h" -#include "sample_app_table.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" /* * Macro to add a test case to the list of tests to execute */ #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 ca8567e..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_events.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); +}