Skip to content

Commit

Permalink
Merge pull request #915 from jphickey/fix-888-symEach-errs
Browse files Browse the repository at this point in the history
Fix #888, better return codes from OS_SymbolTableDump_Impl
  • Loading branch information
astrogeco authored Mar 29, 2021
2 parents 073019a + c9327ee commit 318afe6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/os/inc/osapi-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef char os_err_name_t[OS_ERROR_NAME_LENGTH];
#define OS_ERR_STREAM_DISCONNECTED (-37) /**< @brief Stream disconnected */
#define OS_ERR_OPERATION_NOT_SUPPORTED (-38) /**< @brief Requested operation not support on supplied object(s) */
#define OS_ERR_INVALID_SIZE (-40) /**< @brief Invalid Size */
#define OS_ERR_OUTPUT_TOO_LARGE (-41) /**< @brief Size of output exceeds limit */

/*
** Defines for File System Calls
Expand Down
13 changes: 12 additions & 1 deletion src/os/vxworks/src/os-impl-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_
if (memchr(name, 0, OS_MAX_SYM_LEN) == NULL)
{
OS_DEBUG("%s(): symbol name too long\n", __func__);
state->StatusCode = OS_ERROR;
state->StatusCode = OS_ERR_NAME_TOO_LONG;
return (false);
}

Expand All @@ -190,6 +190,7 @@ BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_
** However this is not considered an error, just a stop condition.
*/
OS_DEBUG("%s(): symbol table size exceeded\n", __func__);
state->StatusCode = OS_ERR_OUTPUT_TOO_LARGE;
return (false);
}

Expand Down Expand Up @@ -264,6 +265,16 @@ int32 OS_SymbolTableDump_Impl(const char *filename, size_t size_limit)
close(state->fd);
}

/*
* If output size was zero this means a failure of the symEach call,
* in that it didn't iterate over anything at all.
*/
if (state->StatusCode == OS_SUCCESS && state->CurrSize == 0)
{
OS_DEBUG("%s(): No symbols found!\n", __func__);
state->StatusCode = OS_ERROR;
}

return (state->StatusCode);

} /* end OS_SymbolTableDump_Impl */
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
#include "common_types.h"

int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, size_t TestSize, size_t SizeLimit);
int32 UT_SymTabTest_GetIteratorStatus(void);

#endif /* UT_ADAPTOR_SYMTAB_H */
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ int32 UT_SymTabTest_CallIteratorFunc(const char *name, void *val, size_t TestSiz
*/
return OS_SymTableIterator_Impl((char *)name, (OCS_SYM_VALUE)val, 0, 0, 0);
}

/*
* Gets the current status of the iterator function
*/
int32 UT_SymTabTest_GetIteratorStatus(void)
{
return OS_VxWorks_SymbolDumpState.StatusCode;
}
28 changes: 27 additions & 1 deletion src/unit-test-coverage/vxworks/src/coveragetest-symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,51 @@ void Test_OS_SymTableIterator_Impl(void)
*/
uint32 Data = 0;

/* nominal case - nothing goes wrong */
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), true);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_GetIteratorStatus(), OS_SUCCESS);

/* Check case where next entry will exceed size limit */
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 101), false);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_GetIteratorStatus(), OS_ERR_OUTPUT_TOO_LARGE);

/* Check case where entry has a name that is too long */
UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_GetIteratorStatus(), OS_ERR_NAME_TOO_LONG);
UT_ClearDefaultReturnValue(UT_KEY(OCS_memchr));

/* Check case where writing to file fails */
UT_SetDefaultReturnValue(UT_KEY(OCS_write), -1);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000), false);
OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_GetIteratorStatus(), OS_ERROR);
UT_ClearDefaultReturnValue(UT_KEY(OCS_write));
}

static int32 UT_symEachHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
{
uint32 Data = 0;
UT_SymTabTest_CallIteratorFunc("ut", &Data, 100, 1000);
return StubRetcode;
}

void Test_OS_SymbolTableDump_Impl(void)
{
/* Test Case For:
* int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit )
*/
OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_SUCCESS);

/* With no action in symEach(), this will yield an empty file, which is an error */
OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_ERROR);

/* Check failure in open() */
UT_SetDefaultReturnValue(UT_KEY(OCS_open), -1);
OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_ERROR);
UT_ClearDefaultReturnValue(UT_KEY(OCS_open));

/* Set up a hook function for symEach() to provide at least one entry */
UT_SetHookFunction(UT_KEY(OCS_symEach), UT_symEachHook, NULL);
OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file", 10000), OS_SUCCESS);
}

/* ------------------- End of test cases --------------------------------------*/
Expand Down

0 comments on commit 318afe6

Please sign in to comment.