From ab2acdcb49f26b604fd6a69457e54d72d37779a1 Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Tue, 14 Apr 2020 10:55:30 -0400 Subject: [PATCH 1/7] Added cmds and utils files and moved functions from app.c to them. --- fsw/src/sample_app.c | 197 ++----------------------------------- fsw/src/sample_app.h | 8 -- fsw/src/sample_app_cmds.c | 148 ++++++++++++++++++++++++++++ fsw/src/sample_app_cmds.h | 42 ++++++++ fsw/src/sample_app_utils.c | 128 ++++++++++++++++++++++++ fsw/src/sample_app_utils.h | 43 ++++++++ 6 files changed, 367 insertions(+), 199 deletions(-) create mode 100644 fsw/src/sample_app_cmds.c create mode 100644 fsw/src/sample_app_cmds.h create mode 100644 fsw/src/sample_app_utils.c create mode 100644 fsw/src/sample_app_utils.h diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 82e51e1..ff1daa8 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 @@ -277,7 +279,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", MsgId); break; } @@ -303,27 +305,15 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) switch (CommandCode) { case SAMPLE_APP_NOOP_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) - { - SAMPLE_Noop((SAMPLE_Noop_t *)Msg); - } - + SAMPLE_Noop((SAMPLE_Noop_t *)Msg); break; case SAMPLE_APP_RESET_COUNTERS_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) - { - SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); - } - + SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); break; case SAMPLE_APP_PROCESS_CC: - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) - { - SAMPLE_Process((SAMPLE_Process_t *)Msg); - } - + SAMPLE_Process((SAMPLE_Process_t *)Msg); break; /* default case already found during FC vs length test */ @@ -376,179 +366,4 @@ 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", - 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..ddaf2e9 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -117,13 +117,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..cd86081 --- /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 */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) +{ + + if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + { + 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. */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) +{ + + if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + { + 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 */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_Process( const SAMPLE_Process_t *Msg ) +{ + int32 status; + SAMPLE_Table_t *TblPtr; + const char *TableName = "SAMPLE_APP.SampleTable"; + + + if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + { + /* 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); + + SAMPLE_AppData.ErrCounter++; + return; + } + + 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); + + SAMPLE_AppData.ErrCounter++; + return; + } + + /* Invoke a function provided by SAMPLE_LIB */ + SAMPLE_Function(); + + SAMPLE_AppData.CmdCounter++; + } + +} /* 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..a464e45 --- /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" + + +void SAMPLE_Noop(const SAMPLE_Noop_t *Msg); + +void SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); + +void SAMPLE_Process(const SAMPLE_Process_t *Msg); + +#endif /* _sample_app_cmds_h_ */ diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c new file mode 100644 index 0000000..555f785 --- /dev/null +++ b/fsw/src/sample_app_utils.c @@ -0,0 +1,128 @@ +/******************************************************************************* +** +** 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_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_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_ */ From 9f02e2e1454bc7a3e9d2939e0301f8801b9e1cc9 Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Tue, 14 Apr 2020 13:26:31 -0400 Subject: [PATCH 2/7] Replaced a lot of the WriteToSysLog calls with CFE_EVS_SendEvent. --- fsw/src/sample_app.c | 31 +++++++++++++++++++++++-------- fsw/src/sample_app_cmds.c | 22 ++++++++++++++-------- fsw/src/sample_app_events.h | 12 +++++++++++- fsw/src/sample_app_utils.c | 9 +++++++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index ff1daa8..d958d41 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -108,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 */ @@ -188,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 ); } @@ -200,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 ); } @@ -212,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 ); } @@ -228,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 ); } diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index cd86081..6faeea4 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -114,24 +114,30 @@ void SAMPLE_Process( const SAMPLE_Process_t *Msg ) if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", - (unsigned long)status); + 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; } - CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", - TblPtr->Int1, - TblPtr->Int2); + 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_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", - (unsigned long)status); + { + 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; 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 index 555f785..c026630 100644 --- a/fsw/src/sample_app_utils.c +++ b/fsw/src/sample_app_utils.c @@ -115,12 +115,17 @@ void SAMPLE_GetCrc( const char *TableName ) status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); if (status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info"); + CFE_EVS_SendEvent(SAMPLE_APP_TBL_GETINF_ERR_EID, + CFE_EVS_EventType_ERROR, + "Sample App: Error Getting Table Info"); } else { Crc = TblInfoPtr.Crc; - CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)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; From 7905af93e1a1498f09e96b49903d51e0ae721803 Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Tue, 14 Apr 2020 15:15:57 -0400 Subject: [PATCH 3/7] Attempts at making unit tests compile. --- CMakeLists.txt | 4 +- fsw/src/sample_app.h | 4 + unit-test/CMakeLists.txt | 2 +- .../coveragetest/coveragetest_sample_app.c | 8 +- .../coveragetest_sample_app_cmds.c | 217 +++++++++++++++++ .../coveragetest_sample_app_utils.c | 218 ++++++++++++++++++ .../sample_app_coveragetest_common.h | 2 + unit-test/inc/ut_sample_app.h | 2 + 8 files changed, 451 insertions(+), 6 deletions(-) create mode 100644 unit-test/coveragetest/coveragetest_sample_app_cmds.c create mode 100644 unit-test/coveragetest/coveragetest_sample_app_utils.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e5514ac..07c6d45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,10 @@ include_directories(fsw/platform_inc) # to call library-provided functions include_directories(${sample_lib_MISSION_DIR}/fsw/public_inc) +aux_source_directory(fsw/src APP_SRC_FILES) + # Create the app module -add_cfe_app(sample_app fsw/src/sample_app.c) +add_cfe_app(sample_app ${APP_SRC_FILES}) # Add table add_cfe_tables(sampleTable fsw/src/sample_table.c) diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index ddaf2e9..9bc26c9 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 */ @@ -105,6 +107,8 @@ typedef struct } SAMPLE_AppData_t; +extern SAMPLE_AppData_t SAMPLE_AppData; + /****************************************************************************/ /* ** Local function prototypes. diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index a880399..36441a4 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -32,7 +32,7 @@ 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) +foreach(SRCFILE sample_app.c sample_app_cmds.c sample_app_utils.c) get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) set(TESTNAME "${UT_NAME}-${UNITNAME}") diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index b7a53a6..90f421a 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -416,7 +416,7 @@ void Test_SAMPLE_NoopCmd(void) /* test dispatch of NOOP */ 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 @@ -439,7 +439,7 @@ void Test_SAMPLE_ResetCounters(void) UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); - UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); + //UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); /* * Confirm that the event was generated @@ -466,7 +466,7 @@ 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_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_SUCCESS); /* * Confirm that the CFE_TBL_GetAddress() call was done @@ -487,7 +487,7 @@ void Test_SAMPLE_ProcessCC(void) * 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); + //UT_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED); } void Test_SAMPLE_VerifyCmdLength(void) 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..6e688b1 --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_cmds.c @@ -0,0 +1,217 @@ +/* +** 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: 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" +#include "sample_app_coveragetest_common.h" +#include "ut_sample_app.h" + +/* to get the SAMPLE_Function() declaration */ + +typedef struct +{ + uint16 ExpectedEvent; + uint32 MatchCount; +} 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) +{ + UT_CheckEvent_t *State = UserObj; + uint16 *EventIdPtr; + + /* + * The CFE_EVS_SendEvent stub passes the EventID as the + * first context argument. + */ + if (Context->ArgCount > 0) + { + EventIdPtr = (uint16*)Context->ArgPtr[0]; + if (*EventIdPtr == State->ExpectedEvent) + { + ++State->MatchCount; + } + } + + return 0; +} + +/* + * Helper function to set up for event checking + * This attaches the hook function to CFE_EVS_SendEvent + */ +static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) +{ + memset(Evt, 0, sizeof(*Evt)); + Evt->ExpectedEvent = ExpectedEvent; + UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); +} + + + + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ +void Test_SAMPLE_NoopCmd(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 dispatch of NOOP */ + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); + + SAMPLE_Noop(&TestMsg); + + /* + * Confirm that the event was generated + */ + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_COMMANDNOP_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); +} + +void Test_SAMPLE_ResetCounters(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)); + + UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); + + //UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); + + /* + * Confirm that the event was generated + */ + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_COMMANDRST_INF_EID generated (%u)", + (unsigned int)EventTest.MatchCount); +} + +void Test_SAMPLE_ProcessCC(void) +{ + /* + * Test Case For: + * void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg ) + */ + SAMPLE_Process_t TestMsg; + SAMPLE_Table_t TestTblData; + void *TblPtr = &TestTblData; + + 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_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_SUCCESS); + + /* + * Confirm that the CFE_TBL_GetAddress() call was done + */ + UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_GetAddress)) == 1, + "CFE_TBL_GetAddress() called"); + + + /* + * Confirm that the SAMPLE_Function() call was done + * NOTE: This stub is provided by the sample_lib library + */ + UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 1, + "SAMPLE_Function() called"); + + /* + * 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); +} + + +/* + * 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 + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_NoopCmd); + ADD_TEST(SAMPLE_ResetCounters); + ADD_TEST(SAMPLE_ProcessCC); +} + + + + + 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..a0a7b6b --- /dev/null +++ b/unit-test/coveragetest/coveragetest_sample_app_utils.c @@ -0,0 +1,218 @@ +/* +** 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: 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" +#include "sample_app_coveragetest_common.h" +#include "ut_sample_app.h" + +/* to get the SAMPLE_Function() declaration */ + +typedef struct +{ + uint16 ExpectedEvent; + uint32 MatchCount; +} 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) +{ + UT_CheckEvent_t *State = UserObj; + uint16 *EventIdPtr; + + /* + * The CFE_EVS_SendEvent stub passes the EventID as the + * first context argument. + */ + if (Context->ArgCount > 0) + { + EventIdPtr = (uint16*)Context->ArgPtr[0]; + if (*EventIdPtr == State->ExpectedEvent) + { + ++State->MatchCount; + } + } + + return 0; +} + +/* + * Helper function to set up for event checking + * This attaches the hook function to CFE_EVS_SendEvent + */ +static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) +{ + memset(Evt, 0, sizeof(*Evt)); + Evt->ExpectedEvent = ExpectedEvent; + UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); +} + + + + +/* +********************************************************************************** +** TEST CASE FUNCTIONS +********************************************************************************** +*/ +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)); + + /* + * 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); + + /* + * test a mismatch case + */ + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + 10 + sizeof(TestMsg)); + SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); + + /* + * Confirm that the event WAS generated + */ + UtAssert_True(EventTest.MatchCount == 1, + "SAMPLE_LEN_ERR_EID generated (%u)", + (unsigned int)EventTest.MatchCount); +} + +void Test_SAMPLE_TblValidationFunc(void) +{ + /* + * Test Case For: + * int32 SAMPLE_TblValidationFunc( void *TblData ) + */ + SAMPLE_Table_t TestTblData; + + memset(&TestTblData, 0, sizeof(TestTblData)); + + /* nominal case (0) should succeed */ + UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), CFE_SUCCESS); + + /* 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), + SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE); +} + +void Test_SAMPLE_GetCrc(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_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_ClearForceFail(UT_KEY(CFE_TBL_GetInfo)); + SAMPLE_GetCrc("UT"); + UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, + "CFE_ES_WriteToSysLog() called"); + +} + + + +/* + * 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 + */ +void UtTest_Setup(void) +{ + ADD_TEST(SAMPLE_VerifyCmdLength); + ADD_TEST(SAMPLE_TblValidationFunc); + ADD_TEST(SAMPLE_GetCrc); +} + + + + + 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. From a49bb4ab72f03170d35ebb71268eeab2f184f54c Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Wed, 15 Apr 2020 14:18:34 -0400 Subject: [PATCH 4/7] Put unit tests back into one file. Broke out some of the failure cases into separate functions. Added new failure cases. Updated CMakeLists file. --- fsw/src/sample_app_cmds.c | 2 +- unit-test/CMakeLists.txt | 59 ++- .../coveragetest/coveragetest_sample_app.c | 364 ++++++++++++++++-- .../coveragetest_sample_app_cmds.c | 217 ----------- .../coveragetest_sample_app_utils.c | 218 ----------- 5 files changed, 348 insertions(+), 512 deletions(-) delete mode 100644 unit-test/coveragetest/coveragetest_sample_app_cmds.c delete mode 100644 unit-test/coveragetest/coveragetest_sample_app_utils.c diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index 6faeea4..8a45148 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -77,7 +77,7 @@ void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) { - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) { SAMPLE_AppData.CmdCounter = 0; SAMPLE_AppData.ErrCounter = 0; diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 36441a4..2e71b9d 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -29,47 +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 sample_app_cmds.c sample_app_utils.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_C_FLAGS to the units under test - # This should enable coverage analysis on platforms that support this - set_target_properties(ut_${TESTNAME}_object PROPERTIES - COMPILE_FLAGS "${UT_C_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} - $ - ) - - # This also needs to be linked with UT_C_FLAGS (for coverage) - set_target_properties(${TESTNAME}-testrunner PROPERTIES - LINK_FLAGS "${UT_C_FLAGS}") +# 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 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 90f421a..3470b33 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) { /* @@ -414,6 +430,8 @@ 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); SAMPLE_Noop(&TestMsg); @@ -426,6 +444,32 @@ 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_Noop(&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) { /* @@ -437,18 +481,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); + + SAMPLE_ResetCounters(&TestMsg); + + UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, + sizeof(SAMPLE_ResetCounters_t) + 2); + + UtAssert_True(EventTest.MatchCount == 0, + "SAMPLE_COMMANDRST_INF_EID not generated (%u)", + (unsigned int)EventTest.MatchCount); + +} + + void Test_SAMPLE_ProcessCC(void) { /* @@ -458,7 +535,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)); @@ -466,7 +544,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 @@ -474,6 +558,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 @@ -482,40 +572,163 @@ 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_Process(&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 */ @@ -524,13 +737,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) { /* @@ -544,6 +785,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), @@ -552,7 +806,6 @@ void Test_SAMPLE_TblValidationFunc(void) - void Test_SAMPLE_GetCrc(void) { /* @@ -568,17 +821,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); } @@ -611,11 +887,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/coveragetest_sample_app_cmds.c b/unit-test/coveragetest/coveragetest_sample_app_cmds.c deleted file mode 100644 index 6e688b1..0000000 --- a/unit-test/coveragetest/coveragetest_sample_app_cmds.c +++ /dev/null @@ -1,217 +0,0 @@ -/* -** 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: 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" -#include "sample_app_coveragetest_common.h" -#include "ut_sample_app.h" - -/* to get the SAMPLE_Function() declaration */ - -typedef struct -{ - uint16 ExpectedEvent; - uint32 MatchCount; -} 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) -{ - UT_CheckEvent_t *State = UserObj; - uint16 *EventIdPtr; - - /* - * The CFE_EVS_SendEvent stub passes the EventID as the - * first context argument. - */ - if (Context->ArgCount > 0) - { - EventIdPtr = (uint16*)Context->ArgPtr[0]; - if (*EventIdPtr == State->ExpectedEvent) - { - ++State->MatchCount; - } - } - - return 0; -} - -/* - * Helper function to set up for event checking - * This attaches the hook function to CFE_EVS_SendEvent - */ -static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) -{ - memset(Evt, 0, sizeof(*Evt)); - Evt->ExpectedEvent = ExpectedEvent; - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); -} - - - - -/* -********************************************************************************** -** TEST CASE FUNCTIONS -********************************************************************************** -*/ -void Test_SAMPLE_NoopCmd(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 dispatch of NOOP */ - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); - - SAMPLE_Noop(&TestMsg); - - /* - * Confirm that the event was generated - */ - UtAssert_True(EventTest.MatchCount == 1, - "SAMPLE_COMMANDNOP_INF_EID generated (%u)", - (unsigned int)EventTest.MatchCount); -} - -void Test_SAMPLE_ResetCounters(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)); - - UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); - - //UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS); - - /* - * Confirm that the event was generated - */ - UtAssert_True(EventTest.MatchCount == 1, - "SAMPLE_COMMANDRST_INF_EID generated (%u)", - (unsigned int)EventTest.MatchCount); -} - -void Test_SAMPLE_ProcessCC(void) -{ - /* - * Test Case For: - * void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg ) - */ - SAMPLE_Process_t TestMsg; - SAMPLE_Table_t TestTblData; - void *TblPtr = &TestTblData; - - 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_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_SUCCESS); - - /* - * Confirm that the CFE_TBL_GetAddress() call was done - */ - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_GetAddress)) == 1, - "CFE_TBL_GetAddress() called"); - - - /* - * Confirm that the SAMPLE_Function() call was done - * NOTE: This stub is provided by the sample_lib library - */ - UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 1, - "SAMPLE_Function() called"); - - /* - * 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); -} - - -/* - * 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 - */ -void UtTest_Setup(void) -{ - ADD_TEST(SAMPLE_NoopCmd); - ADD_TEST(SAMPLE_ResetCounters); - ADD_TEST(SAMPLE_ProcessCC); -} - - - - - diff --git a/unit-test/coveragetest/coveragetest_sample_app_utils.c b/unit-test/coveragetest/coveragetest_sample_app_utils.c deleted file mode 100644 index a0a7b6b..0000000 --- a/unit-test/coveragetest/coveragetest_sample_app_utils.c +++ /dev/null @@ -1,218 +0,0 @@ -/* -** 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: 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" -#include "sample_app_coveragetest_common.h" -#include "ut_sample_app.h" - -/* to get the SAMPLE_Function() declaration */ - -typedef struct -{ - uint16 ExpectedEvent; - uint32 MatchCount; -} 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) -{ - UT_CheckEvent_t *State = UserObj; - uint16 *EventIdPtr; - - /* - * The CFE_EVS_SendEvent stub passes the EventID as the - * first context argument. - */ - if (Context->ArgCount > 0) - { - EventIdPtr = (uint16*)Context->ArgPtr[0]; - if (*EventIdPtr == State->ExpectedEvent) - { - ++State->MatchCount; - } - } - - return 0; -} - -/* - * Helper function to set up for event checking - * This attaches the hook function to CFE_EVS_SendEvent - */ -static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent) -{ - memset(Evt, 0, sizeof(*Evt)); - Evt->ExpectedEvent = ExpectedEvent; - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt); -} - - - - -/* -********************************************************************************** -** TEST CASE FUNCTIONS -********************************************************************************** -*/ -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)); - - /* - * 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); - - /* - * test a mismatch case - */ - UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, - 10 + sizeof(TestMsg)); - SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg)); - - /* - * Confirm that the event WAS generated - */ - UtAssert_True(EventTest.MatchCount == 1, - "SAMPLE_LEN_ERR_EID generated (%u)", - (unsigned int)EventTest.MatchCount); -} - -void Test_SAMPLE_TblValidationFunc(void) -{ - /* - * Test Case For: - * int32 SAMPLE_TblValidationFunc( void *TblData ) - */ - SAMPLE_Table_t TestTblData; - - memset(&TestTblData, 0, sizeof(TestTblData)); - - /* nominal case (0) should succeed */ - UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), CFE_SUCCESS); - - /* 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), - SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE); -} - -void Test_SAMPLE_GetCrc(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_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_ClearForceFail(UT_KEY(CFE_TBL_GetInfo)); - SAMPLE_GetCrc("UT"); - UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, - "CFE_ES_WriteToSysLog() called"); - -} - - - -/* - * 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 - */ -void UtTest_Setup(void) -{ - ADD_TEST(SAMPLE_VerifyCmdLength); - ADD_TEST(SAMPLE_TblValidationFunc); - ADD_TEST(SAMPLE_GetCrc); -} - - - - - From eac4f1604ba7743184a86224f5c07d32a41643df Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Wed, 29 Apr 2020 17:27:36 -0400 Subject: [PATCH 5/7] Putting command verification back into the main file. --- beth_sample | 1 + fsw/src/sample_app.c | 15 ++++-- fsw/src/sample_app_cmds.c | 108 ++++++++++++++++++-------------------- 3 files changed, 63 insertions(+), 61 deletions(-) create mode 160000 beth_sample diff --git a/beth_sample b/beth_sample new file mode 160000 index 0000000..ab2acdc --- /dev/null +++ b/beth_sample @@ -0,0 +1 @@ +Subproject commit ab2acdcb49f26b604fd6a69457e54d72d37779a1 diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index d958d41..f01608b 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -320,15 +320,24 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) switch (CommandCode) { case SAMPLE_APP_NOOP_CC: - SAMPLE_Noop((SAMPLE_Noop_t *)Msg); + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) + { + SAMPLE_Noop((SAMPLE_Noop_t *)Msg); + } break; case SAMPLE_APP_RESET_COUNTERS_CC: - SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) + { + SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); + } break; case SAMPLE_APP_PROCESS_CC: - SAMPLE_Process((SAMPLE_Process_t *)Msg); + if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) + { + SAMPLE_Process((SAMPLE_Process_t *)Msg); + } break; /* default case already found during FC vs length test */ diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index 8a45148..d035936 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -49,18 +49,16 @@ void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) { - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) - { - 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); - } + 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; @@ -77,15 +75,12 @@ void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) { - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t))) - { - SAMPLE_AppData.CmdCounter = 0; - SAMPLE_AppData.ErrCounter = 0; + SAMPLE_AppData.CmdCounter = 0; + SAMPLE_AppData.ErrCounter = 0; - CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID, - CFE_EVS_EventType_INFORMATION, - "SAMPLE: RESET command"); - } + CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID, + CFE_EVS_EventType_INFORMATION, + "SAMPLE: RESET command"); return CFE_SUCCESS; @@ -105,50 +100,47 @@ void SAMPLE_Process( const SAMPLE_Process_t *Msg ) const char *TableName = "SAMPLE_APP.SampleTable"; - if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) - { - /* Sample Use of Table */ + /* Sample Use of Table */ - status = CFE_TBL_GetAddress((void *)&TblPtr, - SAMPLE_AppData.TblHandles[0]); + 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); + 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; - } - - 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; + } + + 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; - } - - /* Invoke a function provided by SAMPLE_LIB */ - SAMPLE_Function(); - - SAMPLE_AppData.CmdCounter++; + SAMPLE_AppData.ErrCounter++; + return; } + /* Invoke a function provided by SAMPLE_LIB */ + SAMPLE_Function(); + + SAMPLE_AppData.CmdCounter++; + } /* End of SAMPLE_ProcessCC */ From daf6cc22ca90ac3ae0a5a4c19d51177c3af7df75 Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Wed, 29 Apr 2020 17:55:46 -0400 Subject: [PATCH 6/7] Changed command return codes back to int32. Fixed unit tests. --- beth_sample | 1 - fsw/src/sample_app_cmds.c | 12 +++++++----- fsw/src/sample_app_cmds.h | 6 +++--- unit-test/coveragetest/coveragetest_sample_app.c | 10 ++++++---- 4 files changed, 16 insertions(+), 13 deletions(-) delete mode 160000 beth_sample diff --git a/beth_sample b/beth_sample deleted file mode 160000 index ab2acdc..0000000 --- a/beth_sample +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab2acdcb49f26b604fd6a69457e54d72d37779a1 diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index d035936..a1780c9 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -46,7 +46,7 @@ /* SAMPLE_Noop -- SAMPLE NOOP commands */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) +int32 SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) { SAMPLE_AppData.CmdCounter++; @@ -72,7 +72,7 @@ void SAMPLE_Noop( const SAMPLE_Noop_t *Msg ) /* part of the task telemetry. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) +int32 SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) { SAMPLE_AppData.CmdCounter = 0; @@ -93,7 +93,7 @@ void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg ) /* This function Process Ground Station Command */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_Process( const SAMPLE_Process_t *Msg ) +int32 SAMPLE_Process( const SAMPLE_Process_t *Msg ) { int32 status; SAMPLE_Table_t *TblPtr; @@ -113,7 +113,7 @@ void SAMPLE_Process( const SAMPLE_Process_t *Msg ) (unsigned long) status); SAMPLE_AppData.ErrCounter++; - return; + return status; } CFE_EVS_SendEvent(SAMPLE_APP_TBL_INF_EID, @@ -133,7 +133,7 @@ void SAMPLE_Process( const SAMPLE_Process_t *Msg ) (unsigned long)status); SAMPLE_AppData.ErrCounter++; - return; + return status; } /* Invoke a function provided by SAMPLE_LIB */ @@ -141,6 +141,8 @@ void SAMPLE_Process( const SAMPLE_Process_t *Msg ) 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 index a464e45..95ccb11 100644 --- a/fsw/src/sample_app_cmds.h +++ b/fsw/src/sample_app_cmds.h @@ -33,10 +33,10 @@ #include "sample_app.h" -void SAMPLE_Noop(const SAMPLE_Noop_t *Msg); +int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg); -void SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); +int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg); -void SAMPLE_Process(const SAMPLE_Process_t *Msg); +int32 SAMPLE_Process(const SAMPLE_Process_t *Msg); #endif /* _sample_app_cmds_h_ */ diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index 3470b33..a566971 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -459,7 +459,8 @@ void Test_SAMPLE_NoopCmd_LengthFailure(void) UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(SAMPLE_Noop_t) + 2); UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID); - SAMPLE_Noop(&TestMsg); + + SAMPLE_ProcessGroundCommand(&TestMsg); /* * Confirm that the event was not generated @@ -514,11 +515,11 @@ void Test_SAMPLE_ResetCounters_LengthFailure(void) */ UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID); - SAMPLE_ResetCounters(&TestMsg); - 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); @@ -598,7 +599,8 @@ void Test_SAMPLE_ProcessCC_LengthFailure(void) UT_CheckEvent_Setup(&EventTest, SAMPLE_APP_TBL_INF_EID); - SAMPLE_Process(&TestMsg); + + SAMPLE_ProcessGroundCommand(&TestMsg); /* * Confirm that the Info event was not sent. From 32fcba9253c12f16023d14c6d67d18aae572df0f Mon Sep 17 00:00:00 2001 From: Elizabeth Timmons Date: Wed, 29 Apr 2020 18:06:39 -0400 Subject: [PATCH 7/7] Explicitly listed source files in CMakeLists.txt --- CMakeLists.txt | 6 +++--- fsw/src/sample_app.c | 7 +++---- fsw/src/sample_app.h | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07c6d45..683cf7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,10 +8,10 @@ include_directories(fsw/platform_inc) # to call library-provided functions include_directories(${sample_lib_MISSION_DIR}/fsw/public_inc) -aux_source_directory(fsw/src APP_SRC_FILES) - # Create the app module -add_cfe_app(sample_app ${APP_SRC_FILES}) +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 f01608b..17098e4 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -311,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); /* @@ -321,21 +320,21 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) { case SAMPLE_APP_NOOP_CC: 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))) - { + { SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg); } break; case SAMPLE_APP_PROCESS_CC: if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) - { + { SAMPLE_Process((SAMPLE_Process_t *)Msg); } break; diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 9bc26c9..74410c5 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -55,6 +55,7 @@ #define SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE -1 #define SAMPLE_TBL_ELEMENT_1_MAX 10 + /************************************************************************ ** Type Definitions *************************************************************************/