diff --git a/CMakeLists.txt b/CMakeLists.txt index e5514ac..683cf7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,9 @@ include_directories(fsw/platform_inc) include_directories(${sample_lib_MISSION_DIR}/fsw/public_inc) # Create the app module -add_cfe_app(sample_app fsw/src/sample_app.c) +add_cfe_app(sample_app fsw/src/sample_app.c + fsw/src/sample_app_cmds.c + fsw/src/sample_app_utils.c) # Add table add_cfe_tables(sampleTable fsw/src/sample_table.c) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 1686c5d..0ffc80b 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -32,6 +32,8 @@ #include "sample_app_version.h" #include "sample_app.h" #include "sample_table.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" /* The sample_lib module provides the SAMPLE_Function() prototype */ #include @@ -106,6 +108,13 @@ void SAMPLE_AppMain( void ) } + + CFE_EVS_SendEvent(SAMPLE_APP_EXIT_ERR_EID, + CFE_EVS_EventType_ERROR, + "SAMPLE_APP Terminating"); + + CFE_ES_WriteToSysLog("SAMPLE_APP Terminating."); + /* ** Performance Log Exit Stamp */ @@ -186,8 +195,10 @@ int32 SAMPLE_AppInit( void ) SAMPLE_AppData.PipeName); if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", - (unsigned long)status); + CFE_EVS_SendEvent(SAMPLE_APP_PIPE_CREATE_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error creating pipe, RC = 0x%08lX\n", + (unsigned long)status); return ( status ); } @@ -198,8 +209,10 @@ int32 SAMPLE_AppInit( void ) SAMPLE_AppData.CommandPipe); if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", - (unsigned long)status); + CFE_EVS_SendEvent(SAMPLE_APP_SUB_HK_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", + (unsigned long)status); return ( status ); } @@ -210,8 +223,10 @@ int32 SAMPLE_AppInit( void ) SAMPLE_AppData.CommandPipe); if (status != CFE_SUCCESS ) { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", - (unsigned long)status); + CFE_EVS_SendEvent(SAMPLE_APP_SUB_CMD_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error Subscribing to Command, RC = 0x%08lX\n", + (unsigned long)status); return ( status ); } @@ -226,8 +241,10 @@ int32 SAMPLE_AppInit( void ) SAMPLE_TblValidationFunc); if ( status != CFE_SUCCESS ) { - CFE_ES_WriteToSysLog("Sample App: Error Registering \ - Table, RC = 0x%08lX\n", (unsigned long)status); + CFE_EVS_SendEvent(SAMPLE_APP_TBL_REG_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error Registering Table, RC = 0x%08lX\n", + (unsigned long)status); return ( status ); } @@ -277,7 +294,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg ) default: CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID, CFE_EVS_EventType_ERROR, - "SAMPLE: invalid command packet,MID = 0x%x", + "SAMPLE: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId)); break; } @@ -294,7 +311,6 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg ) void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) { uint16 CommandCode; - CommandCode = CFE_SB_GetCmdCode(Msg); /* @@ -303,27 +319,24 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) switch (CommandCode) { case SAMPLE_APP_NOOP_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) - { + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + { SAMPLE_Noop((SAMPLE_Noop_t *)Msg); } - break; case SAMPLE_APP_RESET_COUNTERS_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) - { + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) + { SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); } - break; case SAMPLE_APP_PROCESS_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) - { + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) + { SAMPLE_Process((SAMPLE_Process_t *)Msg); } - break; /* default case already found during FC vs length test */ @@ -376,179 +389,5 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) } /* End of SAMPLE_ReportHousekeeping() */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* SAMPLE_Noop -- SAMPLE NOOP commands */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -int32 SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) -{ - - SAMPLE_AppData.CmdCounter++; - - CFE_EVS_SendEvent(SAMPLE_COMMANDNOP_INF_EID, - CFE_EVS_EventType_INFORMATION, - "SAMPLE: NOOP command Version %d.%d.%d.%d", - SAMPLE_APP_MAJOR_VERSION, - SAMPLE_APP_MINOR_VERSION, - SAMPLE_APP_REVISION, - SAMPLE_APP_MISSION_REV); - - return CFE_SUCCESS; - -} /* End of SAMPLE_Noop */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: SAMPLE_ResetCounters */ -/* */ -/* Purpose: */ -/* This function resets all the global counter variables that are */ -/* part of the task telemetry. */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) -{ - - SAMPLE_AppData.CmdCounter = 0; - SAMPLE_AppData.ErrCounter = 0; - - CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID, - CFE_EVS_EventType_INFORMATION, - "SAMPLE: RESET command"); - - return CFE_SUCCESS; - -} /* End of SAMPLE_ResetCounters() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: SAMPLE_Process */ -/* */ -/* Purpose: */ -/* This function Process Ground Station Command */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_Process( const SAMPLE_Process_t *Msg ) -{ - int32 status; - SAMPLE_Table_t *TblPtr; - const char *TableName = "SAMPLE_APP.SampleTable"; - - /* Sample Use of Table */ - - status = CFE_TBL_GetAddress((void *)&TblPtr, - SAMPLE_AppData.TblHandles[0]); - - 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_GetCrc(TableName); - - status = CFE_TBL_ReleaseAddress(SAMPLE_AppData.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_LIB */ - SAMPLE_Function(); - - return CFE_SUCCESS; - -} /* End of SAMPLE_ProcessCC */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* SAMPLE_VerifyCmdLength() -- Verify command packet length */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength ) -{ - bool result = true; - - uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg); - - /* - ** Verify the command packet length. - */ - if (ExpectedLength != ActualLength) - { - CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg); - uint16 CommandCode = CFE_SB_GetCmdCode(Msg); - - CFE_EVS_SendEvent(SAMPLE_LEN_ERR_EID, - CFE_EVS_EventType_ERROR, - "Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d", - (unsigned int)CFE_SB_MsgIdToValue(MessageID), - CommandCode, - ActualLength, - ExpectedLength); - result = false; - - SAMPLE_AppData.ErrCounter++; - } - - return( result ); - -} /* End of SAMPLE_VerifyCmdLength() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* SAMPLE_TblValidationFunc -- Verify contents of First Table */ -/* buffer contents */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_TblValidationFunc( void *TblData ) -{ - int32 ReturnCode = CFE_SUCCESS; - SAMPLE_Table_t *TblDataPtr = (SAMPLE_Table_t *)TblData; - - /* - ** Sample Table Validation - */ - if (TblDataPtr->Int1 > SAMPLE_TBL_ELEMENT_1_MAX) - { - /* First element is out of range, return an appropriate error code */ - ReturnCode = SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE; - } - - return ReturnCode; - -} /* End of Sample_TblValidationFunc*/ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* SAMPLE_GetCrc -- Output CRC */ -/* */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_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; -} /* End of SAMPLE_GetCrc */ diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index a7c2c47..74410c5 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -41,6 +41,8 @@ #include "sample_app_perfids.h" #include "sample_app_msgids.h" #include "sample_app_msg.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" /***********************************************************************/ #define SAMPLE_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ @@ -53,6 +55,7 @@ #define SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE -1 #define SAMPLE_TBL_ELEMENT_1_MAX 10 + /************************************************************************ ** Type Definitions *************************************************************************/ @@ -105,6 +108,8 @@ typedef struct } SAMPLE_AppData_t; +extern SAMPLE_AppData_t SAMPLE_AppData; + /****************************************************************************/ /* ** Local function prototypes. @@ -117,13 +122,5 @@ int32 SAMPLE_AppInit(void); void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg); void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg); int32 SAMPLE_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg); -int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); -int32 SAMPLE_Process(const SAMPLE_Process_t *Msg); -int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg); -void SAMPLE_GetCrc(const char *TableName); - -int32 SAMPLE_TblValidationFunc(void *TblData); - -bool SAMPLE_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength); #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..a1780c9 --- /dev/null +++ b/fsw/src/sample_app_cmds.c @@ -0,0 +1,148 @@ +/******************************************************************************* +** +** 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_cmds.c +** +** Purpose: +** This file contains the source code for the Sample App command handling +** functions. +** +*******************************************************************************/ + +/* +** Include Files: +*/ +#include "sample_app_events.h" +#include "sample_app_version.h" +#include "sample_app.h" +#include "sample_table.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" + +/* The sample_lib module provides the SAMPLE_Function() prototype */ +#include +#include "sample_lib.h" + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* SAMPLE_Noop -- SAMPLE NOOP commands */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +int32 SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) +{ + + SAMPLE_AppData.CmdCounter++; + + CFE_EVS_SendEvent(SAMPLE_COMMANDNOP_INF_EID, + CFE_EVS_EventType_INFORMATION, + "SAMPLE: NOOP command Version %d.%d.%d.%d", + SAMPLE_APP_MAJOR_VERSION, + SAMPLE_APP_MINOR_VERSION, + SAMPLE_APP_REVISION, + SAMPLE_APP_MISSION_REV); + + + return CFE_SUCCESS; + +} /* End of SAMPLE_Noop */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* Name: SAMPLE_ResetCounters */ +/* */ +/* Purpose: */ +/* This function resets all the global counter variables that are */ +/* part of the task telemetry. */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) +{ + + SAMPLE_AppData.CmdCounter = 0; + SAMPLE_AppData.ErrCounter = 0; + + CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID, + CFE_EVS_EventType_INFORMATION, + "SAMPLE: RESET command"); + + return CFE_SUCCESS; + +} /* End of SAMPLE_ResetCounters() */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* Name: SAMPLE_Process */ +/* */ +/* Purpose: */ +/* This function Process Ground Station Command */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_Process( const SAMPLE_Process_t *Msg ) +{ + int32 status; + SAMPLE_Table_t *TblPtr; + const char *TableName = "SAMPLE_APP.SampleTable"; + + + /* Sample Use of Table */ + + status = CFE_TBL_GetAddress((void *)&TblPtr, + SAMPLE_AppData.TblHandles[0]); + + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(SAMPLE_APP_TBL_ADDR_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Fail to get table address: 0x%08lx", + (unsigned long) status); + + SAMPLE_AppData.ErrCounter++; + return status; + } + + CFE_EVS_SendEvent(SAMPLE_APP_TBL_INF_EID, + CFE_EVS_EventType_INFORMATION, + "Sample App: Table Value 1: %d Value 2: %d", + TblPtr->Int1, + TblPtr->Int2); + + SAMPLE_GetCrc(TableName); + + status = CFE_TBL_ReleaseAddress(SAMPLE_AppData.TblHandles[0]); + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(SAMPLE_APP_TBL_REL_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Fail to release table address: 0x%08lx", + (unsigned long)status); + + SAMPLE_AppData.ErrCounter++; + return status; + } + + /* Invoke a function provided by SAMPLE_LIB */ + SAMPLE_Function(); + + SAMPLE_AppData.CmdCounter++; + + return CFE_SUCCESS; + +} /* End of SAMPLE_ProcessCC */ + + diff --git a/fsw/src/sample_app_cmds.h b/fsw/src/sample_app_cmds.h new file mode 100644 index 0000000..95ccb11 --- /dev/null +++ b/fsw/src/sample_app_cmds.h @@ -0,0 +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_cmds.h +** +** Purpose: +** This file contains prototypes for command handling functions +** for the SAMPLE application. +** +** +*******************************************************************************/ + +#ifndef _sample_app_cmds_h_ +#define _sample_app_cmds_h_ + +#include "sample_app.h" + + +int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg); + +int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); + +int32 SAMPLE_Process(const SAMPLE_Process_t *Msg); + +#endif /* _sample_app_cmds_h_ */ diff --git a/fsw/src/sample_app_events.h b/fsw/src/sample_app_events.h index b329ae0..0c175c5 100644 --- a/fsw/src/sample_app_events.h +++ b/fsw/src/sample_app_events.h @@ -38,8 +38,18 @@ #define SAMPLE_INVALID_MSGID_ERR_EID 5 #define SAMPLE_LEN_ERR_EID 6 #define SAMPLE_PIPE_ERR_EID 7 +#define SAMPLE_APP_EXIT_ERR_EID 8 +#define SAMPLE_APP_PIPE_CREATE_ERR_EID 9 +#define SAMPLE_APP_SUB_HK_ERR_EID 10 +#define SAMPLE_APP_SUB_CMD_ERR_EID 11 +#define SAMPLE_APP_TBL_REG_ERR_EID 12 +#define SAMPLE_APP_TBL_ADDR_ERR_EID 13 +#define SAMPLE_APP_TBL_INF_EID 14 +#define SAMPLE_APP_TBL_REL_ERR_EID 15 +#define SAMPLE_APP_TBL_GETINF_ERR_EID 16 +#define SAMPLE_APP_TBL_CRC_INF_EID 17 -#define SAMPLE_EVENT_COUNTS 7 +#define SAMPLE_EVENT_COUNTS 17 #endif /* _sample_app_events_h_ */ diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c new file mode 100644 index 0000000..c026630 --- /dev/null +++ b/fsw/src/sample_app_utils.c @@ -0,0 +1,133 @@ +/******************************************************************************* +** +** 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_utils.c +** +** Purpose: +** This file contains the source code for the Sample App utility functions. +** +*******************************************************************************/ + +/* +** Include Files: +*/ +#include "sample_app_events.h" +#include "sample_app_version.h" +#include "sample_app.h" +#include "sample_table.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" + +/* The sample_lib module provides the SAMPLE_Function() prototype */ +#include +#include "sample_lib.h" + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* SAMPLE_VerifyCmdLength() -- Verify command packet length */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength ) +{ + bool result = true; + + uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg); + + /* + ** Verify the command packet length. + */ + if (ExpectedLength != ActualLength) + { + CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg); + uint16 CommandCode = CFE_SB_GetCmdCode(Msg); + + CFE_EVS_SendEvent(SAMPLE_LEN_ERR_EID, + CFE_EVS_EventType_ERROR, + "Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d", + MessageID, + CommandCode, + ActualLength, + ExpectedLength); + + result = false; + + SAMPLE_AppData.ErrCounter++; + } + + return( result ); + +} /* End of SAMPLE_VerifyCmdLength() */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* SAMPLE_TblValidationFunc -- Verify contents of First Table */ +/* buffer contents */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_TblValidationFunc( void *TblData ) +{ + int32 ReturnCode = CFE_SUCCESS; + SAMPLE_Table_t *TblDataPtr = (SAMPLE_Table_t *)TblData; + + /* + ** Sample Table Validation + */ + if (TblDataPtr->Int1 > SAMPLE_TBL_ELEMENT_1_MAX) + { + /* First element is out of range, return an appropriate error code */ + ReturnCode = SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE; + } + + return ReturnCode; + +} /* End of Sample_TblValidationFunc*/ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* SAMPLE_GetCrc -- Output CRC */ +/* */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_GetCrc( const char *TableName ) +{ + int32 status; + uint32 Crc; + CFE_TBL_Info_t TblInfoPtr; + + status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(SAMPLE_APP_TBL_GETINF_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error Getting Table Info"); + } + else + { + Crc = TblInfoPtr.Crc; + CFE_EVS_SendEvent(SAMPLE_APP_TBL_CRC_INF_EID, + CFE_EVS_EventType_INFORMATION, + "Sample App: CRC: 0x%08lX\n\n", + (unsigned long)Crc); + } + + return; + +} /* End of SAMPLE_GetCrc */ diff --git a/fsw/src/sample_app_utils.h b/fsw/src/sample_app_utils.h new file mode 100644 index 0000000..37f1bae --- /dev/null +++ b/fsw/src/sample_app_utils.h @@ -0,0 +1,43 @@ +/******************************************************************************* +** +** 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_utils.h +** +** Purpose: +** This file contains prototypes for utility functions for the +** SAMPLE application. +** +** +*******************************************************************************/ + +#ifndef _sample_app_utils_h_ +#define _sample_app_utils_h_ + +#include "sample_app.h" + + +void SAMPLE_GetCrc(const char *TableName); + +int32 SAMPLE_TblValidationFunc(void *TblData); + +bool SAMPLE_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength); + + +#endif /* _sample_app_utils_h_ */ diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 38cad88..2e71b9d 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -29,44 +29,34 @@ include_directories(${osal_MISSION_DIR}/ut_assert/inc) include_directories(${PROJECT_SOURCE_DIR}/fsw/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) -# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit -# Although sample_app has only one source file, this is done in a loop such that -# the general pattern should work for several files as well. -foreach(SRCFILE sample_app.c) - get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) - - set(TESTNAME "${UT_NAME}-${UNITNAME}") - set(UNIT_SOURCE_FILE "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/${UNITNAME}.c") - set(TESTCASE_SOURCE_FILE "coveragetest/coveragetest_${UNITNAME}.c") - - # Compile the source unit under test as a OBJECT - add_library(ut_${TESTNAME}_object OBJECT - ${UNIT_SOURCE_FILE} - ) - - # Apply the UT_COVERAGE_COMPILE_FLAGS to the units under test - # This should enable coverage analysis on platforms that support this - target_compile_options(ut_${TESTNAME}_object PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) +set(TESTNAME "sample_app") +add_library(ut_${TESTNAME}_object OBJECT + ${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app.c + ${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_cmds.c + ${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_utils.c) + +# Apply the UT_COVERAGE_COMPILE_FLAGS to the units under test +# This should enable coverage analysis on platforms that support this +target_compile_options(ut_${TESTNAME}_object PRIVATE + ${UT_COVERAGE_COMPILE_FLAGS}) - # Compile a test runner application, which contains the - # actual coverage test code (test cases) and the unit under test - add_executable(${TESTNAME}-testrunner - ${TESTCASE_SOURCE_FILE} - $ - ) +# Compile a test runner application, which contains the +# actual coverage test code (test cases) and the unit under test +add_executable(${TESTNAME}-testrunner + coveragetest/coveragetest_sample_app.c + $) - # This also needs to be linked with UT_COVERAGE_LINK_FLAGS (for coverage) - # This is also linked with any other stub libraries needed, - # as well as the UT assert framework - target_link_libraries(${TESTNAME}-testrunner +# This also needs to be linked with UT_COVERAGE_LINK_FLAGS (for coverage) +# This is also linked with any other stub libraries needed, +# as well as the UT assert framework +target_link_libraries(${TESTNAME}-testrunner ${UT_COVERAGE_LINK_FLAGS} ut_sample_lib_stubs ut_cfe-core_stubs ut_assert ) - # Add it to the set of tests to run as part of "make test" - add_test(${TESTNAME} ${TESTNAME}-testrunner) - -endforeach() +# Add it to the set of tests to run as part of "make test" +add_test(${TESTNAME} ${TESTNAME}-testrunner) + diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 81cd5fc..a8c03fb 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -88,8 +88,6 @@ static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) } - - /* ********************************************************************************** ** TEST CASE FUNCTIONS @@ -205,8 +203,15 @@ void Test_SAMPLE_AppInit(void) * int32 SAMPLE_AppInit( void ) */ + UT_CheckEvent_t EventTest; + /* nominal case should return CFE_SUCCESS */ + UT_CheckEvent_Setup(&EventTest, SAMPLE_STARTUP_INF_EID); UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SUCCESS); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_STARTUP_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + /* trigger a failure for each of the sub-calls, * and confirm a write to syslog for each. @@ -217,25 +222,37 @@ void Test_SAMPLE_AppInit(void) UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, "CFE_ES_WriteToSysLog() called"); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_CreatePipe), 1, CFE_SB_BAD_ARGUMENT); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_PIPE_CREATE_ERR_EID); UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, - "CFE_ES_WriteToSysLog() called"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_PIPE_CREATE_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 1, CFE_SB_BAD_ARGUMENT); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_SUB_HK_ERR_EID); UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 3, - "CFE_ES_WriteToSysLog() called"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_SUB_HK_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 2, CFE_SB_BAD_ARGUMENT); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_SUB_CMD_ERR_EID); UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 4, - "CFE_ES_WriteToSysLog() called"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_SUB_CMD_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_ERR_INVALID_OPTIONS); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_REG_ERR_EID); UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_TBL_ERR_INVALID_OPTIONS); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 5, - "CFE_ES_WriteToSysLog() called"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_REG_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); } @@ -285,12 +302,11 @@ void Test_SAMPLE_ProcessCommandPacket(void) * Confirm that the event was generated only _once_ */ UtAssert_True(EventTest.MatchCount == 1, - "SAMPLE_COMMAND_ERR_EID generated (%u)", + "SAMPLE_INVALID_MSGID_ERR_EID generated (%u)", (unsigned int)EventTest.MatchCount); } - void Test_SAMPLE_ProcessGroundCommand(void) { /* @@ -426,9 +442,11 @@ void Test_SAMPLE_NoopCmd(void) memset(&TestMsg, 0, sizeof(TestMsg)); /* test dispatch of NOOP */ + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Noop_t)); UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); - UT_TEST_FUNCTION_RC(SAMPLE_Noop(&TestMsg), CFE_SUCCESS); + SAMPLE_Noop(&TestMsg); /* * Confirm that the event was generated @@ -438,6 +456,33 @@ void Test_SAMPLE_NoopCmd(void) (unsigned int)EventTest.MatchCount); } +void Test_SAMPLE_NoopCmd_LengthFailure(void) +{ + /* + * Test Case For: + * void SAMPLE_NoopCmd( const SAMPLE_Noop_t *Msg ) + */ + SAMPLE_Noop_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* test NOOP with bad length */ + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Noop_t) + 2); + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); + + SAMPLE_ProcessGroundCommand(&TestMsg); + + /* + * Confirm that the event was not generated + */ + UtAssert_True(EventTest.MatchCount == 0, + "SAMPLE_COMMANDNOP_INF_EID not generated (%u)", + (unsigned int)EventTest.MatchCount); + +} + void Test_SAMPLE_ResetCounters(void) { /* @@ -449,18 +494,51 @@ void Test_SAMPLE_ResetCounters(void) memset(&TestMsg, 0, sizeof(TestMsg)); + /* + * Successful ResetCounters command - confirm that the event was generated + */ UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); - UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_ResetCounters_t)); + + + SAMPLE_ResetCounters(&TestMsg); - /* - * Confirm that the event was generated - */ UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMANDRST_INF_EID generated (%u)", (unsigned int)EventTest.MatchCount); } + +void Test_SAMPLE_ResetCounters_LengthFailure(void) +{ + /* + * Test Case For: + * void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) + */ + SAMPLE_ResetCounters_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* + * Failed ResetCounters command - confirm that the event was not generated + */ + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_ResetCounters_t) + 2); + + SAMPLE_ProcessGroundCommand(&TestMsg); + + UtAssert_True(EventTest.MatchCount == 0, + "SAMPLE_COMMANDRST_INF_EID not generated (%u)", + (unsigned int)EventTest.MatchCount); + +} + + void Test_SAMPLE_ProcessCC(void) { /* @@ -470,7 +548,8 @@ void Test_SAMPLE_ProcessCC(void) SAMPLE_Process_t TestMsg; SAMPLE_Table_t TestTblData; void *TblPtr = &TestTblData; - + UT_CheckEvent_t EventTest; + memset(&TestTblData, 0, sizeof(TestTblData)); memset(&TestMsg, 0, sizeof(TestMsg)); @@ -478,7 +557,13 @@ void Test_SAMPLE_ProcessCC(void) TestTblData.Int1 = 40; TestTblData.Int2 = 50; UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); - UT_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_SUCCESS); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Process_t)); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_INF_EID); + + SAMPLE_Process(&TestMsg); /* * Confirm that the CFE_TBL_GetAddress() call was done @@ -486,6 +571,12 @@ void Test_SAMPLE_ProcessCC(void) UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_GetAddress)) == 1, "CFE_TBL_GetAddress() called"); + /* + * Confirm that the Info event was sent. + */ + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); /* * Confirm that the SAMPLE_Function() call was done @@ -494,40 +585,164 @@ void Test_SAMPLE_ProcessCC(void) UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 1, "SAMPLE_Function() called"); +} + +void Test_SAMPLE_ProcessCC_LengthFailure(void) +{ /* + * Test Case For: + * void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg ) + */ + SAMPLE_Process_t TestMsg; + SAMPLE_Table_t TestTblData; + void *TblPtr = &TestTblData; + UT_CheckEvent_t EventTest; + + memset(&TestTblData, 0, sizeof(TestTblData)); + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* Provide some table data for the SAMPLE_Process() function to use */ + TestTblData.Int1 = 40; + TestTblData.Int2 = 50; + UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Process_t) + 2); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_INF_EID); + + + SAMPLE_ProcessGroundCommand(&TestMsg); + + /* + * Confirm that the Info event was not sent. + */ + UtAssert_True(EventTest.MatchCount == 0, + "SAMPLE_APP_TBL_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + + /* + * Confirm that the SAMPLE_Function and CFE_TBL_ReleaseAddress() + * calls were not done + */ + UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_GetAddress)) == 0, + "CFE_TBL_GetAddress() not called"); + UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 0, + "SAMPLE_Function() not called"); + + +} + +void Test_SAMPLE_ProcessCC_TblRegisterFailure(void) +{ + /* + * Test Case For: + * void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg ) + */ + SAMPLE_Process_t TestMsg; + SAMPLE_Table_t TestTblData; + void *TblPtr = &TestTblData; + UT_CheckEvent_t EventTest; + + memset(&TestTblData, 0, sizeof(TestTblData)); + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* Provide some table data for the SAMPLE_Process() function to use */ + TestTblData.Int1 = 40; + TestTblData.Int2 = 50; + UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Process_t)); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_ADDR_ERR_EID); + + /* * Configure the CFE_TBL_GetAddress function to return an error * Exercise the error return path */ UT_SetForceFail(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); - UT_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED); + + SAMPLE_Process(&TestMsg); + + /* + * Confirm that the SAMPLE_Function and CFE_TBL_ReleaseAddress() + * calls were not done + */ + UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_ReleaseAddress)) == 0, + "CFE_TBL_ReleaseAddress() not called"); + UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 0, + "SAMPLE_Function() not called"); + + /* + * Confirm that the Error event was sent. + */ + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_ADDR_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); + } -void Test_SAMPLE_VerifyCmdLength(void) +void Test_SAMPLE_ProcessCC_TblReleaseFailure(void) { /* * Test Case For: - * bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength ) + * void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg ) */ - CFE_SB_Msg_t TestMsg; + SAMPLE_Process_t TestMsg; + SAMPLE_Table_t TestTblData; + void *TblPtr = &TestTblData; UT_CheckEvent_t EventTest; - + + memset(&TestTblData, 0, sizeof(TestTblData)); memset(&TestMsg, 0, sizeof(TestMsg)); - /* - * test a match case + /* Provide some table data for the SAMPLE_Process() function to use */ + TestTblData.Int1 = 40; + TestTblData.Int2 = 50; + UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_Process_t)); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_REL_ERR_EID); + + /* + * Configure the CFE_TBL_ReleaseAddress function to return an error + * Exercise the error return path */ - UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg)); - UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID); + UT_SetForceFail(UT_KEY(CFE_TBL_ReleaseAddress), CFE_TBL_ERR_UNREGISTERED); + + SAMPLE_Process(&TestMsg); - SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); + /* + * Confirm that the SAMPLE_Function call was not done + */ + UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 0, + "SAMPLE_Function() not called"); /* - * Confirm that the event was NOT generated + * Confirm that the Error event was sent. */ - UtAssert_True(EventTest.MatchCount == 0, - "SAMPLE_LEN_ERR_EID NOT generated (%u)", + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_REL_ERR_EID generated (%u)", (unsigned int)EventTest.MatchCount); +} + +void Test_SAMPLE_VerifyCmdLength(void) +{ + /* + * Test Case For: + * bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength ) + */ + CFE_SB_Msg_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID); + /* * test a mismatch case */ @@ -536,13 +751,41 @@ void Test_SAMPLE_VerifyCmdLength(void) SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); /* - * Confirm that the event WAS generated + * Confirm that the error event generated */ UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_LEN_ERR_EID generated (%u)", (unsigned int)EventTest.MatchCount); } +void Test_SAMPLE_VerifyCmdLength_Failure(void) +{ + /* + * Test Case For: + * bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength ) + */ + CFE_SB_Msg_t TestMsg; + UT_CheckEvent_t EventTest; + + memset(&TestMsg, 0, sizeof(TestMsg)); + + /* + * test a match case + */ + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg)); + UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID); + + SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); + + /* + * Confirm that the event was NOT generated + */ + UtAssert_True(EventTest.MatchCount == 0, + "SAMPLE_LEN_ERR_EID NOT generated (%u)", + (unsigned int)EventTest.MatchCount); + +} + void Test_SAMPLE_TblValidationFunc(void) { /* @@ -556,6 +799,19 @@ void Test_SAMPLE_TblValidationFunc(void) /* nominal case (0) should succeed */ UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), CFE_SUCCESS); +} + + +void Test_SAMPLE_TblValidationFunc_Failure(void) +{ + /* + * Test Case For: + * int32 SAMPLE_TblValidationFunc( void *TblData ) + */ + SAMPLE_Table_t TestTblData; + + memset(&TestTblData, 0, sizeof(TestTblData)); + /* error case should return SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE */ TestTblData.Int1 = 1 + SAMPLE_TBL_ELEMENT_1_MAX; UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), @@ -564,7 +820,6 @@ void Test_SAMPLE_TblValidationFunc(void) - void Test_SAMPLE_GetCrc(void) { /* @@ -580,17 +835,40 @@ void Test_SAMPLE_GetCrc(void) * a different message. This could actually verify * the message using a hook function, if desired. */ - - UT_SetForceFail(UT_KEY(CFE_TBL_GetInfo), CFE_TBL_ERR_INVALID_NAME); - SAMPLE_GetCrc("UT"); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, - "CFE_ES_WriteToSysLog() called"); + UT_CheckEvent_t EventTest; UT_ClearForceFail(UT_KEY(CFE_TBL_GetInfo)); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_CRC_INF_EID); SAMPLE_GetCrc("UT"); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, - "CFE_ES_WriteToSysLog() called"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_CRC_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); +} + +void Test_SAMPLE_GetCrc_Failure(void) +{ + /* + * Test Case For: + * void SAMPLE_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_CheckEvent_t EventTest; + + UT_SetForceFail(UT_KEY(CFE_TBL_GetInfo), CFE_TBL_ERR_INVALID_NAME); + UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_GETINF_ERR_EID); + SAMPLE_GetCrc("UT"); + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_APP_TBL_GETINF_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); } @@ -623,11 +901,19 @@ void UtTest_Setup(void) ADD_TEST(SAMPLE_ProcessGroundCommand); ADD_TEST(SAMPLE_ReportHousekeeping); ADD_TEST(SAMPLE_NoopCmd); + ADD_TEST(SAMPLE_NoopCmd_LengthFailure); ADD_TEST(SAMPLE_ResetCounters); + ADD_TEST(SAMPLE_ResetCounters_LengthFailure); ADD_TEST(SAMPLE_ProcessCC); + ADD_TEST(SAMPLE_ProcessCC_LengthFailure); + ADD_TEST(SAMPLE_ProcessCC_TblRegisterFailure); + ADD_TEST(SAMPLE_ProcessCC_TblReleaseFailure); ADD_TEST(SAMPLE_VerifyCmdLength); + ADD_TEST(SAMPLE_VerifyCmdLength_Failure); ADD_TEST(SAMPLE_TblValidationFunc); + ADD_TEST(SAMPLE_TblValidationFunc_Failure); ADD_TEST(SAMPLE_GetCrc); + ADD_TEST(SAMPLE_GetCrc_Failure); } diff --git a/unit-test/coveragetest/sample_app_coveragetest_common.h b/unit-test/coveragetest/sample_app_coveragetest_common.h index f514747..3909de4 100644 --- a/unit-test/coveragetest/sample_app_coveragetest_common.h +++ b/unit-test/coveragetest/sample_app_coveragetest_common.h @@ -41,6 +41,8 @@ #include #include #include +#include +#include /* * Macro to call a function and check its int32 return code diff --git a/unit-test/inc/ut_sample_app.h b/unit-test/inc/ut_sample_app.h index d0202a3..b677ec8 100644 --- a/unit-test/inc/ut_sample_app.h +++ b/unit-test/inc/ut_sample_app.h @@ -41,6 +41,8 @@ */ #include #include +#include +#include /* * Allow UT access to the global "SAMPLE_AppData" object.