Skip to content

Commit

Permalink
IC:Caelum-rc4+dev11: cFE v7.0.0-rc4+dev143
Browse files Browse the repository at this point in the history
- Endian macro mask before shift to avoid shift overflow warning
- Add macro for initializing command header
- Add CFE_ES_StatusToString and CFE_STATUS_C
- See <nasa/cFS#492>
  • Loading branch information
astrogeco committed Jun 22, 2022
2 parents 10898c9 + 68931c6 commit cacc83a
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ The detailed cFE user's guide can be viewed at <https://github.com/nasa/cFE/blob

## Changelog

### Development Build: v7.0.0-rc4+dev143

- Endian macro mask before shift to avoid shift overflow warning
- Add macro for initializing command header
- Add CFE_ES_StatusToString and CFE_STATUS_C
- See <https://github.com/nasa/cFS/pull/492>

### Development Build: v7.0.0-rc4+dev136

- Resolve UT uninit var static analysis warnings
Expand Down
1 change: 1 addition & 0 deletions docs/src/cfe_api.dox
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<LI> #CFE_ES_CalculateCRC - \copybrief CFE_ES_CalculateCRC
<LI> #CFE_ES_WriteToSysLog - \copybrief CFE_ES_WriteToSysLog
<LI> #CFE_ES_ProcessAsyncEvent - \copybrief CFE_ES_ProcessAsyncEvent
<LI> #CFE_ES_StatusToString - \copybrief CFE_ES_StatusToString
</UL>
<LI> \ref CFEAPIESResourceID
<UL>
Expand Down
1 change: 1 addition & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_cfe_app(cfe_testcase
src/cfe_test_table.c
src/es_application_control_test.c
src/es_behavior_test.c
src/es_error_test.c
src/es_info_test.c
src/es_task_test.c
src/es_cds_test.c
Expand Down
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void CFE_TestMain(void)
ESBehaviorestSetup();
ESCDSTestSetup();
ESCounterTestSetup();
ESErrorTestSetup();
ESInfoTestSetup();
ESMemPoolTestSetup();
ESMiscTestSetup();
Expand Down
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void ESApplicationControlTestSetup(void);
void ESBehaviorestSetup(void);
void ESCDSTestSetup(void);
void ESCounterTestSetup(void);
void ESErrorTestSetup(void);
void ESInfoTestSetup(void);
void ESMemPoolTestSetup(void);
void ESMiscTestSetup(void);
Expand Down
58 changes: 58 additions & 0 deletions modules/cfe_testcase/src/es_error_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
* Functional test of basic ES Error APIs
*/

/*
* Includes
*/

#include "cfe_test.h"

void TestStatusToString_Helper(CFE_Status_t status)
{
CFE_StatusString_t status_string;
char * rtn_addr;
char expected[CFE_STATUS_STRING_LENGTH + 1];

/* Used oversized string to test for truncation */
snprintf(expected, sizeof(expected), "0x%08x", (unsigned int)status);
rtn_addr = CFE_ES_StatusToString(status, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
}

void TestStatusToString(void)
{
/* NULL test */
UtAssert_ADDRESS_EQ(CFE_ES_StatusToString(CFE_SUCCESS, NULL), NULL);

/* Status value tests */
TestStatusToString_Helper(CFE_SUCCESS);
TestStatusToString_Helper(CFE_SEVERITY_ERROR);
TestStatusToString_Helper(CFE_STATUS_C(INT32_MAX));
TestStatusToString_Helper(CFE_STATUS_C(INT32_MIN));
}

void ESErrorTestSetup(void)
{
UtTest_Add(TestStatusToString, NULL, NULL, "TestStatusToString");
}
4 changes: 2 additions & 2 deletions modules/core_api/fsw/inc/cfe_endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
#define CFE_MAKE_BIG16(n) (n)
#define CFE_MAKE_BIG32(n) (n)
#else
#define CFE_MAKE_BIG16(n) ((((n) << 8) & 0xFF00) | (((n) >> 8) & 0x00FF))
#define CFE_MAKE_BIG16(n) ((((n)&0x00FF) << 8) | (((n)&0xFF00) >> 8))
#define CFE_MAKE_BIG32(n) \
((((n) << 24) & 0xFF000000) | (((n) << 8) & 0x00FF0000) | (((n) >> 8) & 0x0000FF00) | (((n) >> 24) & 0x000000FF))
((((n)&0x000000FF) << 24) | (((n)&0x0000FF00) << 8) | (((n)&0x00FF0000) >> 8) | (((n)&0xFF000000) >> 24))
#endif

#endif /* CFE_ENDIAN_H */
33 changes: 31 additions & 2 deletions modules/core_api/fsw/inc/cfe_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,40 @@
/* Include Files */
#include "osapi.h"

/*
* Define a type for readability.
/**
* \brief cFE Status type for readability and eventually type safety
*/
typedef int32 CFE_Status_t;

/**
* \brief cFE Status macro for literal
*/
#define CFE_STATUS_C(X) ((CFE_Status_t)(X))

/**
* \brief cFE Status converted to string length limit
*
* Used for sizing CFE_StatusString_t intended for use in printing CFE_Status_t values
* Sized for 0x%08x and NULL
*/
#define CFE_STATUS_STRING_LENGTH 11

/**
* @brief For the @ref CFE_ES_StatusToString() function, to ensure
* everyone is making an array of the same length.
*/
typedef char CFE_StatusString_t[CFE_STATUS_STRING_LENGTH];

/**
* @brief Convert status to a string
*
* @param[in] status Status value to convert
* @param[out] status_string Buffer to store status converted to string
*
* @return Passed in string pointer
*/
char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string);

/*
** Status Codes are 32 bit values formatted as follows:
**
Expand Down
2 changes: 1 addition & 1 deletion modules/core_api/fsw/inc/cfe_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define CFE_VERSION_H

/* Development Build Macro Definitions */
#define CFE_BUILD_NUMBER 136 /**< @brief Development: Number of development git commits since CFE_BUILD_BASELINE */
#define CFE_BUILD_NUMBER 143 /**< @brief Development: Number of development git commits since CFE_BUILD_BASELINE */
#define CFE_BUILD_BASELINE "v7.0.0-rc4" /**< @brief Development: Reference git tag for build number */

/* See \ref cfsversions for definitions */
Expand Down
17 changes: 17 additions & 0 deletions modules/core_api/ut-stubs/src/cfe_es_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,3 +954,20 @@ CFE_Status_t CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...)

return UT_GenStub_GetReturnValue(CFE_ES_WriteToSysLog, CFE_Status_t);
}

/*
* ----------------------------------------------------
* Generated stub function for CFE_ES_StatusToString()
* ----------------------------------------------------
*/
char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string)
{
UT_GenStub_SetupReturnBuffer(CFE_ES_StatusToString, char *);

UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_Status_t, status);
UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_StatusString_t *, status_string);

UT_GenStub_Execute(CFE_ES_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_ES_StatusToString, char *);
}
20 changes: 20 additions & 0 deletions modules/es/fsw/src/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,23 @@ void CFE_ES_ProcessAsyncEvent(void)
/* This just wakes up the background task to log/handle the event. */
CFE_ES_BackgroundWakeup();
}

/*----------------------------------------------------------------
*
* Function: CFE_ES_StatusToString
*
* Implemented per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string)
{
char *string = NULL;

if (status_string != NULL)
{
snprintf(*status_string, sizeof(*status_string), "0x%08x", (unsigned int)status);
string = *status_string;
}
return string;
}
32 changes: 32 additions & 0 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ void UtTest_Setup(void)
UT_ADD_TEST(TestESMempool);
UT_ADD_TEST(TestSysLog);
UT_ADD_TEST(TestBackground);
UT_ADD_TEST(TestStatusToString);
}

/*
Expand Down Expand Up @@ -5631,3 +5632,34 @@ void TestBackground(void)
/* The number of jobs running should be 1 (perf log dump) */
UtAssert_UINT32_EQ(CFE_ES_Global.BackgroundTask.NumJobsRunning, 1);
}

/*--------------------------------------------------------------------------------*
* TestStatusToString test helper function to avoid repeating logic
*--------------------------------------------------------------------------------*/
void TestStatusToString_Helper(CFE_Status_t status)
{
CFE_StatusString_t status_string;
char * rtn_addr;
char expected[CFE_STATUS_STRING_LENGTH + 1];

/* Used oversized string to test for truncation */
snprintf(expected, sizeof(expected), "0x%08x", (unsigned int)status);
rtn_addr = CFE_ES_StatusToString(status, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
}

/*--------------------------------------------------------------------------------*
* Functional CFE_ES_StatusToString test
*--------------------------------------------------------------------------------*/
void TestStatusToString(void)
{
/* NULL test */
UtAssert_ADDRESS_EQ(CFE_ES_StatusToString(CFE_SUCCESS, NULL), NULL);

/* Status value tests */
TestStatusToString_Helper(CFE_SUCCESS);
TestStatusToString_Helper(CFE_SEVERITY_ERROR);
TestStatusToString_Helper(CFE_STATUS_C(INT32_MAX));
TestStatusToString_Helper(CFE_STATUS_C(INT32_MIN));
}
1 change: 1 addition & 0 deletions modules/es/ut-coverage/es_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,6 @@ void TestResourceID(void);
void TestGenericCounterAPI(void);
void TestGenericPool(void);
void TestLibs(void);
void TestStatusToString(void);

#endif /* ES_UT_H */
14 changes: 14 additions & 0 deletions modules/msg/option_inc/default_cfe_msg_hdr_pri.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@
*/
#define CFE_MSG_PTR(shdr) (&((shdr).Msg))

/**
* \brief Macro to initialize a command header, useful in tables that define commands
*/
#define CFE_MSG_CMD_HDR_INIT(mid, size, fc, cksum) \
{ \
.Msg.CCSDS = \
{ \
.Pri = {.StreamId = {((mid) >> 8) & 0xFF, (mid)&0xFF}, \
.Sequence = {0xC0, 0}, \
.Length = {((size)-7) >> 8, ((size)-7) & 0xFF}}, \
}, \
CFE_MSG_CMD_HDR_SEC_INIT(fc, cksum) \
}

/*
* Type Definitions
*/
Expand Down
22 changes: 22 additions & 0 deletions modules/msg/option_inc/default_cfe_msg_hdr_priext.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
*/
#define CFE_MSG_PTR(shdr) (&((shdr).Msg))

/**
* \brief Macro to initialize a command header, useful in tables that define commands
*/
#define CFE_MSG_CMD_HDR_INIT(mid, size, fc, cksum) \
{ \
.Msg.CCSDS = \
{ \
.Pri = \
{ \
.StreamId = {(((mid)&0x80)<<5, (mid)&0x7F}, \
.Sequence = {0xC0, 0}, \
.Length = {((size)-7)>>8, ((size)-7)&0xFF} \
}, \
.Ext = \
{ \
.Subsystem = {0, ((mid)>>8)&0xFF}, \
.SystemId = {0, 0) \
} \
}, \
CFE_MSG_CMD_HDR_SEC_INIT(fc, cksum) \
}

/*
* Type Definitions
*/
Expand Down
5 changes: 5 additions & 0 deletions modules/msg/option_inc/default_cfe_msg_sechdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
* Defines
*/

/**
* \brief Macro to initialize secondary header, used in macro to intialize entire header which is useful in tables
*/
#define CFE_MSG_CMD_HDR_SEC_INIT(fc, cksum) .Sec = {.FunctionCode = (fc), .Checksum = (cksum)}

/*
* Type Definitions
*/
Expand Down

0 comments on commit cacc83a

Please sign in to comment.