diff --git a/README.md b/README.md index 121dd6ad0..705bb03a0 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,17 @@ The autogenerated OSAL user's guide can be viewed at for more details. +- Applies minor code and documentation cleanup: white space, typos, etc. +- Adds test to get full coverage of vxworks in `os-impl-bsd-socket.c` resulting in full line coverage for OSAL +- Adds more descriptive return codes if `OS_SymbolTableDump_Impl` does not do what is expected. Adds a new error `OS_ERR_OUTPUT_TOO_LARGE` if the size limit was insufficient. Return `OS_ERROR` if an empty file was written - this likely indicates some fundamental issue with the VxWorks symbol table. Returns `OS_ERR_NAME_TOO_LONG` if one of the symbol names was too long. Improves unit test to check for/verify these responses. +- Removes the unneeded `OS_TaskRegister()` and all references to it in code, tests, and documentation. No impact to behavior, but does affect API and has depenedencies +- Removes unused `-SCRIPT_MODE` flag in cmake +- Remove comparison between `osal_id_t` and `integers` to use the provided comparison function, `OS_ObjectIdDefined()`. System builds and runs again when using a type-safe/non-integer osal_id_t type. +- See + ### Development Build: v5.1.0-rc1+dev350 - Moves copyblock size to a macro and add comments. Defines `OS_CP_BLOCK_SIZE` and adds clear documentation that it could be adjusted for page size, performance, etc. diff --git a/src/examples/tasking-example/tasking-example.c b/src/examples/tasking-example/tasking-example.c index 68431b2ea..ab0379168 100644 --- a/src/examples/tasking-example/tasking-example.c +++ b/src/examples/tasking-example/tasking-example.c @@ -127,8 +127,6 @@ void task_1(void) OS_printf("Starting task 1\n"); - OS_TaskRegister(); - while (1) { status = OS_MutSemTake(mutex_id); @@ -171,8 +169,6 @@ void task_2(void) OS_printf("Starting task 2\n"); - OS_TaskRegister(); - while (1) { status = OS_MutSemTake(mutex_id); @@ -220,8 +216,6 @@ void task_3(void) OS_printf("Starting task 3\n"); - OS_TaskRegister(); - while (1) { status = OS_QueueGet(msgq_id, (void *)&data_received, MSGQ_SIZE, &data_size, OS_PEND); diff --git a/src/os/inc/common_types.h b/src/os/inc/common_types.h index ff5ed718c..108f1004b 100644 --- a/src/os/inc/common_types.h +++ b/src/os/inc/common_types.h @@ -138,34 +138,6 @@ extern "C" CompileTimeAssert(sizeof(int64) == 8, Typeint64WrongSize); CompileTimeAssert(sizeof(cpuaddr) >= sizeof(void *), TypePtrWrongSize); -/* - * TEMPORARY COMPATIBILITY MACRO - * - * Any code that depends on this macro should be fixed so as to not need it. - * The value for this had been set by the BSP makefiles but this is not reliable, - * especially on processors that support both big- and little- endian modes e.g. - * ARM and MIPS. - * - * This is deprecated and only here to bridge the gap until code that depends - * on this can be fixed. Do not write any new code that uses this macro. - * - * If using an older makefile that defines one of the BIT_ORDER macros already, - * then this entire section is skipped and the macro is used as-is. - */ -#if !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER) - -#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || \ - defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) -/* It is a big-endian target architecture */ -#define SOFTWARE_BIG_BIT_ORDER -#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || \ - defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) -/* It is a little-endian target architecture */ -#define SOFTWARE_LITTLE_BIT_ORDER -#endif - -#endif /* !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER) */ - #ifdef __cplusplus } #endif diff --git a/src/os/inc/osapi-dir.h b/src/os/inc/osapi-dir.h index a9c594dcc..d29a1f196 100644 --- a/src/os/inc/osapi-dir.h +++ b/src/os/inc/osapi-dir.h @@ -121,7 +121,7 @@ int32 OS_mkdir(const char *path, uint32 access); /** * @brief Removes a directory from the file system. * - * Removes a directory from the structure. + * Removes a directory from the structure. * The directory must be empty prior to this operation. * * @param[in] path The directory to remove diff --git a/src/os/inc/osapi-error.h b/src/os/inc/osapi-error.h index c0af8e57e..b623292ca 100644 --- a/src/os/inc/osapi-error.h +++ b/src/os/inc/osapi-error.h @@ -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 diff --git a/src/os/inc/osapi-select.h b/src/os/inc/osapi-select.h index fefc18cd0..0d4ced4b3 100644 --- a/src/os/inc/osapi-select.h +++ b/src/os/inc/osapi-select.h @@ -34,6 +34,10 @@ * This is part of the select API and is manipulated using the * related API calls. It should not be modified directly by applications. * + * Note: Math is to determine uint8 array size needed to represent + * single bit OS_MAX_NUM_OPEN_FILES objects, + 7 rounds up + * and 8 is the size of uint8. + * * @sa OS_SelectFdZero(), OS_SelectFdAdd(), OS_SelectFdClear(), OS_SelectFdIsSet() */ typedef struct diff --git a/src/os/inc/osapi-task.h b/src/os/inc/osapi-task.h index acc7e1304..97b29b7cf 100644 --- a/src/os/inc/osapi-task.h +++ b/src/os/inc/osapi-task.h @@ -144,6 +144,7 @@ int32 OS_TaskInstallDeleteHandler(osal_task_entry function_pointer); * @brief Delay a task for specified amount of milliseconds * * Causes the current thread to be suspended from execution for the period of millisecond. + * This is a scheduled wait (clock_nanosleep/rtems_task_wake_after/taskDelay), not a "busy" wait. * * @param[in] millisecond Amount of time to delay * @@ -169,18 +170,6 @@ int32 OS_TaskDelay(uint32 millisecond); */ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority); -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obsolete - * @deprecated Explicit registration call no longer needed - * - * Obsolete function retained for compatibility purposes. - * Does Nothing in the current implementation. - * - * @return #OS_SUCCESS (always), see @ref OSReturnCodes - */ -int32 OS_TaskRegister(void); - /*-------------------------------------------------------------------------------------*/ /** * @brief Obtain the task id of the calling task diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 89b2df060..e7182a964 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -32,7 +32,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 350 +#define OS_BUILD_NUMBER 367 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index 70575e6c9..b41832f24 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -117,18 +117,19 @@ static int32 OS_FdSet_ConvertIn_Impl(int *os_maxfd, fd_set *os_set, const OS_FdS return status; } /* end OS_FdSet_ConvertIn_Impl */ -/*---------------------------------------------------------------- - * Function: OS_FdSet_ConvertOut_Impl +/*----------------------------------------------------------------*/ +/** + * \brief Convert a POSIX fd_set structure into an OSAL OS_FdSet + * which can then be returned back to the application. * - * Purpose: Local helper routine, not part of OSAL API. + * Local helper routine, not part of OSAL API. * - * Convert a POSIX fd_set structure into an OSAL OS_FdSet - * which can then be returned back to the application. + * This un-sets bits in OSAL_set that are set in the OS_set * - * This actually un-sets any bits in the "Input" parameter - * which are also set in the "output" parameter. + * \param[in] OS_set The fd_set from select + * \param[in, out] OSAL_set The OS_FdSet updated by this helper *-----------------------------------------------------------------*/ -static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) +static void OS_FdSet_ConvertOut_Impl(fd_set *OS_set, OS_FdSet *OSAL_set) { size_t offset; size_t bit; @@ -136,9 +137,9 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) uint8 objids; int osfd; - for (offset = 0; offset < sizeof(Input->object_ids); ++offset) + for (offset = 0; offset < sizeof(OSAL_set->object_ids); ++offset) { - objids = Input->object_ids[offset]; + objids = OSAL_set->object_ids[offset]; bit = 0; while (objids != 0) { @@ -146,9 +147,9 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES) { osfd = OS_impl_filehandle_table[id].fd; - if (osfd < 0 || !FD_ISSET(osfd, output)) + if (osfd < 0 || !FD_ISSET(osfd, OS_set)) { - Input->object_ids[offset] &= ~(1 << bit); + OSAL_set->object_ids[offset] &= ~(1 << bit); } } ++bit; @@ -187,7 +188,7 @@ static int32 OS_DoSelect(int maxfd, fd_set *rd_set, fd_set *wr_set, int32 msecs) } else { - /* eliminates a false warning about possibly uninitialized use */ + /* Zero for consistency and to avoid possible confusion if not cleared */ memset(&ts_end, 0, sizeof(ts_end)); } diff --git a/src/os/portable/os-impl-posix-dirs.c b/src/os/portable/os-impl-posix-dirs.c index 05b246f6d..87467960d 100644 --- a/src/os/portable/os-impl-posix-dirs.c +++ b/src/os/portable/os-impl-posix-dirs.c @@ -82,7 +82,7 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access) if (errno == EEXIST) { - /* it exists, but not necessarily a directory */ + /* Success if already exists and is a directory */ if (stat(local_path, &st) == 0 && S_ISDIR(st.st_mode)) { return_code = OS_SUCCESS; diff --git a/src/os/shared/inc/os-shared-task.h b/src/os/shared/inc/os-shared-task.h index 280ebbc71..9ec7d350e 100644 --- a/src/os/shared/inc/os-shared-task.h +++ b/src/os/shared/inc/os-shared-task.h @@ -166,7 +166,7 @@ int32 OS_TaskGetInfo_Impl(const OS_object_token_t *token, OS_task_prop_t *task_p Purpose: Perform registration actions after new task creation NOTE: This is invoked via the OS_TaskEntryPoint() immediately - after new task creation, not through OS_TaskRegister() API + after new task creation Returns: OS_SUCCESS on success, or relevant error code ------------------------------------------------------------------*/ diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index cf6bad493..2543d9887 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -255,21 +255,11 @@ void OS_ApplicationExit(int32 Status) } } /* end OS_ApplicationExit */ -/*--------------------------------------------------------------------------------------- - Name: OS_CleanUpObject - - Purpose: Implements a single API call that can delete ANY object - Will dispatch to the correct delete implementation for that object type - - Returns: None - ----------------------------------------------------------------------------------------*/ - /*---------------------------------------------------------------- * * Function: OS_CleanUpObject * - * Purpose: Local helper routine, not part of OSAL API. + * Purpose: Local helper routine that can delete ANY object, not part of OSAL API. * *-----------------------------------------------------------------*/ void OS_CleanUpObject(osal_id_t object_id, void *arg) diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index f902a9fb7..758f74307 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -971,7 +971,7 @@ int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, osal_objtype_t idtype, OS /* * The "ConvertToken" routine will return with the global lock * in a state appropriate for returning to the caller, as indicated - * by the "check_mode" parameter. + * by the "lock_mode" parameter. */ return_code = OS_ObjectIdConvertToken(token); } diff --git a/src/os/shared/src/osapi-printf.c b/src/os/shared/src/osapi-printf.c index f3bcac68c..a21f55b36 100644 --- a/src/os/shared/src/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -281,10 +281,7 @@ void OS_printf(const char *String, ...) } else if (OS_SharedGlobalVars.PrintfEnabled) { - /* - * Call vsnprintf() to determine the actual size of the - * string we are going to write to the buffer after formatting. - */ + /* Format and determine the size of string to write */ va_start(va, String); actualsz = vsnprintf(msg_buffer, sizeof(msg_buffer), String, va); va_end(va); diff --git a/src/os/shared/src/osapi-queue.c b/src/os/shared/src/osapi-queue.c index f50278f8e..e8f8c4f46 100644 --- a/src/os/shared/src/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -87,7 +87,7 @@ int32 OS_QueueAPI_Init(void) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size, +int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t max_size, uint32 flags) { int32 return_code; @@ -97,7 +97,7 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun /* validate inputs */ OS_CHECK_POINTER(queue_id); OS_CHECK_APINAME(queue_name); - OS_CHECK_SIZE(data_size); + OS_CHECK_SIZE(max_size); ARGCHECK(queue_depth <= OS_QUEUE_MAX_DEPTH, OS_QUEUE_INVALID_SIZE); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ @@ -110,7 +110,7 @@ int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcoun OS_OBJECT_INIT(token, queue, queue_name, queue_name); queue->max_depth = queue_depth; - queue->max_size = data_size; + queue->max_size = max_size; /* Now call the OS-specific implementation. This reads info from the queue table. */ return_code = OS_QueueCreate_Impl(&token, flags); diff --git a/src/os/shared/src/osapi-select.c b/src/os/shared/src/osapi-select.c index f74453366..5d346eb66 100644 --- a/src/os/shared/src/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -141,6 +141,11 @@ int32 OS_SelectFdAdd(OS_FdSet *Set, osal_id_t objid) return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) { + /* + * Sets the bit in the uint8 object_ids array that corresponds + * to the local_id where local_id >> 3 determines the array element, + * and the mask/shift sets the bit within that element. + */ Set->object_ids[local_id >> 3] |= 1 << (local_id & 0x7); } @@ -166,6 +171,11 @@ int32 OS_SelectFdClear(OS_FdSet *Set, osal_id_t objid) return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) { + /* + * Clears the bit in the uint8 object_ids array that corresponds + * to the local_id where local_id >> 3 determines the array element, + * and the mask/shift clears the bit within that element. + */ Set->object_ids[local_id >> 3] &= ~(1 << (local_id & 0x7)); } @@ -194,5 +204,10 @@ bool OS_SelectFdIsSet(OS_FdSet *Set, osal_id_t objid) return false; } + /* + * Returns boolean for if the bit in the uint8 object_ids array that corresponds + * to the local_id is set where local_id >> 3 determines the array element, + * and the mask/shift checks the bit within that element. + */ return ((Set->object_ids[local_id >> 3] >> (local_id & 0x7)) & 0x1); } /* end OS_SelectFdIsSet */ diff --git a/src/os/shared/src/osapi-task.c b/src/os/shared/src/osapi-task.c index 29c60dd4f..bbf817aae 100644 --- a/src/os/shared/src/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -329,25 +329,6 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) return return_code; } /* end OS_TaskSetPriority */ -/*---------------------------------------------------------------- - * - * Function: OS_TaskRegister - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskRegister(void) -{ - OS_object_token_t token; - - /* - * Just to retain compatibility (really, only the unit test cares) - * this will return NON success when called from a non-task context - */ - return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &token); -} /* end OS_TaskRegister */ - /*---------------------------------------------------------------- * * Function: OS_TaskGetId diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c index f5d44dc69..9fc250814 100644 --- a/src/os/vxworks/src/os-impl-console.c +++ b/src/os/vxworks/src/os-impl-console.c @@ -119,6 +119,7 @@ int OS_VxWorks_ConsoleTask_Entry(int arg) OS_ObjectIdRelease(&token); } + /* Return OK since called from taskSpawn, error is reported in debug message */ return OK; } /* end OS_ConsoleTask_Entry */ diff --git a/src/os/vxworks/src/os-impl-symtab.c b/src/os/vxworks/src/os-impl-symtab.c index ed4244761..3956f0541 100644 --- a/src/os/vxworks/src/os-impl-symtab.c +++ b/src/os/vxworks/src/os-impl-symtab.c @@ -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); } @@ -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); } @@ -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 */ diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c index 2f6ebfed4..e05524f33 100644 --- a/src/os/vxworks/src/os-impl-tasks.c +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -166,7 +166,7 @@ int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) * NOTE: Allocation of the stack requires a malloc() of some form. * This is what taskSpawn() effectively does internally to create * stack. If the system malloc() is unacceptable here then this - * could be replaced with a statically-allocated OSAL stack buffer. + * could be replaced with a locally scoped statically allocated buffer. * * ALSO NOTE: The stack-rounding macros are normally supplied from * vxWorks.h on relevant platforms. If not provided then it is diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 58e3d303d..f5175e0a3 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -319,8 +319,8 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) /* * Finally compute the Microseconds per tick - * This must further round again to the nearest microsecond, so it is undesirable to use - * this for time computations if the result is not exact. + * This must further round again to the nearest microsecond (using the + 500 / 1000), + * so it is undesirable to use this for time computations if the result is not exact. */ OS_SharedGlobalVars.MicroSecPerTick = (OS_ClockAccuracyNsec + 500) / 1000; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index af5435f28..9e08b109a 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -8,10 +8,6 @@ enable_testing() # Each test module is stored within its own subdir file(GLOB OSAL_TESTS *-test) -# The original OSAL tests ran forever until CTRL+C, this does not work for scripted testing -# This SCRIPT_MODE define plus some hooks in the code allow for limited runs -add_definitions(-DSCRIPT_MODE) - foreach(OSTEST ${OSAL_TESTS}) get_filename_component(TESTNAME ${OSTEST} NAME) set(TESTFILES) diff --git a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c index 67bf0a553..33297a34c 100644 --- a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c +++ b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c @@ -62,7 +62,6 @@ void task_1(void) int counter = 0; OS_printf("Starting task 1\n"); - OS_TaskRegister(); OS_printf("TASK 1: Waiting on the semaphore\n"); status = OS_BinSemTake(bin_sem_id); @@ -101,7 +100,6 @@ void task_2(void) task_2_failures = 0; OS_printf("Starting task 2\n"); - OS_TaskRegister(); OS_printf("TASK 2: Waiting on the semaphore\n"); status = OS_BinSemTake(bin_sem_id); @@ -139,7 +137,6 @@ void task_3(void) int counter = 0; OS_printf("Starting task 3\n"); - OS_TaskRegister(); OS_printf("TASK 3: Waiting on the semaphore\n"); status = OS_BinSemTake(bin_sem_id); diff --git a/src/tests/bin-sem-test/bin-sem-test.c b/src/tests/bin-sem-test/bin-sem-test.c index 584cea5c5..36fa6cc4f 100644 --- a/src/tests/bin-sem-test/bin-sem-test.c +++ b/src/tests/bin-sem-test/bin-sem-test.c @@ -106,8 +106,6 @@ void task_1(void) OS_printf("Starting task 1\n"); - OS_TaskRegister(); - OS_printf("Delay for 1 second before starting\n"); OS_TaskDelay(1000); diff --git a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c index 0339f8054..78c72022e 100644 --- a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c +++ b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c @@ -101,8 +101,6 @@ void task_1(void) OS_printf("Starting task 1\n"); - OS_TaskRegister(); - OS_printf("Delay for 1 second before starting\n"); OS_TaskDelay(1000); diff --git a/src/tests/count-sem-test/count-sem-test.c b/src/tests/count-sem-test/count-sem-test.c index 61239a590..48efe2c8b 100644 --- a/src/tests/count-sem-test/count-sem-test.c +++ b/src/tests/count-sem-test/count-sem-test.c @@ -59,7 +59,6 @@ void task_1(void) uint32 status; OS_printf("Starting task 1\n"); - OS_TaskRegister(); while (1) { @@ -100,7 +99,6 @@ void task_2(void) uint32 status; OS_printf("Starting task 2\n"); - OS_TaskRegister(); while (1) { @@ -126,7 +124,6 @@ void task_3(void) uint32 status; OS_printf("Starting task 3\n"); - OS_TaskRegister(); while (1) { diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 7a1f7de7f..a0ced207f 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -173,10 +173,9 @@ void TestCreatRemove(void) UtAssert_True(status == OS_SUCCESS, "status after remove max name length file = %d", (int)status); /* try creating with file name too big, should fail */ - fd = ~OS_OBJECT_ID_UNDEFINED; status = OS_OpenCreate(&fd, longfilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status < OS_SUCCESS, "status after create file name too long = %d", (int)status); - UtAssert_UINT32_EQ(fd, OS_OBJECT_ID_UNDEFINED); + UtAssert_True(!OS_ObjectIdDefined(fd), "fd(%lu) not defined", OS_ObjectIdToInteger(fd)); /* try removing with file name too big. Should Fail */ status = OS_remove(longfilename); @@ -235,10 +234,9 @@ void TestOpenClose(void) UtAssert_True(status != OS_SUCCESS, "status after close = %d", (int)status); /* open a file that was never in the system */ - fd = ~OS_OBJECT_ID_UNDEFINED; status = OS_OpenCreate(&fd, "/drive0/FileNotHere", OS_FILE_FLAG_NONE, OS_READ_ONLY); UtAssert_True(status < OS_SUCCESS, "status after open = %d", (int)status); - UtAssert_UINT32_EQ(fd, OS_OBJECT_ID_UNDEFINED); + UtAssert_True(!OS_ObjectIdDefined(fd), "fd(%lu) not defined", OS_ObjectIdToInteger(fd)); /* try removing the file from the drive to end the function */ status = OS_remove(filename); diff --git a/src/tests/mutex-test/mutex-test.c b/src/tests/mutex-test/mutex-test.c index dbe69950d..d47de5741 100644 --- a/src/tests/mutex-test/mutex-test.c +++ b/src/tests/mutex-test/mutex-test.c @@ -60,7 +60,6 @@ void task_1(void) uint32 status; OS_printf("Starting task 1\n"); - OS_TaskRegister(); while (1) { @@ -112,7 +111,6 @@ void task_2(void) uint32 status; OS_printf("Starting task 2\n"); - OS_TaskRegister(); while (1) { @@ -165,7 +163,6 @@ void task_3(void) uint32 status; OS_printf("Starting task 3\n"); - OS_TaskRegister(); while (1) { diff --git a/src/tests/osal-core-test/osal-core-test.c b/src/tests/osal-core-test/osal-core-test.c index 79593e653..a70aa4aec 100644 --- a/src/tests/osal-core-test/osal-core-test.c +++ b/src/tests/osal-core-test/osal-core-test.c @@ -109,8 +109,6 @@ void UtTest_Setup(void) void task_generic_no_exit(void) { - OS_TaskRegister(); - while (1) { OS_TaskDelay(100); diff --git a/src/tests/queue-test/queue-test.c b/src/tests/queue-test/queue-test.c index 70ff31ce9..9d36294b1 100644 --- a/src/tests/queue-test/queue-test.c +++ b/src/tests/queue-test/queue-test.c @@ -72,8 +72,6 @@ void task_1(void) OS_printf("Starting task 1\n"); - OS_TaskRegister(); - OS_printf("Delay for 1 second before starting\n"); OS_TaskDelay(1000); diff --git a/src/tests/sem-speed-test/sem-speed-test.c b/src/tests/sem-speed-test/sem-speed-test.c index 797ed8af7..3c2a61379 100644 --- a/src/tests/sem-speed-test/sem-speed-test.c +++ b/src/tests/sem-speed-test/sem-speed-test.c @@ -96,7 +96,6 @@ void task_1(void) uint32 status; OS_printf("Starting task 1\n"); - OS_TaskRegister(); while (task_1_work < SEMTEST_WORK_LIMIT) { @@ -123,7 +122,6 @@ void task_2(void) uint32 status; OS_printf("Starting task 2\n"); - OS_TaskRegister(); while (task_2_work < SEMTEST_WORK_LIMIT) { diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c index 5a13a14fa..95f570dd8 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c @@ -27,12 +27,53 @@ #include "os-shared-sockets.h" #include "os-shared-idmap.h" #include "os-shared-file.h" +#include "os-shared-select.h" +#include "os-impl-io.h" #include "OCS_sys_socket.h" +#include "OCS_errno.h" #include "OCS_fcntl.h" +#include "OCS_arpa_inet.h" #include "ut-adaptor-portable-posix-io.h" +/* Unique error code for return testing */ +#define UT_ERR_UNIQUE 0xDEADBEEF + +/* Buffer size */ +#define UT_BUFFER_SIZE 16 + +/* OS_SelectSingle_Impl hook to set SelectFlags per input */ +static int32 UT_Hook_OS_SelectSingle_Impl(void *UserObj, int32 StubRetcode, uint32 CallCount, + const UT_StubContext_t *Context) +{ + uint32 *SelectFlags; + + SelectFlags = UT_Hook_GetArgValueByName(Context, "SelectFlags", uint32 *); + + if (SelectFlags != NULL) + { + *SelectFlags = *((uint32 *)UserObj); + } + + return 0; +} + +/* OCS_getsockopt hook to set sockopt per input */ +static int32 UT_Hook_OCS_getsockopt(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) +{ + int *optval; + + optval = UT_Hook_GetArgValueByName(Context, "optval", int *); + + if (optval != NULL) + { + *optval = *((int *)UserObj); + } + + return 0; +} + void Test_OS_SocketOpen_Impl(void) { OS_object_token_t token = {0}; @@ -50,7 +91,7 @@ void Test_OS_SocketOpen_Impl(void) OS_stream_table[0].socket_domain = -1; OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_ERR_NOT_IMPLEMENTED); - /* Socket error */ + /* Fail socket */ OS_stream_table[0].socket_domain = OS_SocketDomain_INET; UT_SetDeferredRetcode(UT_KEY(OCS_socket), 1, -1); OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_ERROR); @@ -80,6 +121,308 @@ void Test_OS_SocketOpen_Impl(void) "Socket not selectable without O_NONBLOCK flag"); } +void Test_OS_SocketBind_Impl(void) +{ + OS_object_token_t token = {0}; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Set up token for index 0 */ + token.obj_idx = UT_INDEX_0; + + /* Default family case */ + sa->sa_family = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (&token, &addr), OS_ERR_BAD_ADDRESS); + + /* Note - not attempting to hit addrlen > OS_SOCKADDR_MAX_LEN at this point (NOT MC/DC) + * would require compiling with a small OS_SOCKADDR_MAX_LEN or bigger structure */ + + /* Fail bind */ + sa->sa_family = OCS_AF_INET; + UT_SetDeferredRetcode(UT_KEY(OCS_bind), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (&token, &addr), OS_ERROR); + + /* Fail listen */ + sa->sa_family = OCS_AF_INET6; + OS_stream_table[0].socket_type = OS_SocketType_STREAM; + UT_SetDeferredRetcode(UT_KEY(OCS_listen), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (&token, &addr), OS_ERROR); + + /* Success with OS_SocketType_STREAM */ + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (&token, &addr), OS_SUCCESS); + + /* Success with ~OS_SocketType_STREAM */ + OS_stream_table[0].socket_type = ~OS_SocketType_STREAM; + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (&token, &addr), OS_SUCCESS); +} + +void Test_OS_SocketConnect_Impl(void) +{ + OS_object_token_t token = {0}; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + int32 selectflags; + int sockopt; + + /* Set up token for index 0 */ + token.obj_idx = UT_INDEX_0; + + /* Default family case */ + sa->sa_family = -1; + addr.ActualLength = sizeof(struct OCS_sockaddr_in); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_ERR_BAD_ADDRESS); + + /* Sucessful connect */ + sa->sa_family = OCS_AF_INET; + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_SUCCESS); + + /* Fail connect, errno ! EINPROGRESS */ + OCS_errno = ~OCS_EINPROGRESS; + UT_SetDefaultReturnValue(UT_KEY(OCS_connect), -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_ERROR); + + /* Fail OS_SelectSingle_Impl, errno == EINPROGRESS */ + OCS_errno = OCS_EINPROGRESS; + sa->sa_family = OCS_AF_INET6; + addr.ActualLength = sizeof(struct OCS_sockaddr_in6); + OS_impl_filehandle_table[0].selectable = true; + UT_SetDeferredRetcode(UT_KEY(OS_SelectSingle_Impl), 1, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), UT_ERR_UNIQUE); + + /* Timout error by clearing select flags with hook */ + selectflags = 0; + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), UT_Hook_OS_SelectSingle_Impl, &selectflags); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_ERROR_TIMEOUT); + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), NULL, NULL); + + /* Fail getsockopt status */ + UT_SetDeferredRetcode(UT_KEY(OCS_getsockopt), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_ERROR); + + /* Nonzero getsockopt sockopt */ + sockopt = 1; + UT_SetHookFunction(UT_KEY(OCS_getsockopt), UT_Hook_OCS_getsockopt, &sockopt); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_ERROR); + UT_SetHookFunction(UT_KEY(OCS_getsockopt), NULL, NULL); + + /* Success case with selectable */ + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_SUCCESS); + + /* Success case with not selectable */ + OS_impl_filehandle_table[0].selectable = false; + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (&token, &addr, 0), OS_SUCCESS); +} + +void Test_OS_SocketAccept_Impl(void) +{ + OS_object_token_t sock_token = {0}; + OS_object_token_t conn_token = {0}; + OS_SockAddr_t addr = {0}; + int32 selectflags; + + /* Set up tokens */ + sock_token.obj_idx = UT_INDEX_0; + conn_token.obj_idx = UT_INDEX_1; + + /* Fail OS_SelectSingle_Impl with sock_token selectable */ + OS_impl_filehandle_table[0].selectable = true; + UT_SetDeferredRetcode(UT_KEY(OS_SelectSingle_Impl), 1, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), UT_ERR_UNIQUE); + + /* Timeout by clearing select flags with hook */ + selectflags = 0; + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), UT_Hook_OS_SelectSingle_Impl, &selectflags); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_ERROR_TIMEOUT); + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), NULL, NULL); + + /* Clear selectable and fail accept */ + OS_impl_filehandle_table[0].selectable = false; + UT_SetDeferredRetcode(UT_KEY(OCS_accept), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_ERROR); + + /* Success case */ + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); +} + +void Test_OS_SocketRecvFrom_Impl(void) +{ + OS_object_token_t token = {0}; + uint8 buffer[UT_BUFFER_SIZE]; + OS_SockAddr_t addr = {0}; + int32 selectflags; + + /* Set up token */ + token.obj_idx = UT_INDEX_0; + + /* NULL RemoteAddr, selectable, fail OS_SelectSingle_Impl */ + OS_impl_filehandle_table[0].selectable = true; + UT_SetDeferredRetcode(UT_KEY(OS_SelectSingle_Impl), 1, UT_ERR_UNIQUE); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), NULL, 0), UT_ERR_UNIQUE); + + /* Timeout by clearing select flags with hook */ + selectflags = 0; + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), UT_Hook_OS_SelectSingle_Impl, &selectflags); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), &addr, 0), OS_ERROR_TIMEOUT); + UT_SetHookFunction(UT_KEY(OS_SelectSingle_Impl), NULL, NULL); + + /* Not selectable, 0 timeout, EAGAIN error from recvfrom error */ + OS_impl_filehandle_table[0].selectable = false; + OCS_errno = OCS_EAGAIN; + UT_SetDeferredRetcode(UT_KEY(OCS_recvfrom), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), &addr, 0), OS_QUEUE_EMPTY); + + /* With timeout, other error from recvfrom error */ + OCS_errno = 0; + UT_SetDeferredRetcode(UT_KEY(OCS_recvfrom), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), &addr, 1), OS_ERROR); + + /* With timeout, EWOULDBLOCK error from recvfrom error */ + OCS_errno = OCS_EWOULDBLOCK; + UT_SetDeferredRetcode(UT_KEY(OCS_recvfrom), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), &addr, 1), OS_QUEUE_EMPTY); + + /* Success with NULL RemoteAddr */ + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), NULL, 0), OS_SUCCESS); + + /* Success with non-NULL RemoteAddr */ + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (&token, buffer, sizeof(buffer), &addr, 0), OS_SUCCESS); +} + +void Test_OS_SocketSendTo_Impl(void) +{ + OS_object_token_t token = {0}; + uint8 buffer[UT_BUFFER_SIZE]; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Set up token */ + token.obj_idx = UT_INDEX_0; + + /* Bad adderss length */ + sa->sa_family = -1; + addr.ActualLength = sizeof(struct OCS_sockaddr_in); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo_Impl, (&token, buffer, sizeof(buffer), &addr), OS_ERR_BAD_ADDRESS); + + /* AF_INET, failed sendto */ + sa->sa_family = OCS_AF_INET; + UT_SetDeferredRetcode(UT_KEY(OCS_sendto), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo_Impl, (&token, buffer, sizeof(buffer), &addr), OS_ERROR); + + /* AF_INET6, success */ + sa->sa_family = OCS_AF_INET6; + addr.ActualLength = sizeof(struct OCS_sockaddr_in6); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo_Impl, (&token, buffer, sizeof(buffer), &addr), OS_SUCCESS); +} + +void Test_OS_SocketGetInfo_Impl(void) +{ + OSAPI_TEST_FUNCTION_RC(OS_SocketGetInfo_Impl, (NULL, NULL), OS_SUCCESS); +} + +void Test_OS_SocketAddrInit_Impl(void) +{ + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Unknown domain */ + sa->sa_family = -1; + addr.ActualLength = 5; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit_Impl, (&addr, -1), OS_ERR_NOT_IMPLEMENTED); + UtAssert_INT32_EQ(sa->sa_family, 0); + UtAssert_INT32_EQ(addr.ActualLength, 0); + + /* Note - not attempting to hit addrlen > OS_SOCKADDR_MAX_LEN at this point (NOT MC/DC) + * would require compiling with a small OS_SOCKADDR_MAX_LEN or bigger structure */ + + /* INET, success */ + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit_Impl, (&addr, OS_SocketDomain_INET), OS_SUCCESS); + UtAssert_INT32_EQ(sa->sa_family, OCS_AF_INET); + UtAssert_INT32_EQ(addr.ActualLength, sizeof(struct OCS_sockaddr_in)); + + /* AF_INET6, success */ + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit_Impl, (&addr, OS_SocketDomain_INET6), OS_SUCCESS); + UtAssert_INT32_EQ(sa->sa_family, OCS_AF_INET6); + UtAssert_INT32_EQ(addr.ActualLength, sizeof(struct OCS_sockaddr_in6)); +} + +void Test_OS_SocketAddrToString_Impl(void) +{ + char buffer[UT_BUFFER_SIZE]; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Bad family */ + sa->sa_family = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString_Impl, (buffer, sizeof(buffer), &addr), OS_ERR_BAD_ADDRESS); + + /* AF_INET6 failed inet_ntop */ + sa->sa_family = OCS_AF_INET6; + UT_SetDeferredRetcode(UT_KEY(OCS_inet_ntop), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString_Impl, (buffer, sizeof(buffer), &addr), OS_ERROR); + + /* AF_INET, success */ + sa->sa_family = OCS_AF_INET; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString_Impl, (buffer, sizeof(buffer), &addr), OS_SUCCESS); +} + +void Test_OS_SocketAddrFromString_Impl(void) +{ + char buffer[UT_BUFFER_SIZE]; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Bad family */ + sa->sa_family = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString_Impl, (&addr, buffer), OS_ERR_BAD_ADDRESS); + + /* AF_INET6 failed inet_ntop */ + sa->sa_family = OCS_AF_INET6; + UT_SetDeferredRetcode(UT_KEY(OCS_inet_pton), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString_Impl, (&addr, buffer), OS_ERROR); + + /* AF_INET, success */ + sa->sa_family = OCS_AF_INET; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString_Impl, (&addr, buffer), OS_SUCCESS); +} + +void Test_OS_SocketAddrGetPort_Impl(void) +{ + uint16 port; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Bad family */ + sa->sa_family = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort_Impl, (&port, &addr), OS_ERR_BAD_ADDRESS); + + /* AF_INET6, success */ + sa->sa_family = OCS_AF_INET6; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort_Impl, (&port, &addr), OS_SUCCESS); + + /* AF_INET, success */ + sa->sa_family = OCS_AF_INET; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort_Impl, (&port, &addr), OS_SUCCESS); +} + +void Test_OS_SocketAddrSetPort_Impl(void) +{ + uint16 port = 1; + OS_SockAddr_t addr = {0}; + struct OCS_sockaddr *sa = (struct OCS_sockaddr *)&addr.AddrData; + + /* Bad family */ + sa->sa_family = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort_Impl, (&addr, port), OS_ERR_BAD_ADDRESS); + + /* AF_INET6, success */ + sa->sa_family = OCS_AF_INET6; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort_Impl, (&addr, port), OS_SUCCESS); + + /* AF_INET, success */ + sa->sa_family = OCS_AF_INET; + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort_Impl, (&addr, port), OS_SUCCESS); +} + /* ------------------- End of test cases --------------------------------------*/ /* Osapi_Test_Setup @@ -109,4 +452,15 @@ void Osapi_Test_Teardown(void) {} void UtTest_Setup(void) { ADD_TEST(OS_SocketOpen_Impl); + ADD_TEST(OS_SocketBind_Impl); + ADD_TEST(OS_SocketConnect_Impl); + ADD_TEST(OS_SocketAccept_Impl); + ADD_TEST(OS_SocketRecvFrom_Impl); + ADD_TEST(OS_SocketSendTo_Impl); + ADD_TEST(OS_SocketGetInfo_Impl); + ADD_TEST(OS_SocketAddrInit_Impl); + ADD_TEST(OS_SocketAddrToString_Impl); + ADD_TEST(OS_SocketAddrFromString_Impl); + ADD_TEST(OS_SocketAddrGetPort_Impl); + ADD_TEST(OS_SocketAddrSetPort_Impl); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index ae1035d24..1da6564aa 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -184,17 +184,6 @@ void Test_OS_TaskSetPriority(void) UtAssert_True(actual == expected, "OS_TaskSetPriority() (%ld) == OS_SUCCESS", (long)actual); } -void Test_OS_TaskRegister(void) -{ - /* - * Test Case For: - * int32 OS_TaskRegister (void) - */ - int32 expected = OS_SUCCESS; - int32 actual = OS_TaskRegister(); - - UtAssert_True(actual == expected, "OS_TaskRegister() (%ld) == OS_SUCCESS", (long)actual); -} void Test_OS_TaskGetId(void) { /* @@ -360,7 +349,6 @@ void UtTest_Setup(void) ADD_TEST(OS_TaskExit); ADD_TEST(OS_TaskDelay); ADD_TEST(OS_TaskSetPriority); - ADD_TEST(OS_TaskRegister); ADD_TEST(OS_TaskGetId); ADD_TEST(OS_TaskGetIdByName); ADD_TEST(OS_TaskGetInfo); diff --git a/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c b/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c index 27f89d3ad..7501db7ae 100644 --- a/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c @@ -30,12 +30,17 @@ const char *OCS_inet_ntop(int af, const void *cp, char *buf, size_t len) { int32 Status; + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_ntop), af); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_ntop), cp); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_ntop), buf); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_ntop), len); + Status = UT_DEFAULT_IMPL(OCS_inet_ntop); if (Status == 0) { /* "nominal" response */ - return inet_ntop(af, cp, buf, len); + return buf; } return (char *)0; @@ -43,5 +48,9 @@ const char *OCS_inet_ntop(int af, const void *cp, char *buf, size_t len) int OCS_inet_pton(int af, const char *cp, void *buf) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_pton), af); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_pton), cp); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_inet_pton), buf); + return UT_DEFAULT_IMPL(OCS_inet_pton); } diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c index 4f4b720d6..4b8cff505 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c @@ -33,5 +33,20 @@ #include "utstubs.h" #include "os-shared-select.h" -UT_DEFAULT_STUB(OS_SelectSingle_Impl, (const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs)) -UT_DEFAULT_STUB(OS_SelectMultiple_Impl, (OS_FdSet * ReadSet, OS_FdSet *WriteSet, int32 msecs)) +int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), token); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), SelectFlags); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectSingle_Impl), msecs); + + return UT_DEFAULT_IMPL(OS_SelectSingle_Impl); +} + +int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), ReadSet); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), WriteSet); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_SelectMultiple_Impl), msecs); + + return UT_DEFAULT_IMPL(OS_SelectMultiple_Impl); +} diff --git a/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c b/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c index 6a7e0d9d2..4d71e50e8 100644 --- a/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c @@ -27,46 +27,91 @@ int OCS_accept(int fd, struct OCS_sockaddr *addr, OCS_socklen_t *addr_len) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_accept), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_accept), addr); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_accept), addr_len); + return UT_DEFAULT_IMPL(OCS_accept); } int OCS_bind(int fd, const struct OCS_sockaddr *addr, OCS_socklen_t len) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_bind), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_bind), addr); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_bind), len); + return UT_DEFAULT_IMPL(OCS_bind); } int OCS_connect(int fd, const struct OCS_sockaddr *addr, OCS_socklen_t len) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_connect), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_connect), addr); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_connect), len); + return UT_DEFAULT_IMPL(OCS_connect); } int OCS_getsockopt(int fd, int level, int optname, void *optval, OCS_socklen_t *optlen) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_getsockopt), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_getsockopt), level); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_getsockopt), optname); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_getsockopt), optval); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_getsockopt), optlen); + return UT_DEFAULT_IMPL(OCS_getsockopt); } int OCS_listen(int fd, int n) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_listen), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_listen), n); + return UT_DEFAULT_IMPL(OCS_listen); } OCS_ssize_t OCS_recvfrom(int fd, void *buf, size_t n, int flags, struct OCS_sockaddr *addr, OCS_socklen_t *addr_len) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), buf); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), n); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), flags); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), addr); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_recvfrom), addr_len); + return UT_DEFAULT_IMPL(OCS_recvfrom); } OCS_ssize_t OCS_sendto(int fd, const void *buf, size_t n, int flags, const struct OCS_sockaddr *addr, OCS_socklen_t addr_len) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), buf); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), n); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), flags); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), addr); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_sendto), addr_len); + return UT_DEFAULT_IMPL(OCS_sendto); } int OCS_setsockopt(int fd, int level, int optname, const void *optval, OCS_socklen_t optlen) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_setsockopt), fd); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_setsockopt), level); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_setsockopt), optname); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_setsockopt), optval); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_setsockopt), optlen); + return UT_DEFAULT_IMPL(OCS_setsockopt); } int OCS_socket(int domain, int type, int protocol) { + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_socket), domain); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_socket), type); + UT_Stub_RegisterContextGenericArg(UT_KEY(OCS_socket), protocol); + return UT_DEFAULT_IMPL(OCS_socket); } diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h index 9e8f1a32f..7a57eba32 100644 --- a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h @@ -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 */ diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c index 6702e8c0e..b71468a85 100644 --- a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c @@ -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; +} diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c index 147556b3d..b080a3dd4 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -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 --------------------------------------*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 41dd84e80..2e47c3178 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -79,8 +79,6 @@ void generic_test_task(void) osal_id_t task_id; OS_task_prop_t task_prop; - OS_TaskRegister(); - task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); @@ -332,8 +330,6 @@ void delete_handler_test_task(void) osal_id_t task_id; OS_task_prop_t task_prop; - OS_TaskRegister(); - task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); @@ -438,8 +434,6 @@ void exit_test_task(void) osal_id_t task_id; OS_task_prop_t task_prop; - OS_TaskRegister(); - task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); @@ -657,112 +651,6 @@ void UT_os_task_set_priority_test() return; } -/*--------------------------------------------------------------------------------* -** Syntax: OS_TaskRegister -** Purpose: Registers the task, performs application- and OS-specific inits -** Parameters: To-be-filled-in -** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid task id -** OS_ERROR if the OS call failed -** OS_SUCCESS if succeeded -**--------------------------------------------------------------------------------*/ -void register_test_task(void) -{ - osal_id_t task_id; - OS_task_prop_t task_prop; - - g_task_result = OS_TaskRegister(); - - task_id = OS_TaskGetId(); - OS_TaskGetInfo(task_id, &task_prop); - - UtPrintf("Starting RegisterTest Task: %s\n", task_prop.name); - ; - - /* - ** Release the semaphore so the main function can record the results of the test - ** and clean up - */ - OS_BinSemGive(g_task_sync_sem); - - for (;;) - { - OS_TaskDelay(1000); - } -} - -/*--------------------------------------------------------------------------------*/ - -void UT_os_task_register_test(void) -{ - int32 res = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_TaskRegister(); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_task_register_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Invalid-ID-arg"; - - res = OS_TaskRegister(); - if (res == OS_ERR_INVALID_ID) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#3 Nominal"; - - /* Setup */ - res = OS_BinSemCreate(&g_task_sync_sem, "TaskSync", 1, 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Bin-Sem-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - OS_BinSemTake(g_task_sync_sem); - - res = OS_TaskCreate(&g_task_ids[3], g_task_names[3], register_test_task, OSAL_STACKPTR_C(&g_task_stacks[3]), - sizeof(g_task_stacks[3]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0); - if (res != OS_SUCCESS) - { - testDesc = "#3 Nominal - Task-Create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - } - else - { - /* Wait for the task to finish the test */ - OS_BinSemTake(g_task_sync_sem); - /* Delay to let child task run */ - OS_TaskDelay(500); - - OS_TaskDelete(g_task_ids[3]); - res = OS_BinSemDelete(g_task_sync_sem); - - if (g_task_result == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - } - } - -UT_os_task_register_test_exit_tag: - return; -} - /*--------------------------------------------------------------------------------*/ void getid_test_task(void) @@ -770,8 +658,6 @@ void getid_test_task(void) osal_id_t task_id; OS_task_prop_t task_prop; - OS_TaskRegister(); - task_id = OS_TaskGetId(); OS_TaskGetInfo(task_id, &task_prop); diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c index 1567f238d..e1662fd66 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -237,7 +237,6 @@ void UtTest_Setup(void) UtTest_Add(UT_os_task_exit_test, UT_os_init_task_exit_test, NULL, "OS_TaskExit"); UtTest_Add(UT_os_task_delay_test, UT_os_init_task_delay_test, NULL, "OS_TaskDelay"); UtTest_Add(UT_os_task_set_priority_test, UT_os_init_task_set_priority_test, NULL, "OS_TaskSetPriority"); - UtTest_Add(UT_os_task_register_test, UT_os_init_task_register_test, NULL, "OS_TaskRegister"); UtTest_Add(UT_os_task_get_id_test, UT_os_init_task_get_id_test, NULL, "OS_TaskGetId"); UtTest_Add(UT_os_task_get_id_by_name_test, UT_os_init_task_get_id_by_name_test, NULL, "OS_TaskGetIdByName"); UtTest_Add(UT_os_task_get_info_test, UT_os_init_task_get_info_test, NULL, "OS_TaskGetInfo"); diff --git a/src/ut-stubs/osapi-utstub-task.c b/src/ut-stubs/osapi-utstub-task.c index ce3dc4c80..5bd42d0d6 100644 --- a/src/ut-stubs/osapi-utstub-task.c +++ b/src/ut-stubs/osapi-utstub-task.c @@ -178,31 +178,6 @@ int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority) return status; } -/*****************************************************************************/ -/** -** \brief OS_TaskRegister stub function -** -** \par Description -** This function is used to mimic the response of the OS API function -** OS_TaskRegister. The user can adjust the response by setting the value -** of UT_OS_Fail prior to this function being called. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns either OS_SUCCESS or OS_ERROR. -** -******************************************************************************/ -int32 OS_TaskRegister(void) -{ - int32 status; - - status = UT_DEFAULT_IMPL(OS_TaskRegister); - - return status; -} - /*****************************************************************************/ /** ** \brief OS_TaskGetId stub function