diff --git a/CMakeLists.txt b/CMakeLists.txt index f01c22f..4e328d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ project(CFS_HK C) set(APP_SRC_FILES fsw/src/hk_app.c + fsw/src/hk_dispatch.c fsw/src/hk_utils.c ) diff --git a/docs/dox_src/cfs_hk.dox b/docs/dox_src/cfs_hk.dox index 409c3b4..5a8c9a9 100644 --- a/docs/dox_src/cfs_hk.dox +++ b/docs/dox_src/cfs_hk.dox @@ -53,11 +53,11 @@

Scope

This document provides a complete specification for the commands and telemetry associated - with the CFS Housekeeping (HK) application software. The document is intended primarily - for users of the software (operations personal, test engineers, and maintenance personnel). - The last section of the document, the deployment guide section, is intended for mission - developers when deploying and configuring the FM application software for a mission - flight software build environment. + with the CFS Housekeeping (HK) application software. The document is intended primarily + for users of the software (operations personal, test engineers, and maintenance personnel). + The last section of the document, the deployment guide section, is intended for mission + developers when deploying and configuring the FM application software for a mission + flight software build environment. \ref cfshkversion @@ -121,16 +121,16 @@ The HK Application is a passive application and is completely packet driven. There are no timers used to wake up the application. The housekeeping request commands are not sent to the system apps by HK. A common system design uses the - Scheduler (SCH) Application to send the housekeeping + Scheduler (SCH) Application to send the housekeeping requests to the system apps as well as the send-output-message-x command to HK. - A key component that is part of the HK application is the 'copy table'. The copy + A key component that is part of the HK application is the 'copy table'. The copy table has a configurable number of entries. Each entry specifies a source (via - msgid and offset into the packet), destination (via msgid and offset) and a + msgid and offset into the packet), destination (via msgid and offset) and a number of bytes to copy.

HK Design Overview

- + The HK Application has a single Software Bus pipe and wakes up only when a message is received on the pipe (named HK_CMD_PIPE). The HK_CMD_PIPE receives commands and input messages. If the message received @@ -144,10 +144,10 @@ than one area in the same output packet. The number of output packets is also limited only by the the number of entries in the table. The number of entries in the table is a platform configuration parameter. - - The output messages are sent to the software bus when HK receives the - 'Send Output Message x' command. Where 'x' is a parameter in the command that - specifies the message ID of the output message to send. If a piece of data is + + The output messages are sent to the software bus when HK receives the + 'Send Output Message x' command. Where 'x' is a parameter in the command that + specifies the message ID of the output message to send. If a piece of data is missing in the output message at the time the 'Send Output Message x' command is received, the HK app will send a debug event (which is filtered by default) and increment the 'missing data counter' in telemetry. @@ -158,45 +158,45 @@ The operational interface of the HK application consists of two commands, two tables and a few telemetry points. The following items detail the operational - interface. + interface.

1. The application version number

- + The application version number is displayed in the initialization event and the no-op event. Both events are 'informational' type and are unfiltered by default.

2. Loading the copy table

- + The copy table is loaded by way of a file. The file must be present when the application starts up. Otherwise, the app will terminate after initialization. The location of the file is specified by the platform configuration parameter - named #HK_COPY_TABLE_FILENAME. The value of this define specifies the full + named #HK_COPY_TABLE_FILENAME. The value of this define specifies the full path as well as the filename. - - After initialization, a new copy table may be loaded at any time. The steps to + + After initialization, a new copy table may be loaded at any time. The steps to load a new copy table are: - Transfer the table file to the on-board file system - Send the #CFE_TBL_LOAD_CC \copybrief CFE_TBL_LOAD_CC - Send the #CFE_TBL_VALIDATE_CC \copybrief CFE_TBL_VALIDATE_CC - Send the #CFE_TBL_ACTIVATE_CC \copybrief CFE_TBL_ACTIVATE_CC - + The HK application will clean up the items used for the old table (such as SB subscriptions) before updating and processing the new table.

3. Sending the No-op Command

- + To verify connectivity with the Housekeeping application, the ground may send an #HK_NOOP_CC \copybrief HK_NOOP_CC - If the packet length field in the - command is set to the value expected by the HK app, then the command counter will + If the packet length field in the + command is set to the value expected by the HK app, then the command counter will increment and a #HK_NOOP_CMD_EID event message will be sent. This no-op event will show the version number of the HK application. - +

4. Sending the reset counters command

- - The #HK_RESET_CC \copybrief HK_RESET_CC will reset counters in telemetry. - + + The #HK_RESET_COUNTERS_CC \copybrief HK_RESET_COUNTERS_CC will reset counters in telemetry. +

5. Monitoring the command counter

The #HK_HkTlm_Payload_t.CmdCounter will increment only @@ -208,7 +208,7 @@ b. Unexpected packet length field for #HK_SEND_COMBINED_PKT_MID command c. Unexpected packet length field for #HK_SEND_HK_MID command d. Unexpected packet length field for #HK_NOOP_CC command - e. Unexpected packet length field for #HK_RESET_CC command + e. Unexpected packet length field for #HK_RESET_COUNTERS_CC command

7. Monitoring the 'Combined Packets Sent" counter

@@ -229,12 +229,12 @@ The #HK_HkTlm_Payload_t.MissingDataCtr will advance by one count (at most) and send one event (at most) for each #HK_SEND_COMBINED_PKT_MID. - + The HK app will not zero-out or alter the missing data section(s) in any way. The missing data values will match the last 'good' section received.

9. Using the Memory Pool handle to get mempool stats

- + The HK memory pool is used to allocate the memory needed to store the output packets. Each time a new copy table is processed, the memory for the output packets is dynamically allocated from the memory pool. The memory pool handle is @@ -248,22 +248,22 @@ \page cfshkdg CFS Housekeeping Deployment Guide Follow the general guidelines below for platform deployment of the Housekeeping app. - + There are two message IDs that must be included in the CFS Scheduler Table: #HK_SEND_HK_MID is sent out at the housekeeping request interval. The housekeeping app must send its housekeeping data to itself like any other app. #HK_SEND_COMBINED_PKT_MID is sent out at the desired rate for each combined packet. UP to four combined packets are available. - + The HK app can build up to four combined packets based on the definitions supplied in the - HK copy table. The Scheduler Table uses each telemetry IDs (#HK_COMBINED_PKT1_MID , + HK copy table. The Scheduler Table uses each telemetry IDs (#HK_COMBINED_PKT1_MID , #HK_COMBINED_PKT2_MID , #HK_COMBINED_PKT3_MID , and #HK_COMBINED_PKT4_MID ) as a valid parameter in the #HK_SEND_COMBINED_PKT_MID table entries. - + The ES app uses the HK performance ID, #HK_APPMAIN_PERF_ID , to keep track of the performance of the HK app. - - The platform configuration file hk_platform_cfg.h contains parameters that can be adjusted to + + The platform configuration file hk_platform_cfg.h contains parameters that can be adjusted to specific platforms. See \ref cfshkplatformcfg. See \ref cfshkmissioncfg for mission configuration parameters. @@ -271,7 +271,7 @@ /** \page cfshktbl CFS Housekeeping Table Definitions - + The Housekeeping Application uses two tables. A load-dump table referred to as the "copy table" and a dump-only table referred to as the "run-time table". Each table has the same number of entries, defined by the configuration parameter @@ -281,12 +281,12 @@ tables were chosen so that checksumming can be executed on the more-static copy table. - HK Copy Table Validation - The HK copy table currently has an empty validation - call-back function that always returns success. At the time of development, + HK Copy Table Validation - The HK copy table currently has an empty validation + call-back function that always returns success. At the time of development, a validation process that would apply to all projects was not perceived. HK Copy Table Entries - Entries follow the concept of: - Copy A bytes from input message B, byte-offset C to output message Y, + Copy A bytes from input message B, byte-offset C to output message Y, byte-offset Z. The structure format of a single copy table entry is defined by #hk_copy_table_entry_t. @@ -309,7 +309,7 @@ /** \page cfshkcons CFS Housekeeping Constraints - The Housekeeping Application needs to find a valid table at the location + The Housekeeping Application needs to find a valid table at the location specified by the configuration parameter #HK_COPY_TABLE_FILENAME in order to startup. Otherwise the application will send an error event or syslog message then terminate. See \ref cfshktbl for more detail. @@ -323,10 +323,10 @@ \page cfshkfaqs CFS Housekeeping Frequently Asked Questions (Q) - Does the protocol for collecting telemetry use a single housekeeping request + Does the protocol for collecting telemetry use a single housekeeping request command for all apps or a unique housekeeping request command for each app?

- It is unknown to the HK application because HK does not send the + It is unknown to the HK application because HK does not send the housekeeping request command(s). These commands are usually sent by the scheduler. However, each CFS application is capable of receiving a unique housekeeping request command. The message ID of this command is specified in the @@ -336,15 +336,15 @@ housekeeping request commands for each app or using a single command for all apps. In the latter case, all the defines would be set to the same value. - + (Q) What is the basic flow of the application?

- The HK application uses a common application format. When the app starts, + The HK application uses a common application format. When the app starts, initialization is performed, then the app enters an infinite loop waiting for commands from the software bus. - + (Q) In general, what is done during initialization?

@@ -356,24 +356,24 @@ variables. If any error is encountered during initialization, the application will send an event or syslog message, then terminate. - + (Q) - How does the app react if the file to load the copy table (during + How does the app react if the file to load the copy table (during initialization) is not found?

HK will send an error event or a syslog message, then terminate. - + (Q) - At what frequency is the housekeeping request command sent to the system + At what frequency is the housekeeping request command sent to the system applications?

The HK application does not send the housekeeping request command to the - system applications. The frequency of the housekeeping request commands is - typically specified in the scheduler table and sent by the scheduler + system applications. The frequency of the housekeeping request commands is + typically specified in the scheduler table and sent by the scheduler application. - + (Q) What factor controls the input message timing?

@@ -382,7 +382,7 @@ command(s). The housekeeping request command(s) are not sent by the HK application. Rather, it is typically sent by the scheduler application. - + (Q) What determines the timing of the combined output messages?

@@ -391,12 +391,12 @@ command periodically. Where 'x' is a parameter in the command that specifies the message ID of the output message to send. - + (Q) How is the format of the combined output messages defined?

- The output message format is defined by the entries in the copy table. If a - format change to one or more output messages is needed, a new table must be + The output message format is defined by the entries in the copy table. If a + format change to one or more output messages is needed, a new table must be loaded. **/ diff --git a/fsw/inc/hk_msg.h b/fsw/inc/hk_msg.h index 91d518a..efccd98 100644 --- a/fsw/inc/hk_msg.h +++ b/fsw/inc/hk_msg.h @@ -73,7 +73,7 @@ typedef struct /** * \brief No-Operation command packet structure * - * For command details see #HK_RESET_CC + * For command details see #HK_RESET_COUNTERS_CC */ typedef struct { diff --git a/fsw/inc/hk_msgdefs.h b/fsw/inc/hk_msgdefs.h index 959646f..3c5fae8 100644 --- a/fsw/inc/hk_msgdefs.h +++ b/fsw/inc/hk_msgdefs.h @@ -86,7 +86,7 @@ * to be designed such that they react to changes in the counter * values that are reset by this command. */ -#define HK_RESET_CC 1 +#define HK_RESET_COUNTERS_CC 1 /**\}*/ diff --git a/fsw/src/hk_app.c b/fsw/src/hk_app.c index ea3ab7d..ad92ce4 100644 --- a/fsw/src/hk_app.c +++ b/fsw/src/hk_app.c @@ -34,6 +34,7 @@ #include "hk_version.h" #include "hk_platform_cfg.h" #include "hk_utils.h" +#include "hk_dispatch.h" #include /************************************************************************ @@ -301,96 +302,12 @@ int32 HK_TableInit(void) return CFE_SUCCESS; } /* HK_TableInit */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Process a command pipe message */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ - CFE_MSG_FcnCode_t CommandCode = 0; - size_t ActualLength = 0; - - CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); - - CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); - - switch (CFE_SB_MsgIdToValue(MessageID)) - { - case HK_SEND_COMBINED_PKT_MID: - if (ActualLength != sizeof(HK_SendCombinedPktCmd_t)) - { - CFE_EVS_SendEvent(HK_MSG_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Msg with Bad length Rcvd: ID = 0x%08lX, Exp Len = %u, Len = %d", - (unsigned long)CFE_SB_MsgIdToValue(MessageID), - (unsigned int)sizeof(HK_SendCombinedPktCmd_t), (int)ActualLength); - } - else - { - HK_SendCombinedHKCmd(BufPtr); - } - break; - - /* Request for HK's Housekeeping data... */ - case HK_SEND_HK_MID: - if (ActualLength != sizeof(HK_SendHkCmd_t)) - { - CFE_EVS_SendEvent(HK_MSG_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Msg with Bad length Rcvd: ID = 0x%08lX, Exp Len = %u, Len = %d", - (unsigned long)CFE_SB_MsgIdToValue(MessageID), (unsigned int)sizeof(HK_SendHkCmd_t), - (int)ActualLength); - } - else - { - /* Send out HK's housekeeping data */ - HK_HousekeepingCmd((CFE_MSG_CommandHeader_t *)BufPtr); - } - /* Check for copy table load and runtime dump request */ - if (HK_CheckStatusOfTables() != HK_SUCCESS) - { - HK_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; - } - break; - - /* HK ground commands */ - case HK_CMD_MID: - - CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); - - switch (CommandCode) - { - case HK_NOOP_CC: - HK_NoopCmd(BufPtr); - break; - - case HK_RESET_CC: - HK_ResetCtrsCmd(BufPtr); - break; - - default: - CFE_EVS_SendEvent(HK_CC_ERR_EID, CFE_EVS_EventType_ERROR, - "Cmd Msg with Invalid command code Rcvd -- ID = 0x%08lX, CC = %d", - (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode); - HK_AppData.ErrCounter++; - break; - } - break; - - /* Incoming housekeeping data from other Subsystems... */ - default: - - HK_ProcessIncomingHkData(BufPtr); - break; - } -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* Send Combined Housekeeping Packet */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr) +void HK_SendCombinedPktCmd(const CFE_SB_Buffer_t *BufPtr) { const HK_SendCombinedPkt_Payload_t *CmdPtr; @@ -404,7 +321,7 @@ void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr) /* Housekeeping request */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void HK_HousekeepingCmd(const CFE_MSG_CommandHeader_t *Msg) +void HK_SendHkCmd(const CFE_SB_Buffer_t *BufPtr) { HK_HkTlm_Payload_t *PayloadPtr; @@ -429,19 +346,10 @@ void HK_HousekeepingCmd(const CFE_MSG_CommandHeader_t *Msg) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr) { - size_t ExpectedLength = sizeof(HK_NoopCmd_t); + CFE_EVS_SendEvent(HK_NOOP_CMD_EID, CFE_EVS_EventType_INFORMATION, "HK No-op command, Version %d.%d.%d.%d", + HK_MAJOR_VERSION, HK_MINOR_VERSION, HK_REVISION, HK_MISSION_REV); - if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_BAD_MSG_LENGTH_RC) - { - HK_AppData.ErrCounter++; - } - else - { - CFE_EVS_SendEvent(HK_NOOP_CMD_EID, CFE_EVS_EventType_INFORMATION, "HK No-op command, Version %d.%d.%d.%d", - HK_MAJOR_VERSION, HK_MINOR_VERSION, HK_REVISION, HK_MISSION_REV); - - HK_AppData.CmdCounter++; - } + HK_AppData.CmdCounter++; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -449,19 +357,10 @@ void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr) /* Reset counters command */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void HK_ResetCtrsCmd(const CFE_SB_Buffer_t *BufPtr) +void HK_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr) { - size_t ExpectedLength = sizeof(HK_ResetCountersCmd_t); - - if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_BAD_MSG_LENGTH_RC) - { - HK_AppData.ErrCounter++; - } - else - { - HK_ResetHkData(); - CFE_EVS_SendEvent(HK_RESET_CNTRS_CMD_EID, CFE_EVS_EventType_DEBUG, "HK Reset Counters command received"); - } + HK_ResetHkData(); + CFE_EVS_SendEvent(HK_RESET_CNTRS_CMD_EID, CFE_EVS_EventType_DEBUG, "HK Reset Counters command received"); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/fsw/src/hk_app.h b/fsw/src/hk_app.h index 0ad95cf..f0fbc26 100644 --- a/fsw/src/hk_app.h +++ b/fsw/src/hk_app.h @@ -135,21 +135,6 @@ int32 HK_AppInit(void); */ int32 HK_TableInit(void); -/** - * \brief Process a command pipe message - * - * \par Description - * Processes a single software bus command pipe message. Checks - * the message and command IDs and calls the appropriate routine - * to handle the command. - * - * \par Assumptions, External Events, and Notes: - * None - * - * \param [in] BufPtr Pointer to Software Bus buffer - */ -void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr); - /** * \brief Send Combined Housekeeping Message * @@ -163,7 +148,7 @@ void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr); * * \param [in] BufPtr Pointer to Software Bus buffer */ -void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr); +void HK_SendCombinedPktCmd(const CFE_SB_Buffer_t *BufPtr); /** * \brief Process housekeeping request @@ -176,9 +161,9 @@ void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr); * this command will increment the cmd error counter if an invalid cmd * length is detected. * - * \param [in] Msg Pointer to command message header + * \param [in] BufPtr Pointer to command message header */ -void HK_HousekeepingCmd(const CFE_MSG_CommandHeader_t *Msg); +void HK_SendHkCmd(const CFE_SB_Buffer_t *BufPtr); /** * \brief Process noop command @@ -208,9 +193,9 @@ void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr); * * \param [in] BufPtr Pointer to Software Bus buffer * - * \sa #HK_RESET_CC + * \sa #HK_RESET_COUNTERS_CC */ -void HK_ResetCtrsCmd(const CFE_SB_Buffer_t *BufPtr); +void HK_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr); /** * \brief Reset housekeeping data @@ -222,7 +207,7 @@ void HK_ResetCtrsCmd(const CFE_SB_Buffer_t *BufPtr); * \par Assumptions, External Events, and Notes: * None * - * \sa #HK_RESET_CC + * \sa #HK_RESET_COUNTERS_CC */ void HK_ResetHkData(void); diff --git a/fsw/src/hk_dispatch.c b/fsw/src/hk_dispatch.c new file mode 100644 index 0000000..c4f6516 --- /dev/null +++ b/fsw/src/hk_dispatch.c @@ -0,0 +1,218 @@ +/************************************************************************ + * NASA Docket No. GSC-18,919-1, and identified as “Core Flight + * System (cFS) Housekeeping (HK) Application version 2.5.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * The CFS Housekeeping (HK) Application file containing the application + * initialization routines, the main routine and the command interface. + */ + +/************************************************************************ +** Includes +*************************************************************************/ +#include "hk_app.h" +#include "hk_events.h" +#include "hk_msgids.h" +#include "hk_dispatch.h" +#include "hk_utils.h" + +#include + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Verify Command Length */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) +{ + int32 Status = HK_SUCCESS; + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ + CFE_MSG_FcnCode_t CommandCode = 0; + size_t ActualLength = 0; + + CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); + + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); + CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); + + CFE_EVS_SendEvent(HK_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Cmd Msg with Bad length Rcvd: ID = 0x%08lX, CC = %d, Exp Len = %d, Len = %d", + (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode, (int)ExpectedLength, + (int)ActualLength); + + Status = HK_BAD_MSG_LENGTH_RC; + } + + return Status; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Verify Non-Command Msg Length (Event is differnt) */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 HK_VerifyMsgLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) +{ + int32 Status = HK_SUCCESS; + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ + size_t ActualLength = 0; + + CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); + + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); + + CFE_EVS_SendEvent(HK_MSG_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Msg with Bad length Rcvd: ID = 0x%08lX, Exp Len = %u, Len = %u", + (unsigned long)CFE_SB_MsgIdToValue(MessageID), (unsigned int)ExpectedLength, + (unsigned int)ActualLength); + + Status = HK_BAD_MSG_LENGTH_RC; + } + + return Status; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Send Combined Housekeeping Packet */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void HK_SendCombinedPktVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) +{ + if (HK_VerifyMsgLength(BufPtr, sizeof(HK_SendCombinedPktCmd_t)) == HK_SUCCESS) + { + HK_SendCombinedPktCmd(BufPtr); + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Housekeeping request */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void HK_SendHkVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) +{ + if (HK_VerifyMsgLength(BufPtr, sizeof(HK_SendHkCmd_t)) == HK_SUCCESS) + { + HK_SendHkCmd(BufPtr); + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Noop command */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void HK_NoopVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) +{ + size_t ExpectedLength = sizeof(HK_NoopCmd_t); + + if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_SUCCESS) + { + HK_NoopCmd(BufPtr); + } + else + { + HK_AppData.ErrCounter++; + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Reset counters command */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void HK_ResetCountersVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) +{ + size_t ExpectedLength = sizeof(HK_ResetCountersCmd_t); + + if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_SUCCESS) + { + HK_ResetCountersCmd(BufPtr); + } + else + { + HK_AppData.ErrCounter++; + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Process a command pipe message */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ + CFE_MSG_FcnCode_t CommandCode = 0; + + CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); + + switch (CFE_SB_MsgIdToValue(MessageID)) + { + case HK_SEND_COMBINED_PKT_MID: + HK_SendCombinedPktVerifyDispatch(BufPtr); + break; + + /* Request for HK's Housekeeping data... */ + case HK_SEND_HK_MID: + /* Send out HK's housekeeping data */ + HK_SendHkVerifyDispatch(BufPtr); + + /* Check for copy table load and runtime dump request */ + if (HK_CheckStatusOfTables() != HK_SUCCESS) + { + HK_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; + } + break; + + /* HK ground commands */ + case HK_CMD_MID: + + CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); + + switch (CommandCode) + { + case HK_NOOP_CC: + HK_NoopVerifyDispatch(BufPtr); + break; + + case HK_RESET_COUNTERS_CC: + HK_ResetCountersVerifyDispatch(BufPtr); + break; + + default: + CFE_EVS_SendEvent(HK_CC_ERR_EID, CFE_EVS_EventType_ERROR, + "Cmd Msg with Invalid command code Rcvd -- ID = 0x%08lX, CC = %d", + (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode); + HK_AppData.ErrCounter++; + break; + } + break; + + /* Incoming housekeeping data from other Subsystems... */ + default: + HK_ProcessIncomingHkData(BufPtr); + break; + } +} diff --git a/fsw/src/hk_dispatch.h b/fsw/src/hk_dispatch.h new file mode 100644 index 0000000..8735f3e --- /dev/null +++ b/fsw/src/hk_dispatch.h @@ -0,0 +1,71 @@ +/************************************************************************ + * NASA Docket No. GSC-18,919-1, and identified as “Core Flight + * System (cFS) Housekeeping (HK) Application version 2.5.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * The CFS Housekeeping (HK) Dispatch header file + */ + +#ifndef HK_DISPATCH_H +#define HK_DISPATCH_H + +/************************************************************************ + * Includes + ************************************************************************/ + +#include "cfe.h" + +/************************************************************************ + * Exported Functions + ************************************************************************/ + +/** + * \brief Verify length of HK commands + * + * \par Description + * Function called when an HK command is received. + * + * \par Assumptions, External Events, and Notes: + * None + * + * \param[in] BufPtr Pointer to the Software Buss Buffer + * \param[in] ExpectedLength The expected lenght of the command + * + * \return Command Length Status + * \retval #HK_SUCCESS Length Valid + * \retval #HK_BAD_MSG_LENGTH_RC \copydoc HK_BAD_MSG_LENGTH_RC + */ +int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength); + +/** + * \brief Process a command pipe message + * + * \par Description + * Processes a single software bus command pipe message. Checks + * the message and command IDs and calls the appropriate routine + * to handle the command. + * + * \par Assumptions, External Events, and Notes: + * None + * + * \param [in] BufPtr Pointer to Software Bus buffer + */ +void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr); + +#endif diff --git a/fsw/src/hk_utils.c b/fsw/src/hk_utils.c index 20d1bf1..4651aa2 100644 --- a/fsw/src/hk_utils.c +++ b/fsw/src/hk_utils.c @@ -639,36 +639,6 @@ void HK_SetFlagsToNotPresent(CFE_SB_MsgId_t OutPkt) } } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Verify Command Length */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) -{ - int32 Status = HK_SUCCESS; - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ - CFE_MSG_FcnCode_t CommandCode = 0; - size_t ActualLength = 0; - - CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); - - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); - CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); - - CFE_EVS_SendEvent(HK_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Cmd Msg with Bad length Rcvd: ID = 0x%08lX, CC = %d, Exp Len = %d, Len = %d", - (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode, (int)ExpectedLength, - (int)ActualLength); - - Status = HK_BAD_MSG_LENGTH_RC; - } - - return Status; -} - /************************/ /* End of File Comment */ /************************/ diff --git a/fsw/src/hk_utils.h b/fsw/src/hk_utils.h index 5a57b1b..3201195 100644 --- a/fsw/src/hk_utils.h +++ b/fsw/src/hk_utils.h @@ -223,22 +223,4 @@ int32 HK_CheckForMissingData(CFE_SB_MsgId_t OutPktToCheck, CFE_SB_MsgId_t *Missi */ void HK_SetFlagsToNotPresent(CFE_SB_MsgId_t OutPkt); -/** - * \brief Verify length of HK commands - * - * \par Description - * Function called when an HK command is received. - * - * \par Assumptions, External Events, and Notes: - * None - * - * \param[in] BufPtr Pointer to the Software Buss Buffer - * \param[in] ExpectedLength The expected lenght of the command - * - * \return Command Length Status - * \retval #HK_SUCCESS Length Valid - * \retval #HK_BAD_MSG_LENGTH_RC \copydoc HK_BAD_MSG_LENGTH_RC - */ -int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength); - #endif diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index bddf45a..dd1d6be 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -12,6 +12,7 @@ add_cfe_coverage_stubs("hk_internal" stubs/hk_global_stubs.c stubs/hk_utils_stubs.c stubs/hk_app_stubs.c + stubs/hk_dispatch_stubs.c ) # Link with the cfe core stubs and unit test assert libs diff --git a/unit-test/hk_app_tests.c b/unit-test/hk_app_tests.c index c855115..416ce49 100644 --- a/unit-test/hk_app_tests.c +++ b/unit-test/hk_app_tests.c @@ -873,322 +873,19 @@ void Test_HK_TableInit_ProcessNewCpyTblFail(void) /* */ /**********************************************************************/ -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a "Send Combined Packet" message - * received with the expected length. - */ -void Test_HK_AppPipe_CombinedPktLengthOk(void) -{ - /* Arrange */ - uint8 call_count_HK_SendCombinedHKPacket; - size_t forced_Size = sizeof(HK_SendCombinedPktCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID); - CFE_SB_Buffer_t DummyBuf; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - call_count_HK_SendCombinedHKPacket = UT_GetStubCount(UT_KEY(HK_SendCombinedHkPacket)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); - UtAssert_INT32_EQ(call_count_HK_SendCombinedHKPacket, 1); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a "Send Combined Packet" message - * received with an incorrect length. - */ -void Test_HK_AppPipe_CombinedPktBadLength(void) -{ - /* Arrange */ - uint8 call_count_HK_SendCombinedHKPacket; - size_t forced_Size = sizeof(HK_SendCombinedPktCmd_t) + 1; - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID); - CFE_SB_Buffer_t DummyBuf; - - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Msg with Bad length Rcvd: ID = 0x%%08lX, Exp Len = %%u, Len = %%d"); - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - call_count_HK_SendCombinedHKPacket = UT_GetStubCount(UT_KEY(HK_SendCombinedHkPacket)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_MSG_LEN_ERR_EID); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - UtAssert_INT32_EQ(call_count_HK_SendCombinedHKPacket, 0); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a "Housekeeping Request" message - * received with the expected length. - */ -void Test_HK_AppPipe_HkReqLengthOk(void) -{ - /* Arrange */ - uint8 call_count_CFE_SB_TransmitMsg; - size_t forced_Size = sizeof(HK_SendHkCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_SEND_HK_MID); - CFE_SB_Buffer_t DummyBuf; - - UT_SetDefaultReturnValue(UT_KEY(HK_CheckStatusOfTables), HK_SUCCESS); - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - call_count_CFE_SB_TransmitMsg = UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); - - /* call_count_CFE_SB_TransmitMsg indicates indirectly that - * HK_HousekeepingCmd was called */ - UtAssert_INT32_EQ(call_count_CFE_SB_TransmitMsg, 1); - - UtAssert_INT32_EQ(HK_AppData.RunStatus, 0); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a "Housekeeping Request" message - * received with an incorrect length. - */ -void Test_HK_AppPipe_HkReqBadLength(void) -{ - /* Arrange */ - uint8 call_count_CFE_SB_TransmitMsg; - size_t forced_Size = sizeof(HK_SendHkCmd_t) + 1; - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_SEND_HK_MID); - CFE_SB_Buffer_t DummyBuf; - - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Msg with Bad length Rcvd: ID = 0x%%08lX, Exp Len = %%u, Len = %%d"); - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - call_count_CFE_SB_TransmitMsg = UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_MSG_LEN_ERR_EID); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - /* call_count_CFE_SB_TransmitMsg indicates indirectly that - * HK_HousekeepingCmd was called */ - UtAssert_INT32_EQ(call_count_CFE_SB_TransmitMsg, 0); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a "Housekeeping Request" message - * received with the expected length, but during processing - * of the message, the HK_CheckStatusOfTables function fails. - */ -void Test_HK_AppPipe_HkReqBadTblStatus(void) -{ - /* Arrange */ - size_t forced_Size = sizeof(HK_SendHkCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_SEND_HK_MID); - CFE_SB_Buffer_t DummyBuf; - - UT_SetDefaultReturnValue(UT_KEY(HK_CheckStatusOfTables), !HK_SUCCESS); - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); - - UtAssert_INT32_EQ(HK_AppData.RunStatus, CFE_ES_RunStatus_APP_ERROR); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a Command message is received with a - * "No Operation" command code. - */ -void Test_HK_AppPipe_NoopCmd(void) -{ - /* Arrange */ - size_t forced_Size = sizeof(HK_NoopCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_CMD_MID); - CFE_MSG_FcnCode_t forced_CmdCode = HK_NOOP_CC; - CFE_SB_Buffer_t DummyBuf; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(HK_AppData.ErrCounter, 0); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a Command message is received with a - * "Reset" command code. - */ -void Test_HK_AppPipe_ResetCmd(void) -{ - /* Arrange */ - size_t forced_Size = sizeof(HK_ResetCountersCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_CMD_MID); - CFE_MSG_FcnCode_t forced_CmdCode = HK_RESET_CC; - CFE_SB_Buffer_t DummyBuf; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(HK_AppData.ErrCounter, 0); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a Command message is received with an - * unknown command code. - */ -void Test_HK_AppPipe_UnknownCmd(void) -{ - /* Arrange */ - size_t forced_Size = sizeof(HK_NoopCmd_t); - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(HK_CMD_MID); - CFE_MSG_FcnCode_t forced_CmdCode = 47; /* unknown CC */ - CFE_SB_Buffer_t DummyBuf; - - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Cmd Msg with Invalid command code Rcvd -- ID = 0x%%08lX, CC = %%d"); - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_CC_ERR_EID); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); - - UtAssert_INT32_EQ(HK_AppData.ErrCounter, 1); -} - -/* - * Function under test: HK_AppPipe - * - * Case: Tests the case in which a message is received with an unknown - * message ID, triggering a call to HK_ProcessIncomingHkData. - */ -void Test_HK_AppPipe_ProcessIncoming(void) -{ - /* Arrange */ - uint8 call_count_HK_ProcessIncomingHkData; - size_t forced_Size = sizeof(HK_NoopCmd_t); - CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; /* Non HK MID */ - CFE_SB_Buffer_t DummyBuf; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - HK_AppPipe(&DummyBuf); - - call_count_HK_ProcessIncomingHkData = UT_GetStubCount(UT_KEY(HK_ProcessIncomingHkData)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_HK_ProcessIncomingHkData, 1); -} - /**********************************************************************/ /* */ -/* Test functions for HK_SendCombinedHKCmd */ +/* Test functions for HK_SendCombinedPktCmd */ /* */ /**********************************************************************/ /* - * Function under test: HK_SendCombinedHKCmd + * Function under test: HK_SendCombinedPktCmd * - * Case: Tests the nominal case of the HK_SendCombinedHKCmd. Note that + * Case: Tests the nominal case of the HK_SendCombinedPktCmd. Note that * the function under test has no branches. */ -void Test_HK_SendCombinedHKCmd(void) +void Test_HK_SendCombinedPktCmd(void) { union { @@ -1199,7 +896,7 @@ void Test_HK_SendCombinedHKCmd(void) memset(&msgbuf, 0, sizeof(msgbuf)); /* Act */ - HK_SendCombinedHKCmd(&msgbuf.sbbuf); + HK_SendCombinedPktCmd(&msgbuf.sbbuf); /* Assert */ UtAssert_STUB_COUNT(HK_SendCombinedHkPacket, 1); @@ -1207,23 +904,23 @@ void Test_HK_SendCombinedHKCmd(void) /**********************************************************************/ /* */ -/* Test functions for HK_HousekeepingCmd */ +/* Test functions for HK_SendHkCmd */ /* */ /**********************************************************************/ /* - * Function under test: HK_HousekeepingCmd + * Function under test: HK_SendHkCmd * - * Case: Tests the nominal case of the HK_HousekeepingCmd. Note that + * Case: Tests the nominal case of the HK_SendHkCmd. Note that * the function under test has no branches. */ -void Test_HK_HousekeepingCmd(void) +void Test_HK_SendHkCmd(void) { /* Arrange */ - CFE_MSG_CommandHeader_t DummyMsg; - uint8 call_count_CFE_SB_TimeStampMsg; - uint8 call_count_CFE_SB_TransmitMsg; - HK_HkTlm_Payload_t * PayloadPtr; + CFE_SB_Buffer_t DummyMsg; + uint8 call_count_CFE_SB_TimeStampMsg; + uint8 call_count_CFE_SB_TransmitMsg; + HK_HkTlm_Payload_t *PayloadPtr; /* Setup app data values */ HK_AppData.CmdCounter = 1; @@ -1235,7 +932,7 @@ void Test_HK_HousekeepingCmd(void) memset(&DummyMsg, 0, sizeof(DummyMsg)); /* Act */ - HK_HousekeepingCmd(&DummyMsg); + HK_SendHkCmd(&DummyMsg); call_count_CFE_SB_TimeStampMsg = UT_GetStubCount(UT_KEY(CFE_SB_TimeStampMsg)); call_count_CFE_SB_TransmitMsg = UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)); @@ -1265,7 +962,7 @@ void Test_HK_HousekeepingCmd(void) * Case: Tests the case in which the HK_NoopCmd function processes a * Noop command message with the correct length. */ -void Test_HK_NoopCmd_LengthOk(void) +void Test_HK_NoopCmd(void) { /* Arrange */ CFE_SB_Buffer_t DummyBuf; @@ -1273,8 +970,6 @@ void Test_HK_NoopCmd_LengthOk(void) char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "HK No-op command, Version %%d.%%d.%%d.%%d"); - UT_SetDefaultReturnValue(UT_KEY(HK_VerifyCmdLength), CFE_SUCCESS); - /* Act */ HK_NoopCmd(&DummyBuf); @@ -1295,43 +990,19 @@ void Test_HK_NoopCmd_LengthOk(void) UtAssert_INT32_EQ(HK_AppData.ErrCounter, 0); } -/* - * Function under test: HK_NoopCmd - * - * Case: Tests the case in which the HK_NoopCmd function processes a - * Noop command message with an incorrect length. - */ -void Test_HK_NoopCmd_LengthError(void) -{ - /* Arrange */ - CFE_SB_Buffer_t DummyBuf; - - UT_SetDefaultReturnValue(UT_KEY(HK_VerifyCmdLength), HK_BAD_MSG_LENGTH_RC); - - /* Act */ - HK_NoopCmd(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); - UtAssert_INT32_EQ(HK_AppData.CmdCounter, 0); - UtAssert_INT32_EQ(HK_AppData.ErrCounter, 1); -} - /**********************************************************************/ /* */ -/* Test functions for HK_ResetCtrsCmd */ +/* Test functions for HK_ResetCountersCmd */ /* */ /**********************************************************************/ /* - * Function under test: HK_ResetCtrsCmd + * Function under test: HK_ResetCountersCmd * - * Case: Tests the case in which the HK_ResetCtrsCmd function processes + * Case: Tests the case in which the HK_ResetCountersCmd function processes * a Reset Counters command message with the correct length. */ -void Test_HK_ResetCtrsCmd_LengthOk(void) +void Test_HK_ResetCountersCmd(void) { /* Arrange */ CFE_SB_Buffer_t DummyBuf; @@ -1340,10 +1011,8 @@ void Test_HK_ResetCtrsCmd_LengthOk(void) char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "HK Reset Counters command received"); - UT_SetDefaultReturnValue(UT_KEY(HK_VerifyCmdLength), CFE_SUCCESS); - /* Act */ - HK_ResetCtrsCmd(&DummyBuf); + HK_ResetCountersCmd(&DummyBuf); call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); @@ -1363,31 +1032,6 @@ void Test_HK_ResetCtrsCmd_LengthOk(void) UtAssert_INT32_EQ(HK_AppData.ErrCounter, 0); } -/* - * Function under test: HK_ResetCtrsCmd - * - * Case: Tests the case in which the HK_ResetCtrsCmd function processes - * a Reset Counters command message with an incorrect length. - */ -void Test_HK_ResetCtrsCmd_LengthError(void) -{ - /* Arrange */ - CFE_SB_Buffer_t DummyBuf; - - UT_SetDefaultReturnValue(UT_KEY(HK_VerifyCmdLength), HK_BAD_MSG_LENGTH_RC); - - /* Act */ - HK_ResetCtrsCmd(&DummyBuf); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); - - UtAssert_INT32_EQ(HK_AppData.CmdCounter, 0); - UtAssert_INT32_EQ(HK_AppData.ErrCounter, 1); -} - /**********************************************************************/ /* */ /* Test functions for HK_ResetHkData */ @@ -1466,32 +1110,17 @@ void UtTest_Setup(void) UtTest_Add(Test_HK_TableInit_ProcessNewCpyTblFail, HK_Test_Setup, HK_Test_TearDown, "Test_HK_TableInit_ProcessNewCpyTblFail"); - /* Test functions for HK_AppPipe */ - UtTest_Add(Test_HK_AppPipe_CombinedPktLengthOk, HK_Test_Setup, HK_Test_TearDown, - "Test_HK_AppPipe_CombinedPktLengthOk"); - UtTest_Add(Test_HK_AppPipe_CombinedPktBadLength, HK_Test_Setup, HK_Test_TearDown, - "Test_HK_AppPipe_CombinedPktBadLength"); - UtTest_Add(Test_HK_AppPipe_HkReqLengthOk, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_HkReqLengthOk"); - UtTest_Add(Test_HK_AppPipe_HkReqBadLength, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_HkReqBadLength"); - UtTest_Add(Test_HK_AppPipe_HkReqBadTblStatus, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_HkReqBadTblStatus"); - UtTest_Add(Test_HK_AppPipe_NoopCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_NoopCmd"); - UtTest_Add(Test_HK_AppPipe_ResetCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_ResetCmd"); - UtTest_Add(Test_HK_AppPipe_UnknownCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_UnknownCmd"); - UtTest_Add(Test_HK_AppPipe_ProcessIncoming, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_ProcessIncoming"); - /* Test functions for HK_SendCombinedHkPacket */ - UtTest_Add(Test_HK_SendCombinedHKCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_SendCombinedHKCmd"); + UtTest_Add(Test_HK_SendCombinedPktCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_SendCombinedPktCmd"); - /* Test functions for HK_HousekeepingCmd */ - UtTest_Add(Test_HK_HousekeepingCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_HousekeepingCmd"); + /* Test functions for HK_SendHkCmd */ + UtTest_Add(Test_HK_SendHkCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_SendHkCmd"); /* Test functions for HK_NoopCmd */ - UtTest_Add(Test_HK_NoopCmd_LengthOk, HK_Test_Setup, HK_Test_TearDown, "Test_HK_NoopCmd_LengthOk"); - UtTest_Add(Test_HK_NoopCmd_LengthError, HK_Test_Setup, HK_Test_TearDown, "Test_HK_NoopCmd_LengthError"); + UtTest_Add(Test_HK_NoopCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_NoopCmd"); - /* Test functions for HK_ResetCtrsCmd */ - UtTest_Add(Test_HK_ResetCtrsCmd_LengthOk, HK_Test_Setup, HK_Test_TearDown, "Test_HK_ResetCtrsCmd_LengthOk"); - UtTest_Add(Test_HK_ResetCtrsCmd_LengthError, HK_Test_Setup, HK_Test_TearDown, "Test_HK_ResetCtrsCmd_LengthError"); + /* Test functions for HK_ResetCountersCmd */ + UtTest_Add(Test_HK_ResetCountersCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_ResetCountersCmd"); /* Test functions for HK_ResetHkData */ UtTest_Add(Test_HK_ResetHkData, HK_Test_Setup, HK_Test_TearDown, "Test_HK_ResetHkData"); diff --git a/unit-test/hk_dispatch_tests.c b/unit-test/hk_dispatch_tests.c new file mode 100644 index 0000000..4b9300e --- /dev/null +++ b/unit-test/hk_dispatch_tests.c @@ -0,0 +1,253 @@ +/************************************************************************ + * NASA Docket No. GSC-18,919-1, and identified as “Core Flight + * System (cFS) Housekeeping (HK) Application version 2.5.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* + * App Includes + */ + +#include "hk_dispatch.h" +#include "hk_msg.h" +#include "hk_events.h" +#include "hk_msgids.h" +#include "hk_test_utils.h" + +/* UT includes */ +#include "uttest.h" +#include "utassert.h" +#include "utstubs.h" + +#include +#include +#include "cfe.h" + +/* + * Helper functions + */ +static void HK_Dispatch_Test_SetupMsg(CFE_SB_MsgId_t MsgId, CFE_MSG_FcnCode_t FcnCode, size_t MsgSize) +{ + /* Note some paths get the MsgId/FcnCode multiple times, so register accordingly, just in case */ + CFE_SB_MsgId_t RegMsgId[2] = {MsgId, MsgId}; + CFE_MSG_FcnCode_t RegFcnCode[2] = {FcnCode, FcnCode}; + size_t RegMsgSize[2] = {MsgSize, MsgSize}; + + UT_ResetState(UT_KEY(CFE_MSG_GetMsgId)); + UT_ResetState(UT_KEY(CFE_MSG_GetFcnCode)); + UT_ResetState(UT_KEY(CFE_MSG_GetSize)); + + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), RegMsgId, sizeof(RegMsgId), true); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), RegFcnCode, sizeof(RegFcnCode), true); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), RegMsgSize, sizeof(RegMsgSize), true); +} + +/**********************************************************************/ +/* */ +/* Test functions for HK_AppPipe */ +/* */ +/**********************************************************************/ + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a "Send Combined Packet" message + * received with the expected length. + */ +void Test_HK_AppPipe_SendCombinedPktCmd(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID), 0, sizeof(HK_SendCombinedPktCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_SendCombinedPktCmd, 1); + + /* Bad Length */ + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID), 0, 1); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_SendCombinedPktCmd, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_MSG_LEN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); +} + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a "Housekeeping Request" message + * received with the expected length. + */ +void Test_HK_AppPipe_SendHkCmd(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_SEND_HK_MID), 0, sizeof(HK_SendHkCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_SendHkCmd, 1); + + /* Bad Length */ + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_SEND_HK_MID), 0, 1); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_SendHkCmd, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_MSG_LEN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + + /* Bad Table Status */ + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_SEND_HK_MID), 0, sizeof(HK_SendHkCmd_t)); + UT_SetDefaultReturnValue(UT_KEY(HK_CheckStatusOfTables), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_SendHkCmd, 2); + UtAssert_UINT32_EQ(HK_AppData.RunStatus, CFE_ES_RunStatus_APP_ERROR); +} + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a Command message is received with a + * "No Operation" command code. + */ +void Test_HK_AppPipe_NoopCmd(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_NOOP_CC, sizeof(HK_NoopCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_NoopCmd, 1); + UtAssert_ZERO(HK_AppData.ErrCounter); + + /* Bad Length */ + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_NOOP_CC, 1); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_NoopCmd, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_CMD_LEN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + UtAssert_UINT8_EQ(HK_AppData.ErrCounter, 1); +} + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a Command message is received with a + * "Reset" command code. + */ +void Test_HK_AppPipe_ResetCountersCmd(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_RESET_COUNTERS_CC, sizeof(HK_ResetCountersCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_ResetCountersCmd, 1); + UtAssert_ZERO(HK_AppData.ErrCounter); + + /* Bad Length */ + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_RESET_COUNTERS_CC, 1); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_ResetCountersCmd, 1); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_CMD_LEN_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + UtAssert_UINT8_EQ(HK_AppData.ErrCounter, 1); +} + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a Command message is received with an + * unknown command code. + */ +void Test_HK_AppPipe_UnknownCmd(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(CFE_SB_ValueToMsgId(HK_CMD_MID), 47, sizeof(HK_NoopCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_CC_ERR_EID); + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); + UtAssert_UINT8_EQ(HK_AppData.ErrCounter, 1); +} + +/* + * Function under test: HK_AppPipe + * + * Case: Tests the case in which a message is received with an unknown + * message ID, triggering a call to HK_ProcessIncomingHkData. + */ +void Test_HK_AppPipe_ProcessIncoming(void) +{ + CFE_SB_Buffer_t Buf; + + memset(&Buf, 0, sizeof(Buf)); + HK_Dispatch_Test_SetupMsg(HK_UT_MID_100, 0, sizeof(HK_NoopCmd_t)); + + /* Act */ + HK_AppPipe(&Buf); + + UtAssert_STUB_COUNT(HK_ProcessIncomingHkData, 1); +} + +/****************************************************************************/ + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + UtTest_Add(Test_HK_AppPipe_SendCombinedPktCmd, HK_Test_Setup, HK_Test_TearDown, + "Test_HK_AppPipe_SendCombinedPktCmd"); + UtTest_Add(Test_HK_AppPipe_SendHkCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_SendHkCmd"); + UtTest_Add(Test_HK_AppPipe_NoopCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_NoopCmd"); + UtTest_Add(Test_HK_AppPipe_ResetCountersCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_ResetCountersCmd"); + UtTest_Add(Test_HK_AppPipe_UnknownCmd, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_UnknownCmd"); + UtTest_Add(Test_HK_AppPipe_ProcessIncoming, HK_Test_Setup, HK_Test_TearDown, "Test_HK_AppPipe_ProcessIncoming"); +} diff --git a/unit-test/hk_utils_tests.c b/unit-test/hk_utils_tests.c index e1ef7b2..d4e4507 100644 --- a/unit-test/hk_utils_tests.c +++ b/unit-test/hk_utils_tests.c @@ -1908,89 +1908,6 @@ void Test_HK_SetFlagsToNotPresent(void) UtAssert_INT32_EQ(EntriesWithDataPresent, 1); } -/**********************************************************************/ -/* */ -/* Test functions for HK_VerifyCmdLength */ -/* */ -/**********************************************************************/ - -/* - * Function under test: HK_VerifyCmdLength - * - * Case: Tests the case in which the provided message has the expected - * length. - */ -void Test_HK_VerifyCmdLength_LengthOk(void) -{ - /* Arrange */ - int32 ReturnValue = 0; - size_t forced_Size = 10; /* forced size matches the ExpectedLength */ - size_t ExpectedLength = forced_Size; - CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; - CFE_MSG_FcnCode_t forced_CmdCode = 1; - CFE_SB_Buffer_t DummyBuffer; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - ReturnValue = HK_VerifyCmdLength(&DummyBuffer, ExpectedLength); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(ReturnValue, HK_SUCCESS); - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0); -} - -/* - * Function under test: HK_VerifyCmdLength - * - * Case: Tests the case in which the provided message does not have - * the expected length. - */ -void Test_HK_VerifyCmdLength_LengthError(void) -{ - /* Arrange */ - int32 ReturnValue = 0; - size_t forced_Size = 10; - size_t ExpectedLength = forced_Size + 1; /* force a mismatch */ - CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; - CFE_MSG_FcnCode_t forced_CmdCode = 1; - CFE_SB_Buffer_t DummyBuffer; - - /* event message setup */ - int32 strCmpResult; - char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH]; - - snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, - "Cmd Msg with Bad length Rcvd: ID = 0x%%08lX, CC = %%d, Exp Len = %%d, Len = %%d"); - - /* MSG API setup */ - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - - /* Act */ - ReturnValue = HK_VerifyCmdLength(&DummyBuffer, ExpectedLength); - - call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent)); - - /* Assert */ - UtAssert_INT32_EQ(ReturnValue, HK_BAD_MSG_LENGTH_RC); - - UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HK_CMD_LEN_ERR_EID); - - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - - strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); - - UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec); -} - /****************************************************************************/ /* @@ -2108,9 +2025,4 @@ void UtTest_Setup(void) /* Test functions for HK_SetFlagsToNotPresent */ UtTest_Add(Test_HK_SetFlagsToNotPresent, HK_Test_Setup, HK_Test_TearDown, "Test_HK_SetFlagsToNotPresent"); - - /* Test functions for HK_VerifyCmdLength */ - UtTest_Add(Test_HK_VerifyCmdLength_LengthOk, HK_Test_Setup, HK_Test_TearDown, "Test_HK_VerifyCmdLength_LengthOk"); - UtTest_Add(Test_HK_VerifyCmdLength_LengthError, HK_Test_Setup, HK_Test_TearDown, - "Test_HK_VerifyCmdLength_LengthError"); } diff --git a/unit-test/stubs/hk_app_stubs.c b/unit-test/stubs/hk_app_stubs.c index 754480a..955aa8c 100644 --- a/unit-test/stubs/hk_app_stubs.c +++ b/unit-test/stubs/hk_app_stubs.c @@ -53,73 +53,61 @@ void HK_AppMain(void) /* * ---------------------------------------------------- - * Generated stub function for HK_AppPipe() - * ---------------------------------------------------- - */ -void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr) -{ - UT_GenStub_AddParam(HK_AppPipe, const CFE_SB_Buffer_t *, BufPtr); - - UT_GenStub_Execute(HK_AppPipe, Basic, NULL); -} - -/* - * ---------------------------------------------------- - * Generated stub function for HK_HousekeepingCmd() + * Generated stub function for HK_NoopCmd() * ---------------------------------------------------- */ -void HK_HousekeepingCmd(const CFE_MSG_CommandHeader_t *Msg) +void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr) { - UT_GenStub_AddParam(HK_HousekeepingCmd, const CFE_MSG_CommandHeader_t *, Msg); + UT_GenStub_AddParam(HK_NoopCmd, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_Execute(HK_HousekeepingCmd, Basic, NULL); + UT_GenStub_Execute(HK_NoopCmd, Basic, NULL); } /* * ---------------------------------------------------- - * Generated stub function for HK_NoopCmd() + * Generated stub function for HK_ResetCountersCmd() * ---------------------------------------------------- */ -void HK_NoopCmd(const CFE_SB_Buffer_t *BufPtr) +void HK_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr) { - UT_GenStub_AddParam(HK_NoopCmd, const CFE_SB_Buffer_t *, BufPtr); + UT_GenStub_AddParam(HK_ResetCountersCmd, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_Execute(HK_NoopCmd, Basic, NULL); + UT_GenStub_Execute(HK_ResetCountersCmd, Basic, NULL); } /* * ---------------------------------------------------- - * Generated stub function for HK_ResetCtrsCmd() + * Generated stub function for HK_ResetHkData() * ---------------------------------------------------- */ -void HK_ResetCtrsCmd(const CFE_SB_Buffer_t *BufPtr) +void HK_ResetHkData(void) { - UT_GenStub_AddParam(HK_ResetCtrsCmd, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_Execute(HK_ResetCtrsCmd, Basic, NULL); + UT_GenStub_Execute(HK_ResetHkData, Basic, NULL); } /* * ---------------------------------------------------- - * Generated stub function for HK_ResetHkData() + * Generated stub function for HK_SendCombinedPktCmd() * ---------------------------------------------------- */ -void HK_ResetHkData(void) +void HK_SendCombinedPktCmd(const CFE_SB_Buffer_t *BufPtr) { + UT_GenStub_AddParam(HK_SendCombinedPktCmd, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_Execute(HK_ResetHkData, Basic, NULL); + UT_GenStub_Execute(HK_SendCombinedPktCmd, Basic, NULL); } /* * ---------------------------------------------------- - * Generated stub function for HK_SendCombinedHKCmd() + * Generated stub function for HK_SendHkCmd() * ---------------------------------------------------- */ -void HK_SendCombinedHKCmd(const CFE_SB_Buffer_t *BufPtr) +void HK_SendHkCmd(const CFE_SB_Buffer_t *BufPtr) { - UT_GenStub_AddParam(HK_SendCombinedHKCmd, const CFE_SB_Buffer_t *, BufPtr); + UT_GenStub_AddParam(HK_SendHkCmd, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_Execute(HK_SendCombinedHKCmd, Basic, NULL); + UT_GenStub_Execute(HK_SendHkCmd, Basic, NULL); } /* diff --git a/unit-test/stubs/hk_dispatch_stubs.c b/unit-test/stubs/hk_dispatch_stubs.c new file mode 100644 index 0000000..02dd873 --- /dev/null +++ b/unit-test/stubs/hk_dispatch_stubs.c @@ -0,0 +1,56 @@ +/************************************************************************ + * NASA Docket No. GSC-18,919-1, and identified as “Core Flight + * System (cFS) Housekeeping (HK) Application version 2.5.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Auto-Generated stub implementations for functions defined in hk_dispatch header + */ + +#include "hk_dispatch.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for HK_AppPipe() + * ---------------------------------------------------- + */ +void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr) +{ + UT_GenStub_AddParam(HK_AppPipe, const CFE_SB_Buffer_t *, BufPtr); + + UT_GenStub_Execute(HK_AppPipe, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for HK_VerifyCmdLength() + * ---------------------------------------------------- + */ +int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) +{ + UT_GenStub_SetupReturnBuffer(HK_VerifyCmdLength, int32); + + UT_GenStub_AddParam(HK_VerifyCmdLength, const CFE_SB_Buffer_t *, BufPtr); + UT_GenStub_AddParam(HK_VerifyCmdLength, size_t, ExpectedLength); + + UT_GenStub_Execute(HK_VerifyCmdLength, Basic, NULL); + + return UT_GenStub_GetReturnValue(HK_VerifyCmdLength, int32); +} diff --git a/unit-test/stubs/hk_utils_stubs.c b/unit-test/stubs/hk_utils_stubs.c index e3a627d..467d51e 100644 --- a/unit-test/stubs/hk_utils_stubs.c +++ b/unit-test/stubs/hk_utils_stubs.c @@ -170,20 +170,3 @@ int32 HK_ValidateHkCopyTable(void *TblPtr) return UT_GenStub_GetReturnValue(HK_ValidateHkCopyTable, int32); } - -/* - * ---------------------------------------------------- - * Generated stub function for HK_VerifyCmdLength() - * ---------------------------------------------------- - */ -int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) -{ - UT_GenStub_SetupReturnBuffer(HK_VerifyCmdLength, int32); - - UT_GenStub_AddParam(HK_VerifyCmdLength, const CFE_SB_Buffer_t *, BufPtr); - UT_GenStub_AddParam(HK_VerifyCmdLength, size_t, ExpectedLength); - - UT_GenStub_Execute(HK_VerifyCmdLength, Basic, NULL); - - return UT_GenStub_GetReturnValue(HK_VerifyCmdLength, int32); -}