Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1024, check misc API return codes #1030

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/os/inc/osapi-heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct
* @param[out] heap_prop Storage buffer for heap info
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if the heap_prop argument is NULL
*/
int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop);
Expand Down
1 change: 1 addition & 0 deletions src/os/inc/osapi-network.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int32 OS_NetworkGetID(void);
* @param[in] name_len Maximum length of host name buffer
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERR_INVALID_SIZE if the name_len is zero
* @retval #OS_INVALID_POINTER if the host_name is NULL
*/
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Takes a shell command in and writes the output of that command to the specified file
* The output file must be opened previously with write access (OS_WRITE_ONLY or OS_READ_WRITE).
*
* @param[in] Cmd Command to pass to shell
* @param[in] Cmd Command to pass to shell @nonnull
* @param[in] filedes File to send output to.
*
* @return Execution status, see @ref OSReturnCodes
Expand Down
8 changes: 8 additions & 0 deletions src/unit-tests/inc/ut_os_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ static inline bool UtOsalRetVal(int32 Fn, int32 Exp, bool NotImplAllowed, UtAsse
return UtAssertEx(Fn == Exp, casetype, File, Line, "%s (%d) == %s (%d)", FnTxt, (int)Fn, ExpTxt, (int)Exp);
}

static inline bool UtOsalNotSuccess(int32 Fn, UtAssert_CaseType_t casetype, const char *File, uint32 Line,
const char *FnTxt)
{
/* Check result is negative to support APIs that return nonzero on success (e.g. read/write) */
return UtAssertEx(Fn < 0, casetype, File, Line, "%s (%d) not successful", FnTxt, (int)Fn);
}

static inline bool UtManualInspectionWithStatus(int32 Fn, const char *File, uint32 Line, const char *FnTxt)
{
UtAssertEx(false, UTASSERT_CASETYPE_MIR, File, Line, "%s value=%d", FnTxt, (int)Fn);
Expand Down Expand Up @@ -107,6 +114,7 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line)
UtOsalRetVal(Fn, OS_SUCCESS, false, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, "OS_SUCCESS")
#define UT_NOMINAL_OR_NOTIMPL(Fn) \
UtOsalRetVal(Fn, OS_SUCCESS, true, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn, "OS_SUCCESS")
#define UT_NOT_SUCCESS(Fn) UtOsalNotSuccess(Fn, UTASSERT_CASETYPE_FAILURE, __FILE__, __LINE__, #Fn)

#define UT_MIR_STATUS(Fn) UtManualInspectionWithStatus(Fn, __FILE__, __LINE__, #Fn)
#define UT_MIR_VOID(Fn) Fn, UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", #Fn)
Expand Down
27 changes: 13 additions & 14 deletions src/unit-tests/oscore-test/ut_oscore_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ void UT_os_apiinit_test()
/*-----------------------------------------------------*/
/* #1 Init-not-call-first */

UT_RETVAL(OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags), OS_ERROR);
UT_RETVAL(OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions), OS_ERROR);
UT_RETVAL(OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions), OS_ERROR);
UT_RETVAL(OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions), OS_ERROR);
/*
* Note that OS_API_Init() is supposed to be the first function invoked,
* calling any other OSAL API before this is technically undefined behavior.
* There is code to check for errors in this regard so this just tests that
* the result is _not_ success. The specific status code if called before
* OS_API_Init is not documented.
*/
UT_NOT_SUCCESS(OS_QueueCreate(&qId, "Queue A", qDepth, qSize, qFlags));
UT_NOT_SUCCESS(OS_BinSemCreate(&semIds[0], "BinSem 1", semInitValue, semOptions));
UT_NOT_SUCCESS(OS_CountSemCreate(&semIds[1], "CountSem 1", semInitValue, semOptions));
UT_NOT_SUCCESS(OS_MutSemCreate(&semIds[2], "MutexSem 1", semOptions));

/*-----------------------------------------------------*/
/* #2 Nominal */
Expand Down Expand Up @@ -418,23 +425,15 @@ void UT_os_heapgetinfo_test(void)
{
OS_heap_prop_t heapProp;

/*-----------------------------------------------------*/
/* API not implemented */

if (!UT_IMPL(OS_HeapGetInfo(&heapProp)))
{
return;
}

/*-----------------------------------------------------*/
/* #1 Null-pointer-arg */

UT_RETVAL(OS_HeapGetInfo(NULL), OS_INVALID_POINTER);

/*-----------------------------------------------------*/
/* #3 Nominal */
/* #3 Nominal (allows for not implemented) */

UT_NOMINAL(OS_HeapGetInfo(&heapProp));
UT_NOMINAL_OR_NOTIMPL(OS_HeapGetInfo(&heapProp));
}

/*================================================================================*
Expand Down
19 changes: 13 additions & 6 deletions src/unit-tests/osfile-test/ut_osfile_fileio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,11 +1394,6 @@ void UT_os_movefile_test()
**--------------------------------------------------------------------------------*/
void UT_os_outputtofile_test()
{
/*-----------------------------------------------------*/
/* #1 Null-pointer-arg */

UT_RETVAL(OS_ShellOutputToFile(NULL, OS_OBJECT_ID_UNDEFINED), OS_INVALID_POINTER);

/*-----------------------------------------------------*/
/* #2 Invalid-file-desc-arg */

Expand All @@ -1411,7 +1406,12 @@ void UT_os_outputtofile_test()
UT_os_sprintf(g_fNames[0], "%s/Output_Nominal.txt", g_mntName);
if (UT_SETUP(OS_OpenCreate(&g_fDescs[0], g_fNames[0], OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE)))
{
/* #4 Nominal - File-create failed */
/*-----------------------------------------------------*/
/* Null-pointer-arg */

UT_RETVAL(OS_ShellOutputToFile(NULL, g_fDescs[0]), OS_INVALID_POINTER);

/* Nominal */
if (UT_NOMINAL_OR_NOTIMPL(OS_ShellOutputToFile("echo \"UT_os_outputtofile_test\"", g_fDescs[0])))
{
UT_RETVAL(OS_lseek(g_fDescs[0], 0, OS_SEEK_SET), 0);
Expand All @@ -1421,6 +1421,13 @@ void UT_os_outputtofile_test()
UtAssert_True(strstr(g_readBuff, "UT_os_outputtofile_test") != NULL,
"Output file contains UT_os_outputtofile_test");
}

/*
* Executing a command name "false" should fail, either because it is not a known
* command, or if it is valid (e.g. a UNIX-like environment has /bin/false) the
* command always fails.
*/
UT_RETVAL(OS_ShellOutputToFile("false", g_fDescs[0]), OS_ERROR);
}

/* Reset test environment */
Expand Down