Skip to content

Commit 419c673

Browse files
committed
Merge IC:Caelum-rc4+dev11, osal v6.0.0-rc4+dev87
- Add OS_StatusToString API - See <nasa/cFS#505>
2 parents 2864b25 + 223a618 commit 419c673

File tree

9 files changed

+134
-2
lines changed

9 files changed

+134
-2
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ This is a collection of abstraction APIs and associated framework to be located
99

1010
The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cFS/blob/gh-pages/OSAL_Users_Guide.pdf>.
1111

12-
## Version History
12+
## Changelog
13+
14+
### Development Build: v6.0.0-rc4+dev87
15+
16+
- Add OS_StatusToString API
17+
- See <https://github.com/nasa/cFS/pull/505>
1318

1419
### Development Build: v6.0.0-rc4+dev83
1520

src/os/inc/osapi-error.h

+25
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@
4646
*/
4747
typedef char os_err_name_t[OS_ERROR_NAME_LENGTH];
4848

49+
/**
50+
* @brief Status converted to string length limit
51+
*
52+
* Used for sizing os_status_string_t intended for use in printing osal_status_t values
53+
* Sized to fit LONG_MIN including NULL termination
54+
*/
55+
#define OS_STATUS_STRING_LENGTH 12
56+
57+
/**
58+
* @brief For the @ref OS_StatusToString() function, to ensure
59+
* everyone is making an array of the same length.
60+
*/
61+
typedef char os_status_string_t[OS_STATUS_STRING_LENGTH];
62+
4963
/** @defgroup OSReturnCodes OSAL Return Code Defines
5064
*
5165
* The specific status/return code definitions listed in this section may be extended or refined
@@ -165,6 +179,17 @@ static inline long OS_StatusToInteger(osal_status_t Status)
165179
* @retval #OS_ERROR if error could not be converted
166180
*/
167181
int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name);
182+
183+
/*-------------------------------------------------------------------------------------*/
184+
/**
185+
* @brief Convert status to a string
186+
*
187+
* @param[in] status Status value to convert
188+
* @param[out] status_string Buffer to store status converted to string
189+
*
190+
* @return Passed in string pointer
191+
*/
192+
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string);
168193
/**@}*/
169194

170195
#endif /* OSAPI_ERROR_H */

src/os/inc/osapi-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/*
3535
* Development Build Macro Definitions
3636
*/
37-
#define OS_BUILD_NUMBER 83
37+
#define OS_BUILD_NUMBER 87
3838
#define OS_BUILD_BASELINE "v6.0.0-rc4"
3939

4040
/*

src/os/shared/src/osapi-errors.c

+20
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ static const OS_ErrorTable_Entry_t OS_GLOBAL_ERROR_NAME_TABLE[] = {
9898
*********************************************************************************
9999
*/
100100

101+
/*----------------------------------------------------------------
102+
*
103+
* Function: OS_StatusToString
104+
*
105+
* Purpose: Implemented per public OSAL API
106+
* See description in API and header file for detail
107+
*
108+
*-----------------------------------------------------------------*/
109+
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
110+
{
111+
char *string = NULL;
112+
113+
if (status_string != NULL)
114+
{
115+
snprintf(*status_string, sizeof(*status_string), "%ld", OS_StatusToInteger(status));
116+
string = *status_string;
117+
}
118+
return string;
119+
}
120+
101121
/*----------------------------------------------------------------
102122
*
103123
* Function: OS_GetErrorName

src/unit-test-coverage/shared/src/coveragetest-errors.c

+32
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@ void Test_OS_GetErrorName(void)
4747
OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(-555555, NULL), OS_INVALID_POINTER);
4848
}
4949

50+
/*--------------------------------------------------------------------------------*
51+
** OS_StatusToString test helper function to avoid repeating logic
52+
**--------------------------------------------------------------------------------*/
53+
void Test_OS_StatusToString_Helper(osal_status_t status)
54+
{
55+
os_status_string_t status_string;
56+
char * rtn_addr;
57+
char expected[OS_STATUS_STRING_LENGTH + 1];
58+
59+
/* Used oversized string to test for truncation */
60+
snprintf(expected, sizeof(expected), "%ld", OS_StatusToInteger(status));
61+
rtn_addr = OS_StatusToString(status, &status_string);
62+
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
63+
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
64+
}
65+
66+
/*--------------------------------------------------------------------------------*
67+
** Functional OS_StatusToString test
68+
**--------------------------------------------------------------------------------*/
69+
void Test_OS_StatusToString(void)
70+
{
71+
/* NULL test */
72+
UtAssert_ADDRESS_EQ(OS_StatusToString(OS_SUCCESS, NULL), NULL);
73+
74+
/* Status value tests */
75+
Test_OS_StatusToString_Helper(OS_SUCCESS);
76+
Test_OS_StatusToString_Helper(OS_ERROR);
77+
Test_OS_StatusToString_Helper(OSAL_STATUS_C(INT32_MAX));
78+
Test_OS_StatusToString_Helper(OSAL_STATUS_C(INT32_MIN));
79+
}
80+
5081
/* Osapi_Test_Setup
5182
*
5283
* Purpose:
@@ -71,4 +102,5 @@ void Osapi_Test_Teardown(void) {}
71102
void UtTest_Setup(void)
72103
{
73104
ADD_TEST(OS_GetErrorName);
105+
ADD_TEST(OS_StatusToString);
74106
}

src/unit-tests/oscore-test/ut_oscore_misc_test.c

+31
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,37 @@ void UT_os_geterrorname_test(void)
416416
UtAssert_StrCmp(errNames[2], "OS_ERR_NO_FREE_IDS", "%s == %s", errNames[2], "OS_ERR_NO_FREE_IDS");
417417
}
418418

419+
/*--------------------------------------------------------------------------------*
420+
** OS_StatusToString test helper function to avoid repeating logic
421+
**--------------------------------------------------------------------------------*/
422+
void UT_os_statustostring_test_helper(osal_status_t status)
423+
{
424+
os_status_string_t status_string;
425+
char * rtn_addr;
426+
char expected[OS_STATUS_STRING_LENGTH + 1];
427+
428+
/* Used oversized string to test for truncation */
429+
snprintf(expected, sizeof(expected) - 1, "%ld", OS_StatusToInteger(status));
430+
rtn_addr = OS_StatusToString(status, &status_string);
431+
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
432+
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
433+
}
434+
435+
/*--------------------------------------------------------------------------------*
436+
** Functional OS_StatusToString test
437+
**--------------------------------------------------------------------------------*/
438+
void UT_os_statustostring_test(void)
439+
{
440+
/* NULL test */
441+
UtAssert_ADDRESS_EQ(OS_StatusToString(OS_SUCCESS, NULL), NULL);
442+
443+
/* Status value tests */
444+
UT_os_statustostring_test_helper(OS_SUCCESS);
445+
UT_os_statustostring_test_helper(OS_ERROR);
446+
UT_os_statustostring_test_helper(OSAL_STATUS_C(INT32_MAX));
447+
UT_os_statustostring_test_helper(OSAL_STATUS_C(INT32_MIN));
448+
}
449+
419450
/*--------------------------------------------------------------------------------*
420451
** Syntax: int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop)
421452
** Purpose: Returns current info on the heap

src/unit-tests/oscore-test/ut_oscore_misc_test.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void UT_os_getlocaltime_test(void);
6363
void UT_os_setlocaltime_test(void);
6464

6565
void UT_os_geterrorname_test(void);
66+
void UT_os_statustostring_test(void);
6667

6768
void UT_os_heapgetinfo_test(void);
6869

src/unit-tests/oscore-test/ut_oscore_test.c

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void UtTest_Setup(void)
245245
UtTest_Add(UT_os_task_getid_by_sysdata_test, UT_os_task_getid_by_sysdata_test, NULL, "OS_TaskFindIdBySystemData");
246246

247247
UtTest_Add(UT_os_geterrorname_test, NULL, NULL, "OS_GetErrorName");
248+
UtTest_Add(UT_os_statustostring_test, NULL, NULL, "OS_StatusToString");
248249

249250
UtTest_Add(UT_os_getlocaltime_test, NULL, NULL, "OS_GetLocalTime");
250251
UtTest_Add(UT_os_setlocaltime_test, NULL, NULL, "OS_SetLocalTime");

src/ut-stubs/osapi-error-stubs.c

+17
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name)
4343

4444
return UT_GenStub_GetReturnValue(OS_GetErrorName, int32);
4545
}
46+
47+
/*
48+
* ----------------------------------------------------
49+
* Generated stub function for OS_StatusToString()
50+
* ----------------------------------------------------
51+
*/
52+
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
53+
{
54+
UT_GenStub_SetupReturnBuffer(OS_StatusToString, char *);
55+
56+
UT_GenStub_AddParam(OS_StatusToString, osal_status_t, status);
57+
UT_GenStub_AddParam(OS_StatusToString, os_status_string_t *, status_string);
58+
59+
UT_GenStub_Execute(OS_StatusToString, Basic, NULL);
60+
61+
return UT_GenStub_GetReturnValue(OS_StatusToString, char *);
62+
}

0 commit comments

Comments
 (0)