diff --git a/docs/src/cfe_api.dox b/docs/src/cfe_api.dox
index 2bfc5dd25..33f4a8c45 100644
--- a/docs/src/cfe_api.dox
+++ b/docs/src/cfe_api.dox
@@ -84,6 +84,7 @@
#CFE_ES_CalculateCRC - \copybrief CFE_ES_CalculateCRC
#CFE_ES_WriteToSysLog - \copybrief CFE_ES_WriteToSysLog
#CFE_ES_ProcessAsyncEvent - \copybrief CFE_ES_ProcessAsyncEvent
+ #CFE_ES_StatusToString - \copybrief CFE_ES_StatusToString
\ref CFEAPIESResourceID
diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c
index 306f035a3..9a655f0ea 100644
--- a/modules/cfe_testcase/src/cfe_test.c
+++ b/modules/cfe_testcase/src/cfe_test.c
@@ -61,6 +61,7 @@ void CFE_TestMain(void)
ESBehaviorestSetup();
ESCDSTestSetup();
ESCounterTestSetup();
+ ESErrorTestSetup();
ESInfoTestSetup();
ESMemPoolTestSetup();
ESMiscTestSetup();
diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h
index 912c3b7dd..afe5325a8 100644
--- a/modules/cfe_testcase/src/cfe_test.h
+++ b/modules/cfe_testcase/src/cfe_test.h
@@ -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);
diff --git a/modules/cfe_testcase/src/es_error_test.c b/modules/cfe_testcase/src/es_error_test.c
new file mode 100644
index 000000000..36d7a087c
--- /dev/null
+++ b/modules/cfe_testcase/src/es_error_test.c
@@ -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;
+ CFE_StatusString_t *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");
+}
diff --git a/modules/core_api/fsw/inc/cfe_error.h b/modules/core_api/fsw/inc/cfe_error.h
index 5815887ca..17edc99a4 100644
--- a/modules/core_api/fsw/inc/cfe_error.h
+++ b/modules/core_api/fsw/inc/cfe_error.h
@@ -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
+ */
+CFE_StatusString_t *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string);
+
/*
** Status Codes are 32 bit values formatted as follows:
**
diff --git a/modules/es/fsw/src/cfe_es_api.c b/modules/es/fsw/src/cfe_es_api.c
index b0b0463e1..399d92f9c 100644
--- a/modules/es/fsw/src/cfe_es_api.c
+++ b/modules/es/fsw/src/cfe_es_api.c
@@ -2299,3 +2299,20 @@ 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
+ *
+ *-----------------------------------------------------------------*/
+CFE_StatusString_t *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string)
+{
+ if (status_string != NULL)
+ {
+ snprintf(*status_string, sizeof(*status_string), "0x%08x", (unsigned int)status);
+ }
+ return status_string;
+}
diff --git a/modules/es/ut-coverage/es_UT.c b/modules/es/ut-coverage/es_UT.c
index 240be009c..2a1a70ad0 100644
--- a/modules/es/ut-coverage/es_UT.c
+++ b/modules/es/ut-coverage/es_UT.c
@@ -635,6 +635,7 @@ void UtTest_Setup(void)
UT_ADD_TEST(TestESMempool);
UT_ADD_TEST(TestSysLog);
UT_ADD_TEST(TestBackground);
+ UT_ADD_TEST(TestStatusToString);
}
/*
@@ -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;
+ CFE_StatusString_t *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));
+}
diff --git a/modules/es/ut-coverage/es_UT.h b/modules/es/ut-coverage/es_UT.h
index 2d669ad10..ea75e41b3 100644
--- a/modules/es/ut-coverage/es_UT.h
+++ b/modules/es/ut-coverage/es_UT.h
@@ -248,5 +248,6 @@ void TestResourceID(void);
void TestGenericCounterAPI(void);
void TestGenericPool(void);
void TestLibs(void);
+void TestStatusToString(void);
#endif /* ES_UT_H */