diff --git a/README.md b/README.md index 01a94dd59..5b3857e49 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,18 @@ The autogenerated OSAL user's guide can be viewed at + +### Development Build: v5.1.0-rc1+dev262 - Adds test cases for `OS_ObjectIdFinalizeDelete`, `OS_DeleteAllObjects`, and others to get 100% line and function coverage on VxWorks and shared/portable layers. - Ensures APIs check for `NULL` inputs or have documentation stating that a null value is allowed. @@ -33,7 +44,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev221 +### Development Build: v5.1.0-rc1+dev221 - Fixes `printf` format to correctly build in RTEMS-5. - **Deprecates `OS_fsBlocksFree()` and `OS_fsBytesFree()`** in favor of `OS_FileSysStatVolume()`. @@ -52,7 +63,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev184 +### Development Build: v5.1.0-rc1+dev184 - Address issues with OSAL global table management: - use iterators whenever possible @@ -78,7 +89,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev149 +### Development Build: v5.1.0-rc1+dev149 - Document UtAssert_Message parameters, also adds "see also" note for helper macros. - Fix doxygen typo @@ -88,7 +99,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev132 +### Development Build: v5.1.0-rc1+dev132 - Convert the OSAL Configuration Guide from docx and pdf to a markdown file. - Test Tasks do not run at 100%. Move all definitions and instantiations out of the core-test header file and reuse the already-existing single task definition. @@ -102,7 +113,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev109 +### Development Build: v5.1.0-rc1+dev109 - Add support for RTEMS 5.1 in the OSAL and provides defines and necessary ifdefs so RTEMS 4.11 can continue to be supported. - Adds functional test for OS_chmod @@ -112,7 +123,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev91 +### Development Build: v5.1.0-rc1+dev91 - Rename `UT_SetForceFail` to `UT_SetDefaultReturnValue` since some functions that retain more than 1 value are not necessarily failing - Add a 5th timer to TimerTest functional to test the one shot (zero-length time interval) case. @@ -122,7 +133,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev75 +### Development Build: v5.1.0-rc1+dev75 - Ensure that the handle is not NULL before invoking dlclose(). In particular the handle will be NULL for static modules. Shutdown after CTRL+C occurs normally (no segfault). - Add a "flags" parameter to OS_ModuleLoad() to indicate the desired symbol visibility: @@ -131,7 +142,7 @@ The autogenerated OSAL user's guide can be viewed at -### Development Build: 5.1.0-rc1+dev68 +### Development Build: v5.1.0-rc1+dev68 - When `OS_DEBUG` is enabled, this adds a message if mutex give/take actions occur outside the expected sequence. This informs the user (via the debug console) if a lock is taken more than once or if a lock is given by a different task than the one that originally took it: ``` @@ -143,47 +154,47 @@ OS_MutSemTake():216:WARNING: Task 65547 taking mutex 327685 while owned by task - UtAssert macros now accept variable string arguments.The `UtAssert_True` wrapper around call is no longer needed to accommodate dynamic string output, thus removing the double assert. UtAssert macros will now be able to offer more information by themselves. - See -### Development Build: 5.1.0-rc1+dev60 +### Development Build: v5.1.0-rc1+dev60 - Appliy standard formating, whitespace-only changes - See -### Development Build: 5.1.0-rc1+dev55 +### Development Build: v5.1.0-rc1+dev55 - Deprecate `OS_open` and `OS_creat` to and replaced them with by `OS_OpenCreate`, which implements both functions via flags, and follows the correct OSAL API patterns. - Change use of uint32 for ID to the correct typedef. Also use ObjectIdFromInteger/ObjectIdToInteger where it is intended to convert these values to integers e.g. for the "name" fields in RTEMS. - See -### Development Build: 5.1.0-rc1+dev49 +### Development Build: v5.1.0-rc1+dev49 - Adds an event callback mechanism to certain state changes in OSAL. This allows the CFE PSP to be notified at these points, and therefore it can add platform-specific functionality. - Correct issues involving recent OS_Milli2Ticks change. - See -### Development Build: 5.1.0-rc1+dev44 +### Development Build: v5.1.0-rc1+dev44 - Removes OS_Tick2Micros and internalize OS_Milli2Ticks. - Adds ut_assert address equal macro. - See -### Development Build: 5.1.0-rc1+dev38 +### Development Build: v5.1.0-rc1+dev38 - Sets Revision to 99 for development builds - See -### Development Build: 5.1.0-rc1+dev34 +### Development Build: v5.1.0-rc1+dev34 - Move this existing function into the public API, as it is performs more verification than the OS_ConvertToArrayIndex function. - The C library type is signed, and this makes the result check work as intended. - See -### Development Build: 5.1.0-rc1+dev16 +### Development Build: v5.1.0-rc1+dev16 - In the next major OSAL release, this code will be no longer supported at all. It should be removed early in the cycle to avoid needing to maintain this compatibility code. This code was already conditional on the OSAL_OMIT_DEPRECATED flag and as such the CCB has already tested/verified running the code in this configuration as part of CI scripts. After this change, the build should be equivalent to the result of building with OMIT_DEPRECATED=true. - See -### Development Build: 5.1.0-rc1+dev12 +### Development Build: v5.1.0-rc1+dev12 - Removes internal functions that are no longer used or defined but whose prototypes and stubs were still present in OS_ObjectIdMap - Removes repetitive clearing of the global ID and unlocking global table and replaces these with common implementation in the idmap source file. This moves deleting tables to be similar to creating tables and provides @@ -191,7 +202,7 @@ a common location for additional table-deletion-related logic. - Propagates return code from OS_TaskRegister_Impl(). If this routine fails then return the error to the caller, which also prevents the task from starting. - See -### Development Build: 5.1.0-rc1+dev5 +### Development Build: v5.1.0-rc1+dev5 - Adds OSAL network APIs missing functional tests as well as tests for OS_TimedRead and OS_TimedWrite - Allows separate, dynamic registration of test setup and teardown routines which are executed before and after the normal test routine, which can create and delete any global/common test prerequisites. diff --git a/src/os/inc/osapi-file.h b/src/os/inc/osapi-file.h index 421b64442..a281413ac 100644 --- a/src/os/inc/osapi-file.h +++ b/src/os/inc/osapi-file.h @@ -117,65 +117,6 @@ typedef enum * @{ */ -#ifndef OSAL_OMIT_DEPRECATED - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Creates a file specified by path - * - * Creates a file specified by const char *path, with read/write - * permissions by access. The file is also automatically opened by the - * create call. - * - * @param[in] path File name to create - * @param[in] access Intended access mode - see @ref OSFileAccess - * - * @note Valid handle IDs are never negative. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A file handle ID or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long - * @retval #OS_ERROR if permissions are unknown or OS call fails - * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left - * - * @deprecated Replaced by OS_OpenCreate() with flags set to - * OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE. - */ -int32 OS_creat(const char *path, int32 access); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Opens a file - * - * Opens a file. - * - * @param[in] path File name to create - * @param[in] access Intended access mode - see @ref OSFileAccess - * @param[in] mode The file permissions. This parameter is passed through to the - * native open call, but will be ignored. The file mode (or permissions) - * are ignored by the POSIX open call when the O_CREAT access flag is not passed in. - * - * @note Valid handle IDs are never negative. Failure of this - * call can be checked by testing if the result is less than 0. - * - * @return A file handle ID or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if path is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars - * @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed - * @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long - * @retval #OS_ERROR if permissions are unknown or OS call fails - * @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left - * - * @deprecated Replaced by OS_OpenCreate() with flags set to - * OS_FILE_FLAG_NONE. - */ -int32 OS_open(const char *path, int32 access, uint32 mode); - -#endif - /*-------------------------------------------------------------------------------------*/ /** * @brief Open or create a file diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h index e49671b0d..b8fc9f30a 100644 --- a/src/os/inc/osapi-filesys.h +++ b/src/os/inc/osapi-filesys.h @@ -188,52 +188,6 @@ int32 OS_rmfs(const char *devname); */ int32 OS_unmount(const char *mountpoint); -#ifndef OSAL_OMIT_DEPRECATED - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtain number of blocks free - * - * Returns the number of free blocks in a volume - * - * @param[in] name The device/path to operate on - * - * @return Block count or appropriate error code, see @ref OSReturnCodes - * @retval #OS_INVALID_POINTER if name is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long - * @retval #OS_ERROR if the OS call failed - * - * @deprecated Replaced by OS_FileSysStatVolume() - - * Value can be obtained by reading the "blocks_free" struct member. - * - */ -int32 OS_fsBlocksFree(const char *name); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Obtains the number of free bytes in a volume - * - * Returns the number of free bytes in a volume - * - * @note uses a 64 bit data type to support filesystems that - * are greater than 4 Gigabytes - * - * @param[in] name The device/path to operate on - * @param[out] bytes_free The number of free bytes - * - * @return Execution status, see @ref OSReturnCodes - * @retval #OS_SUCCESS @copybrief OS_SUCCESS - * @retval #OS_INVALID_POINTER if name is NULL - * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long - * @retval #OS_ERROR if the OS call failed - * - * @deprecated Replaced by OS_FileSysStatVolume(). - * Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members. - */ -int32 OS_fsBytesFree(const char *name, uint64 *bytes_free); - -#endif /* OSAL_OMIT_DEPRECATED */ - /*-------------------------------------------------------------------------------------*/ /** * @brief Obtains information about size and free space in a volume diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h deleted file mode 100644 index 5ea3b2acb..000000000 --- a/src/os/inc/osapi-os-core.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 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: osapi-os-core.h - * - * Author: Ezra Yeheksli -Code 582/Raytheon - * - * Purpose: Contains functions prototype definitions and variables declarations - * for the OS Abstraction Layer, Core OS module - */ - -#ifndef _osapi_core_ -#define _osapi_core_ - -#ifdef OSAL_OMIT_DEPRECATED -#error This header header is deprecated -#endif - -/* - * BACKWARD COMPATIBILITY HEADER - * - * OSAPI headers have beens split into subsystem-based components. - * - * This header is now just a wrapper that includes the same general - * set of components that this file traditionally supplied. - */ -#include "osapi-common.h" -#include "osapi-idmap.h" -#include "osapi-task.h" -#include "osapi-queue.h" -#include "osapi-binsem.h" -#include "osapi-countsem.h" -#include "osapi-mutex.h" -#include "osapi-clock.h" -#include "osapi-heap.h" -#include "osapi-error.h" -#include "osapi-select.h" -#include "osapi-printf.h" -#include "osapi-bsp.h" - -#endif diff --git a/src/os/inc/osapi-os-filesys.h b/src/os/inc/osapi-os-filesys.h deleted file mode 100644 index a786261ee..000000000 --- a/src/os/inc/osapi-os-filesys.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 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: osapi-os-filesys.h - * - * Author: Alan Cudmore Code 582 - * - * Purpose: Contains functions prototype definitions and variables declarations - * for the OS Abstraction Layer, File System module - */ - -#ifndef _osapi_filesys_ -#define _osapi_filesys_ - -#ifdef OSAL_OMIT_DEPRECATED -#error This header header is deprecated -#endif - -/* - * BACKWARD COMPATIBILITY HEADER - * - * OSAPI headers have beens split into subsystem-based components. - * - * This header is now just a wrapper that includes the same general - * set of components that this file traditionally supplied. - */ -#include "osapi-file.h" -#include "osapi-filesys.h" -#include "osapi-shell.h" - -#endif diff --git a/src/os/inc/osapi-os-loader.h b/src/os/inc/osapi-os-loader.h deleted file mode 100644 index 433b1d1a7..000000000 --- a/src/os/inc/osapi-os-loader.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 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: osapi-os-loader.h - * - * Author: Alan Cudmore - Code 582 - * - * Purpose: Contains functions prototype definitions and variables declarations - * for the OS Abstraction Layer, Object file loader API - */ - -#ifndef _osapi_loader_ -#define _osapi_loader_ - -#ifdef OSAL_OMIT_DEPRECATED -#error This header header is deprecated -#endif - -/* - * BACKWARD COMPATIBILITY HEADER - * - * OSAPI headers have beens split into subsystem-based components. - * - * This header is now just a wrapper that includes the same general - * set of components that this file traditionally supplied. - */ -#include "osapi-module.h" - -#endif diff --git a/src/os/inc/osapi-os-net.h b/src/os/inc/osapi-os-net.h deleted file mode 100644 index 6b18ca94e..000000000 --- a/src/os/inc/osapi-os-net.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 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: osapi-os-net.h - * - * Author: Alan Cudmore Code 582 - * - * Purpose: Contains functions prototype definitions and variables declarations - * for the OS Abstraction Layer, Network Module - */ - -#ifndef _osapi_network_ -#define _osapi_network_ - -#ifdef OSAL_OMIT_DEPRECATED -#error This header header is deprecated -#endif - -/* - * BACKWARD COMPATIBILITY HEADER - * - * OSAPI headers have beens split into subsystem-based components. - * - * This header is now just a wrapper that includes the same general - * set of components that this file traditionally supplied. - */ -#include "osapi-sockets.h" -#include "osapi-network.h" - -#endif diff --git a/src/os/inc/osapi-os-timer.h b/src/os/inc/osapi-os-timer.h deleted file mode 100644 index 7b27548f3..000000000 --- a/src/os/inc/osapi-os-timer.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer" - * - * Copyright (c) 2019 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: osapi-os-timer.h - * - * Author: Alan Cudmore - Code 582 - * - * Purpose: Contains functions prototype definitions and variable declarations - * for the OS Abstraction Layer, Timer API - */ - -#ifndef _osapi_timer_ -#define _osapi_timer_ - -#ifdef OSAL_OMIT_DEPRECATED -#error This header header is deprecated -#endif - -/* - * BACKWARD COMPATIBILITY HEADER - * - * OSAPI headers have beens split into subsystem-based components. - * - * This header is now just a wrapper that includes the same general - * set of components that this file traditionally supplied. - */ -#include "osapi-timebase.h" -#include "osapi-timer.h" - -#endif diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 9923b82c3..c907abf9f 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -30,7 +30,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 262 +#define OS_BUILD_NUMBER 280 #define OS_BUILD_BASELINE "v5.1.0-rc1" /* diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 6781985d1..ebb9c569b 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -148,89 +148,6 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc return return_code; } /* end OS_OpenCreate */ -/* - * The OS_open and OS_creat functions are deprecated, replaced by - * the generic OS_OpenCreate above - */ -#ifndef OSAL_OMIT_DEPRECATED - -/*---------------------------------------------------------------- - * - * Function: OS_creat - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_creat(const char *path, int32 access) -{ - osal_id_t filedes; - int32 return_code; - - /* - ** Check for a valid access mode - */ - switch (access) - { - case OS_WRITE_ONLY: - case OS_READ_WRITE: - break; - case OS_READ_ONLY: - default: - /* Read only does not make sense for creat() */ - return OS_ERROR; - } - - return_code = OS_OpenCreate(&filedes, path, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, access); - if (return_code == OS_SUCCESS) - { - /* for backward compatibility, on success return the ID as an int32. - * This will always within the positive range */ - return_code = (int32)OS_ObjectIdToInteger(filedes); - } - - return return_code; -} /* end OS_creat */ - -/*---------------------------------------------------------------- - * - * Function: OS_open - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_open(const char *path, int32 access, uint32 mode) -{ - osal_id_t filedes; - int32 return_code; - - /* - ** Check for a valid access mode - */ - switch (access) - { - case OS_WRITE_ONLY: - case OS_READ_WRITE: - case OS_READ_ONLY: - break; - default: - return OS_ERROR; - } - - return_code = OS_OpenCreate(&filedes, path, OS_FILE_FLAG_NONE, access); - if (return_code == OS_SUCCESS) - { - /* for backward compatibility, on success return the ID as an int32. - * This will always within the positive range */ - return_code = (int32)OS_ObjectIdToInteger(filedes); - } - - return return_code; -} /* end OS_open */ - -#endif - /*---------------------------------------------------------------- * * Function: OS_close diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 9eb01c768..12769b912 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -538,93 +538,6 @@ int32 OS_unmount(const char *mountpoint) return return_code; } /* end OS_unmount */ -#ifndef OSAL_OMIT_DEPRECATED - -/*---------------------------------------------------------------- - * - * Function: OS_fsBlocksFree - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_fsBlocksFree(const char *name) -{ - int32 return_code; - OS_statvfs_t statfs; - OS_object_token_t token; - - /* Check parameters */ - OS_CHECK_PATHNAME(name); - - return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &token); - - if (return_code == OS_SUCCESS) - { - return_code = OS_FileSysStatVolume_Impl(&token, &statfs); - - OS_ObjectIdRelease(&token); - - if (return_code == OS_SUCCESS) - { - return_code = statfs.blocks_free; - } - } - else - { - /* preserves historical error code */ - return_code = OS_FS_ERR_PATH_INVALID; - } - - return return_code; - -} /* end OS_fsBlocksFree */ - -/*---------------------------------------------------------------- - * - * Function: OS_fsBytesFree - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) -{ - int32 return_code; - OS_statvfs_t statfs; - OS_object_token_t token; - - /* Check parameters */ - OS_CHECK_PATHNAME(name); - OS_CHECK_POINTER(bytes_free); - - return_code = OS_ObjectIdGetBySearch(OS_LOCK_MODE_GLOBAL, LOCAL_OBJID_TYPE, OS_FileSys_FindVirtMountPoint, - (void *)name, &token); - - if (return_code == OS_SUCCESS) - { - return_code = OS_FileSysStatVolume_Impl(&token, &statfs); - - OS_ObjectIdRelease(&token); - - if (return_code == OS_SUCCESS) - { - *bytes_free = (uint64)statfs.blocks_free * (uint64)statfs.block_size; - } - } - else - { - /* preserves historical error code */ - return_code = OS_FS_ERR_PATH_INVALID; - } - - return return_code; - -} /* end OS_fsBytesFree */ - -#endif /* OSAL_OMIT_DEPRECATED */ - /*---------------------------------------------------------------- * * Function: OS_FileSysStatVolume diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index cdf0fded9..9068107b9 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -98,23 +98,21 @@ void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Ad sock = OS_OBJECT_TABLE_GET(OS_stream_table, *token); - if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_NAME, Addr) != OS_SUCCESS) + if (OS_SocketAddrToString_Impl(sock->stream_name, sizeof(sock->stream_name), Addr) != OS_SUCCESS) { sock->stream_name[0] = 0; } if (OS_SocketAddrGetPort_Impl(&port, Addr) == OS_SUCCESS) { len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name)); - snprintf(&sock->stream_name[len], OS_MAX_API_NAME - len, ":%u", (unsigned int)port); + snprintf(&sock->stream_name[len], sizeof(sock->stream_name) - len, ":%u", (unsigned int)port); } - sock->stream_name[OS_MAX_API_NAME - 1] = 0; if (parent_name) { /* Append the name from the parent socket. */ len = OS_strnlen(sock->stream_name, sizeof(sock->stream_name)); snprintf(&sock->stream_name[len], sizeof(sock->stream_name) - len, "-%s", parent_name); - sock->stream_name[sizeof(sock->stream_name) - 1] = 0; } } /* end OS_CreateSocketName */ diff --git a/src/os/vxworks/src/os-impl-network.c b/src/os/vxworks/src/os-impl-network.c index 6180c1439..adfc911b0 100644 --- a/src/os/vxworks/src/os-impl-network.c +++ b/src/os/vxworks/src/os-impl-network.c @@ -85,7 +85,6 @@ int32 OS_NetworkGetID_Impl(int32 *IdBuf) else { *IdBuf = (int32)host_id; - status = OS_SUCCESS; } } diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 235413179..b390f15f2 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -399,11 +399,12 @@ int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) if (!sigismember(&inuse, signo)) { /* signal is available, stop search */ + local->assigned_signal = signo; break; } } - if (signo < SIGRTMIN || signo > SIGRTMAX) + if (local->assigned_signal == 0) { /* no available signal for timer */ OS_DEBUG("No free RT signals to use for simulated time base\n"); @@ -421,7 +422,6 @@ int32 OS_TimeBaseCreate_Impl(const OS_object_token_t *token) * Therefore, we choose the signal now, but defer calling * timer_create to the internal helper task. */ - local->assigned_signal = signo; sigaddset(&local->timer_sigset, signo); /* diff --git a/src/tests/bin-sem-test/bin-sem-test.c b/src/tests/bin-sem-test/bin-sem-test.c index 4f6b6557c..584cea5c5 100644 --- a/src/tests/bin-sem-test/bin-sem-test.c +++ b/src/tests/bin-sem-test/bin-sem-test.c @@ -68,7 +68,7 @@ int counter = 0; * * On RTEMS even a call to BinSemGetInfo has very ill effects. */ -void TimerFunction(osal_id_t timer_id) +void TimerFunction(osal_id_t local_timer_id) { int32 status; 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 54af1b7ef..0339f8054 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 @@ -64,7 +64,7 @@ int counter = 0; * * On RTEMS even a call to BinSemGetInfo has very ill effects. */ -void TimerFunction(osal_id_t timer_id) +void TimerFunction(osal_id_t local_timer_id) { int32 status; diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index 891bcb6d8..ef2dfb3ab 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -43,6 +43,7 @@ OS_SockAddr_t p1_addr; OS_SockAddr_t p2_addr; OS_SockAddr_t s_addr; OS_SockAddr_t c_addr; +bool networkImplemented = true; /***************************************************************************** * @@ -63,128 +64,136 @@ void TestDatagramNetworkApi_Setup(void) p1_socket_id = OS_OBJECT_ID_UNDEFINED; actual = OS_SocketOpen(&p1_socket_id, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(p1_socket_id), "p1_socket_id (%lu) != 0", OS_ObjectIdToInteger(p1_socket_id)); - - /* Initialize peer1 address */ - actual = OS_SocketAddrInit(&p1_addr, OS_SocketDomain_INET); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - - /* Set peer1 port */ - actual = OS_SocketAddrSetPort(&p1_addr, 9999); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - - /* Set peer1 address */ - actual = OS_SocketAddrFromString(&p1_addr, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - /* Bind peer1 socket to address */ - actual = OS_SocketBind(p1_socket_id, &p1_addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); - - /* Open a peer2 socket */ - expected = OS_SUCCESS; - p2_socket_id = OS_OBJECT_ID_UNDEFINED; - - actual = OS_SocketOpen(&p2_socket_id, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(p2_socket_id), "p2_socket_id (%lu) != 0", OS_ObjectIdToInteger(p2_socket_id)); - - /* Initialize peer2 address */ - actual = OS_SocketAddrInit(&p2_addr, OS_SocketDomain_INET); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - - /* Set peer2 port */ - actual = OS_SocketAddrSetPort(&p2_addr, 9998); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - - /* Set peer2 address */ - actual = OS_SocketAddrFromString(&p2_addr, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - /* Bind peer2 socket to address */ - actual = OS_SocketBind(p2_socket_id, &p2_addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); - - /* - * Test for invalid and other nominal input parameters - * to the network functions being called above - */ - - /* OS_SocketOpen */ - actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM); - if (actual == OS_ERR_NOT_IMPLEMENTED) - { - UtPrintf("INET6 not supported\n"); - } - else - { - UtAssert_True(actual == OS_SUCCESS, "OS_SocketOpen() (%ld) Passed", (long)actual); - } - OS_close(socket_id); - - expected = OS_INVALID_POINTER; - actual = OS_SocketOpen(NULL, OS_SocketDomain_INVALID, OS_SocketType_INVALID); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_NOT_IMPLEMENTED; - actual = OS_SocketOpen(&socket_id, OS_SocketDomain_MAX, OS_SocketType_MAX); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); - - /* OS_SocketAddrInit */ - actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6); - if (actual == OS_ERR_NOT_IMPLEMENTED) - { - UtPrintf("INET6 not supported\n"); - } - else - { - UtAssert_True(actual == OS_SUCCESS, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - } - - actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6); if (actual == OS_ERR_NOT_IMPLEMENTED) { - UtPrintf("INET6 not supported\n"); + networkImplemented = false; } else { - UtAssert_True(actual == OS_INVALID_POINTER, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(p1_socket_id), "p1_socket_id (%lu) != 0", OS_ObjectIdToInteger(p1_socket_id)); + + /* Initialize peer1 address */ + actual = OS_SocketAddrInit(&p1_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer1 port */ + actual = OS_SocketAddrSetPort(&p1_addr, 9999); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer1 address */ + actual = OS_SocketAddrFromString(&p1_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind peer1 socket to address */ + actual = OS_SocketBind(p1_socket_id, &p1_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + /* Open a peer2 socket */ + expected = OS_SUCCESS; + p2_socket_id = OS_OBJECT_ID_UNDEFINED; + + actual = OS_SocketOpen(&p2_socket_id, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(p2_socket_id), "p2_socket_id (%lu) != 0", OS_ObjectIdToInteger(p2_socket_id)); + + /* Initialize peer2 address */ + actual = OS_SocketAddrInit(&p2_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer2 port */ + actual = OS_SocketAddrSetPort(&p2_addr, 9998); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set peer2 address */ + actual = OS_SocketAddrFromString(&p2_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind peer2 socket to address */ + actual = OS_SocketBind(p2_socket_id, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Test for invalid and other nominal input parameters + * to the network functions being called above + */ + + /* OS_SocketOpen */ + actual = OS_SocketOpen(&socket_id, OS_SocketDomain_INET6, OS_SocketType_DATAGRAM); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketOpen() (%ld) Passed", (long)actual); + } + OS_close(socket_id); + + expected = OS_INVALID_POINTER; + actual = OS_SocketOpen(NULL, OS_SocketDomain_INVALID, OS_SocketType_INVALID); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_NOT_IMPLEMENTED; + actual = OS_SocketOpen(&socket_id, OS_SocketDomain_MAX, OS_SocketType_MAX); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); + + /* OS_SocketAddrInit */ + actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INET6); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_SUCCESS, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + } + + actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INET6); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + UtPrintf("INET6 not supported\n"); + } + else + { + UtAssert_True(actual == OS_INVALID_POINTER, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", + (long)actual); + } + + expected = OS_ERR_NOT_IMPLEMENTED; + actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrSetPort */ + expected = OS_ERR_BAD_ADDRESS; + actual = OS_SocketAddrSetPort(&addr, 0xFFFF); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_ERR_BAD_ADDRESS", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrSetPort(NULL, 1234); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrFromString */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrFromString(NULL, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* OS_SocketBind */ + expected = OS_ERR_INVALID_ID; + socket_id = OS_ObjectIdFromInteger(1); + actual = OS_SocketBind(socket_id, &addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_STATE; + memset(&inv_addr, 0, sizeof(inv_addr)); + actual = OS_SocketBind(p2_socket_id, &inv_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); } - expected = OS_ERR_NOT_IMPLEMENTED; - actual = OS_SocketAddrInit(&addr, OS_SocketDomain_INVALID); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_ERR_NOT_IMPLEMENTED", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrInit(NULL, OS_SocketDomain_INVALID); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketAddrSetPort */ - expected = OS_ERR_BAD_ADDRESS; - actual = OS_SocketAddrSetPort(&addr, 0xFFFF); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_ERR_BAD_ADDRESS", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrSetPort(NULL, 1234); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketAddrFromString */ - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrFromString(NULL, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - /* OS_SocketBind */ - expected = OS_ERR_INVALID_ID; - socket_id = OS_ObjectIdFromInteger(1); - actual = OS_SocketBind(socket_id, &addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - expected = OS_ERR_INCORRECT_OBJ_STATE; - memset(&inv_addr, 0, sizeof(inv_addr)); - actual = OS_SocketBind(p2_socket_id, &inv_addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - } /* end TestDatagramNetworkApi_Setup */ /***************************************************************************** @@ -194,175 +203,183 @@ void TestDatagramNetworkApi_Setup(void) *****************************************************************************/ void TestDatagramNetworkApi(void) { - char AddrBuffer1[32]; - char AddrBuffer2[32]; - char AddrBuffer3[32]; - char AddrBuffer4[32]; - uint32 Buf1 = 111; - uint32 Buf2 = 000; - uint32 Buf3 = 222; - uint32 Buf4 = 000; - osal_id_t objid; - uint16 PortNum; - OS_socket_prop_t prop; - OS_SockAddr_t l_addr; - int32 expected; - int32 actual; - - /* - * Send data from peer1 to peer2 and verify - */ - - /* Send data from peer1 to peer2 */ - expected = sizeof(Buf1); - actual = OS_SocketSendTo(p1_socket_id, &Buf1, sizeof(Buf1), &p2_addr); - UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); - - /* Recieve data from peer1 to peer2 */ - expected = sizeof(Buf2); - actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, sizeof(Buf2), &l_addr, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf2) (%ld) == 1", (long)actual); - UtAssert_True(Buf1 == Buf2, "Buf1 (%ld) == Buf2 (%ld)", (long)Buf1, (long)Buf2); - - /* Convert addresses to string and verify data is being sent from the correct address */ - expected = OS_SUCCESS; - - actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), &p1_addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrToString(AddrBuffer2, sizeof(AddrBuffer2), &l_addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); - - UtAssert_True(strcmp(AddrBuffer1, AddrBuffer2) == 0, "AddrBuffer1 (%s) == AddrBuffer2 (%s)", AddrBuffer1, - AddrBuffer2); - - /* - * Send data from peer2 to peer1 and verify - */ - - /* Send data from peer2 to peer1 */ - expected = sizeof(Buf3); - actual = OS_SocketSendTo(p2_socket_id, &Buf3, sizeof(Buf3), &p1_addr); - UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); - - /* Recieve data from peer2 to peer1 */ - expected = sizeof(Buf4); - actual = OS_SocketRecvFrom(p1_socket_id, &Buf4, sizeof(Buf4), &l_addr, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf3) (%ld) == 1", (long)actual); - UtAssert_True(Buf3 == Buf4, "Buf3 (%ld) == Buf4 (%ld)", (long)Buf3, (long)Buf4); - - /* Convert addresses to string and verify data is being sent from the correct address */ - expected = OS_SUCCESS; - - actual = OS_SocketAddrToString(AddrBuffer3, sizeof(AddrBuffer3), &p2_addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_SocketAddrToString(AddrBuffer4, sizeof(AddrBuffer4), &l_addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); - - UtAssert_True(strcmp(AddrBuffer3, AddrBuffer4) == 0, "AddrBuffer3 (%s) == AddrBuffer4 (%s)", AddrBuffer3, - AddrBuffer4); - - /* Get port from incoming address and verify */ - actual = OS_SocketAddrGetPort(&PortNum, &p2_addr); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(PortNum == 9998, "PortNum (%ld) == 9998", (long)actual); - - /* Get socket info and verify */ - actual = OS_SocketGetInfo(p1_socket_id, &prop); - UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(!OS_ObjectIdDefined(prop.creator), "prop.creator (%lu) == 0", OS_ObjectIdToInteger(prop.creator)); - UtAssert_True(strcmp(prop.name, "127.0.0.1:9999") == 0, "prop.name (%s) == 127.0.0.1:9999", prop.name); - - actual = OS_SocketGetIdByName(&objid, "127.0.0.1:9999"); - UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdEqual(objid, p1_socket_id), "objid (%lu) == p1_socket_id", OS_ObjectIdToInteger(objid)); - - /* - * Test for invalid input parameters - * to the network functions being called above - */ - - /* OS_SocketSendTo */ - expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(0), NULL); - UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(1), &p2_addr); - UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_INVALID_ID; - objid = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketSendTo(objid, &Buf1, sizeof(Buf1), &p2_addr); - UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - /* OS_SocketRecvFrom */ - expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(1), NULL, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(0), NULL, 0); - UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_INVALID_ID; - objid = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketRecvFrom(objid, &Buf2, sizeof(Buf2), &l_addr, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - expected = OS_ERR_INVALID_SIZE; - actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), &l_addr, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); - - expected = OS_ERR_INVALID_SIZE; - actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), NULL, 100); - UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); - - /* OS_SocketAddrToString */ - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), NULL); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), NULL); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), &p2_addr); - UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketAddrGetPort */ - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrGetPort(NULL, NULL); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrGetPort(NULL, &l_addr); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAddrGetPort(&PortNum, NULL); - UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketGetIdByName */ - expected = OS_INVALID_POINTER; - actual = OS_SocketGetIdByName(NULL, NULL); - UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_NAME_NOT_FOUND; - actual = OS_SocketGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); - - /* OS_SocketGetInfo */ - expected = OS_INVALID_POINTER; - actual = OS_SocketGetInfo(p2_socket_id, NULL); - UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_INVALID_ID; - objid = OS_OBJECT_ID_UNDEFINED; - actual = OS_SocketGetInfo(objid, &prop); - UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_ERR_INVALID_ID", (long)actual); + if (networkImplemented) + { + char AddrBuffer1[32]; + char AddrBuffer2[32]; + char AddrBuffer3[32]; + char AddrBuffer4[32]; + uint32 Buf1 = 111; + uint32 Buf2 = 000; + uint32 Buf3 = 222; + uint32 Buf4 = 000; + osal_id_t objid; + uint16 PortNum; + OS_socket_prop_t prop; + OS_SockAddr_t l_addr; + int32 expected; + int32 actual; + + /* + * Send data from peer1 to peer2 and verify + */ + + /* Send data from peer1 to peer2 */ + expected = sizeof(Buf1); + actual = OS_SocketSendTo(p1_socket_id, &Buf1, sizeof(Buf1), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); + + /* Recieve data from peer1 to peer2 */ + expected = sizeof(Buf2); + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, sizeof(Buf2), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf2) (%ld) == 1", (long)actual); + UtAssert_True(Buf1 == Buf2, "Buf1 (%ld) == Buf2 (%ld)", (long)Buf1, (long)Buf2); + + /* Convert addresses to string and verify data is being sent from the correct address */ + expected = OS_SUCCESS; + + actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), &p1_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + actual = OS_SocketAddrToString(AddrBuffer2, sizeof(AddrBuffer2), &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(strcmp(AddrBuffer1, AddrBuffer2) == 0, "AddrBuffer1 (%s) == AddrBuffer2 (%s)", AddrBuffer1, + AddrBuffer2); + + /* + * Send data from peer2 to peer1 and verify + */ + + /* Send data from peer2 to peer1 */ + expected = sizeof(Buf3); + actual = OS_SocketSendTo(p2_socket_id, &Buf3, sizeof(Buf3), &p1_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() Passed. sizeof(Buf1) (%ld) == 1", (long)actual); + + /* Recieve data from peer2 to peer1 */ + expected = sizeof(Buf4); + actual = OS_SocketRecvFrom(p1_socket_id, &Buf4, sizeof(Buf4), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() Passed. sizeof(Buf3) (%ld) == 1", (long)actual); + UtAssert_True(Buf3 == Buf4, "Buf3 (%ld) == Buf4 (%ld)", (long)Buf3, (long)Buf4); + + /* Convert addresses to string and verify data is being sent from the correct address */ + expected = OS_SUCCESS; + + actual = OS_SocketAddrToString(AddrBuffer3, sizeof(AddrBuffer3), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + actual = OS_SocketAddrToString(AddrBuffer4, sizeof(AddrBuffer4), &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(strcmp(AddrBuffer3, AddrBuffer4) == 0, "AddrBuffer3 (%s) == AddrBuffer4 (%s)", AddrBuffer3, + AddrBuffer4); + + /* Get port from incoming address and verify */ + actual = OS_SocketAddrGetPort(&PortNum, &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(PortNum == 9998, "PortNum (%ld) == 9998", (long)actual); + + /* Get socket info and verify */ + actual = OS_SocketGetInfo(p1_socket_id, &prop); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(!OS_ObjectIdDefined(prop.creator), "prop.creator (%lu) == 0", OS_ObjectIdToInteger(prop.creator)); + UtAssert_True(strcmp(prop.name, "127.0.0.1:9999") == 0, "prop.name (%s) == 127.0.0.1:9999", prop.name); + + actual = OS_SocketGetIdByName(&objid, "127.0.0.1:9999"); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdEqual(objid, p1_socket_id), "objid (%lu) == p1_socket_id", + OS_ObjectIdToInteger(objid)); + + /* + * Test for invalid input parameters + * to the network functions being called above + */ + + /* OS_SocketSendTo */ + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(0), NULL); + UtAssert_True(actual == expected, "OS_SocketSendTo(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketSendTo(p1_socket_id, NULL, OSAL_SIZE_C(1), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + objid = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_SocketSendTo(objid, &Buf1, sizeof(Buf1), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketSendTo() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + /* OS_SocketRecvFrom */ + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(1), NULL, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketRecvFrom(p2_socket_id, NULL, OSAL_SIZE_C(0), NULL, 0); + UtAssert_True(actual == expected, "OS_SocketRecvFrom(NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + objid = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_SocketRecvFrom(objid, &Buf2, sizeof(Buf2), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), &l_addr, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + + expected = OS_ERR_INVALID_SIZE; + actual = OS_SocketRecvFrom(p2_socket_id, &Buf2, OSAL_SIZE_C(0), NULL, 100); + UtAssert_True(actual == expected, "OS_SocketRecvFrom() (%ld) == OS_ERR_INVALID_SIZE", (long)actual); + + /* OS_SocketAddrToString */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), NULL); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(AddrBuffer1, sizeof(AddrBuffer1), NULL); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrToString(NULL, OSAL_SIZE_C(0), &p2_addr); + UtAssert_True(actual == expected, "OS_SocketAddrToString() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketAddrGetPort */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(NULL, NULL); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(NULL, &l_addr); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAddrGetPort(&PortNum, NULL); + UtAssert_True(actual == expected, "OS_SocketAddrGetPort() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketGetIdByName */ + expected = OS_INVALID_POINTER; + actual = OS_SocketGetIdByName(NULL, NULL); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_NAME_NOT_FOUND; + actual = OS_SocketGetIdByName(&objid, "NF"); + UtAssert_True(actual == expected, "OS_SocketGetIdByName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + + /* OS_SocketGetInfo */ + expected = OS_INVALID_POINTER; + actual = OS_SocketGetInfo(p2_socket_id, NULL); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INVALID_ID; + objid = OS_OBJECT_ID_UNDEFINED; + actual = OS_SocketGetInfo(objid, &prop); + UtAssert_True(actual == expected, "OS_SocketGetInfo() (%ld) == OS_ERR_INVALID_ID", (long)actual); + } + else + { + UtAssert_Type(NA, false, "Network API not implemented"); + } } /* end TestDatagramNetworkApi */ @@ -447,170 +464,178 @@ void TestStreamNetworkApi(void) s_socket_id = OS_OBJECT_ID_UNDEFINED; expected = OS_SUCCESS; actual = OS_SocketOpen(&s_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(s_socket_id), "s_socket_id (%lu) != 0", OS_ObjectIdToInteger(s_socket_id)); - - /* Initialize server address */ - actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - - /* Set server port */ - actual = OS_SocketAddrSetPort(&s_addr, 9997); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - - /* Set server address */ - actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - /* Bind server socket to server address */ - actual = OS_SocketBind(s_socket_id, &s_addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); - - /* - * Set up a client - */ - - /* Open a client socket */ - expected = OS_SUCCESS; - c_socket_id = OS_OBJECT_ID_UNDEFINED; - - actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(c_socket_id), "c_socket_id (%lu) != 0", OS_ObjectIdToInteger(c_socket_id)); - - /* Initialize client address */ - actual = OS_SocketAddrInit(&c_addr, OS_SocketDomain_INET); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - - /* Set client port */ - actual = OS_SocketAddrSetPort(&c_addr, 9996); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - - /* Set client address */ - actual = OS_SocketAddrFromString(&c_addr, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - - /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection - */ - - /* Create a server task/thread */ - status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - /* - * Test for invalid input parameters - */ - - /* OS_TimedRead */ - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_TimedRead(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_INVALID_POINTER; - actual = OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_ERROR_TIMEOUT; - actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - /* OS_TimedWrite */ - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_TimedWrite(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - expected = OS_INVALID_POINTER; - actual = OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - /* OS_SocketAccept */ - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, NULL, NULL, 0); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, NULL, &temp_addr, 10); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_SocketAccept(s_socket_id, &temp_id, NULL, 10); - UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); - - /* OS_SocketConnect */ - expected = OS_INVALID_POINTER; - actual = OS_SocketConnect(c_socket_id, NULL, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_INCORRECT_OBJ_STATE; - actual = OS_SocketConnect(c_socket_id, &s_addr, 0); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); - - expected = OS_ERR_INVALID_ID; - temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); - actual = OS_SocketConnect(temp_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - /* - * Once connection is made between - * server and client, transfer data - */ - - /* Send data to server to be transformed and sent back */ - strcpy(Buf_send_c, "xyz"); - expected = sizeof(Buf_send_c); - actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); - UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); - - /* Recieve back transformed data from server*/ - expected = sizeof(Buf_expec_trans); - strcpy(Buf_expec_trans, "uvwxyz"); - - actual = OS_TimedRead(c_socket_id, Buf_rcv_trans, sizeof(Buf_rcv_trans), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - UtAssert_True(strcmp(Buf_rcv_trans, Buf_expec_trans) == 0, "Buf_rcv_trans (%s) == Buf_expected (%s)", Buf_rcv_trans, - Buf_expec_trans); - - /* Recieve all 256 chars from server one at a time */ - expected = sizeof(Buf_each_char_rcv); - actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - /* Verify all 256 chars received */ - for (iter = 0; iter < 256; iter++) + if (actual == OS_ERR_NOT_IMPLEMENTED) { - Buf_each_expected[iter] = iter; + UtAssert_Type(NA, false, "Network API not implemented"); } - - UtAssert_True(memcmp(Buf_each_expected, Buf_each_char_rcv, sizeof(Buf_each_expected)) == 0, "buffer content match"); - - /* Once connection socket is closed, verify that no data is recieved */ - expected = 0; - actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); - UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); - - /* - * NOTE: Tests for invalid and other nominal input parameters - * to some of the network functions being called here are already - * tested in TestDatagramNetworkApi_Setup() - */ - - /* Looping delay in parent task to wait for child task to exit */ - loopcnt = 0; - while ((OS_TaskGetInfo(s_task_id, &taskprop) == OS_SUCCESS) && (loopcnt < UT_EXIT_LOOP_MAX)) + else { - OS_TaskDelay(10); - loopcnt++; + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(s_socket_id), "s_socket_id (%lu) != 0", OS_ObjectIdToInteger(s_socket_id)); + + /* Initialize server address */ + actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server port */ + actual = OS_SocketAddrSetPort(&s_addr, 9997); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set server address */ + actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* Bind server socket to server address */ + actual = OS_SocketBind(s_socket_id, &s_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Set up a client + */ + + /* Open a client socket */ + expected = OS_SUCCESS; + c_socket_id = OS_OBJECT_ID_UNDEFINED; + + actual = OS_SocketOpen(&c_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(c_socket_id), "c_socket_id (%lu) != 0", OS_ObjectIdToInteger(c_socket_id)); + + /* Initialize client address */ + actual = OS_SocketAddrInit(&c_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client port */ + actual = OS_SocketAddrSetPort(&c_addr, 9996); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + + /* Set client address */ + actual = OS_SocketAddrFromString(&c_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "Server", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + /* + * Test for invalid input parameters + */ + + /* OS_TimedRead */ + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_TimedRead(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_ERROR_TIMEOUT; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + /* OS_TimedWrite */ + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_TimedWrite(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + expected = OS_INVALID_POINTER; + actual = OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + /* OS_SocketAccept */ + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, NULL, NULL, 0); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, NULL, &temp_addr, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_INVALID_POINTER; + actual = OS_SocketAccept(s_socket_id, &temp_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketAccept() (%ld) == OS_INVALID_POINTER", (long)actual); + + /* OS_SocketConnect */ + expected = OS_INVALID_POINTER; + actual = OS_SocketConnect(c_socket_id, NULL, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_INVALID_POINTER", (long)actual); + + expected = OS_ERR_INCORRECT_OBJ_STATE; + actual = OS_SocketConnect(c_socket_id, &s_addr, 0); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INCORRECT_OBJ_STATE", (long)actual); + + expected = OS_ERR_INVALID_ID; + temp_id = OS_ObjectIdFromInteger(0xFFFFFFFF); + actual = OS_SocketConnect(temp_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_ERR_INVALID_ID", (long)actual); + + /* + * Once connection is made between + * server and client, transfer data + */ + + /* Send data to server to be transformed and sent back */ + strcpy(Buf_send_c, "xyz"); + expected = sizeof(Buf_send_c); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + UtAssert_True(actual == expected, "OS_TimedWrite() (%ld) == %ld", (long)actual, (long)expected); + + /* Recieve back transformed data from server*/ + expected = sizeof(Buf_expec_trans); + strcpy(Buf_expec_trans, "uvwxyz"); + + actual = OS_TimedRead(c_socket_id, Buf_rcv_trans, sizeof(Buf_rcv_trans), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + UtAssert_True(strcmp(Buf_rcv_trans, Buf_expec_trans) == 0, "Buf_rcv_trans (%s) == Buf_expected (%s)", + Buf_rcv_trans, Buf_expec_trans); + + /* Recieve all 256 chars from server one at a time */ + expected = sizeof(Buf_each_char_rcv); + actual = OS_TimedRead(c_socket_id, Buf_each_char_rcv, sizeof(Buf_each_char_rcv), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + /* Verify all 256 chars received */ + for (iter = 0; iter < 256; iter++) + { + Buf_each_expected[iter] = iter; + } + + UtAssert_True(memcmp(Buf_each_expected, Buf_each_char_rcv, sizeof(Buf_each_expected)) == 0, + "buffer content match"); + + /* Once connection socket is closed, verify that no data is recieved */ + expected = 0; + actual = OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 10); + UtAssert_True(actual == expected, "OS_TimedRead() (%ld) == %ld", (long)actual, (long)expected); + + /* + * NOTE: Tests for invalid and other nominal input parameters + * to some of the network functions being called here are already + * tested in TestDatagramNetworkApi_Setup() + */ + + /* Looping delay in parent task to wait for child task to exit */ + loopcnt = 0; + while ((OS_TaskGetInfo(s_task_id, &taskprop) == OS_SUCCESS) && (loopcnt < UT_EXIT_LOOP_MAX)) + { + OS_TaskDelay(10); + loopcnt++; + } + UtAssert_True(loopcnt < UT_EXIT_LOOP_MAX, "Task exited after %ld iterations", (long)loopcnt); } - UtAssert_True(loopcnt < UT_EXIT_LOOP_MAX, "Task exited after %ld iterations", (long)loopcnt); } /* end TestStreamNetworkApi */ diff --git a/src/tests/queue-test/queue-test.c b/src/tests/queue-test/queue-test.c index 352d8e2a3..70ff31ce9 100644 --- a/src/tests/queue-test/queue-test.c +++ b/src/tests/queue-test/queue-test.c @@ -58,7 +58,7 @@ uint32 timer_start = 10000; uint32 timer_interval = 100000; /* 1000 = 1000 hz, 10000 == 100 hz */ uint32 timer_accuracy; -void TimerFunction(osal_id_t timer_id) +void TimerFunction(osal_id_t local_timer_id) { timer_counter++; } diff --git a/src/tests/select-test/select-test.c b/src/tests/select-test/select-test.c index c9d773a55..7b19ea2de 100644 --- a/src/tests/select-test/select-test.c +++ b/src/tests/select-test/select-test.c @@ -49,6 +49,7 @@ OS_SockAddr_t s2_addr; OS_SockAddr_t c_addr; OS_SockAddr_t c2_addr; osal_id_t bin_sem_id; +bool networkImplemented = true; #define OS_TEST_SELECT_FILENAME "/drive0/select_test.txt" @@ -93,24 +94,31 @@ void Setup_Server(void) s_socket_id = OS_OBJECT_ID_UNDEFINED; expected = OS_SUCCESS; actual = OS_SocketOpen(&s_socket_id, OS_SocketDomain_INET, OS_SocketType_STREAM); - UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(OS_ObjectIdDefined(s_socket_id), "s_socket_id (%lu) != 0", OS_ObjectIdToInteger(s_socket_id)); + if (actual == OS_ERR_NOT_IMPLEMENTED) + { + networkImplemented = false; + } + else + { + UtAssert_True(actual == expected, "OS_SocketOpen() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(OS_ObjectIdDefined(s_socket_id), "s_socket_id (%lu) != 0", OS_ObjectIdToInteger(s_socket_id)); - /* Initialize server address */ - actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); - UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); + /* Initialize server address */ + actual = OS_SocketAddrInit(&s_addr, OS_SocketDomain_INET); + UtAssert_True(actual == expected, "OS_SocketAddrInit() (%ld) == OS_SUCCESS", (long)actual); - /* Set server port */ - actual = OS_SocketAddrSetPort(&s_addr, 9994); - UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); + /* Set server port */ + actual = OS_SocketAddrSetPort(&s_addr, 9994); + UtAssert_True(actual == expected, "OS_SocketAddrSetPort() (%ld) == OS_SUCCESS", (long)actual); - /* Set server address */ - actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); - UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); + /* Set server address */ + actual = OS_SocketAddrFromString(&s_addr, "127.0.0.1"); + UtAssert_True(actual == expected, "OS_SocketAddrFromString() (%ld) == OS_SUCCESS", (long)actual); - /* Bind server socket to server address */ - actual = OS_SocketBind(s_socket_id, &s_addr); - UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + /* Bind server socket to server address */ + actual = OS_SocketBind(s_socket_id, &s_addr); + UtAssert_True(actual == expected, "OS_SocketBind() (%ld) == OS_SUCCESS", (long)actual); + } } void Setup_Client(void) @@ -244,261 +252,303 @@ void Server_Fn2(void) void Setup_Single(void) { Setup_Server(); - Setup_Client(); - BinSemSetup(); + if (networkImplemented) + { + Setup_Client(); + BinSemSetup(); + } } void Setup_Multi(void) { Setup_Single(); - Setup_Server2(); - Setup_Client2(); + if (networkImplemented) + { + Setup_Server2(); + Setup_Client2(); + } } void Teardown_Single(void) { - OS_close(c_socket_id); - OS_BinSemDelete(bin_sem_id); + if (networkImplemented) + { + OS_close(c_socket_id); + OS_BinSemDelete(bin_sem_id); + } } void Teardown_Multi(void) { - // Server 1 is intentionaly left waiting so we close it out here. - OS_close(s_socket_id); - OS_TaskDelete(s_task_id); + if (networkImplemented) + { + // Server 1 is intentionaly left waiting so we close it out here. + OS_close(s_socket_id); + OS_TaskDelete(s_task_id); - OS_close(c2_socket_id); - Teardown_Single(); + OS_close(c2_socket_id); + Teardown_Single(); + } } void TestSelectSingleRead(void) { - /* - * Test Case For: - * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); - */ - int32 expected = OS_SUCCESS; - int32 actual; - - /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection - */ - - /* Create a server task/thread */ - int32 status = OS_TaskCreate(&s_task_id, "ServerSingleRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, - OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - uint32 StateFlags; - expected = OS_ERROR_TIMEOUT; - StateFlags = OS_STREAM_STATE_READABLE; - actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); - UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); - - status = OS_BinSemGive(bin_sem_id); - - expected = OS_SUCCESS; - StateFlags = OS_STREAM_STATE_READABLE; - actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); - - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", - (unsigned int)StateFlags); -} - -void TestSelectMultipleRead(void) -{ - /* - * Test Case For: - * int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); - */ - OS_FdSet ReadSet; - OS_FdSet WriteSet; - int32 expected = OS_SUCCESS; - int32 actual; - int32 status; - - OS_SelectFdZero(&ReadSet); - OS_SelectFdZero(&WriteSet); - - /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection - */ - - /* Create a server task/thread */ - status = OS_TaskCreate(&s_task_id, "ServerMultiRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - status = OS_TaskCreate(&s2_task_id, "ServerMultiRead2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - OS_SelectFdAdd(&ReadSet, c_socket_id); - OS_SelectFdAdd(&ReadSet, c2_socket_id); - - UtAssert_True(OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); - UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); - - actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); - - UtAssert_True(!OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); - UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); -} - -void TestSelectSingleWrite(void) -{ - /* - * Test Case For: - * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); - */ - - int32 actual; - uint32 StateFlags; - int32 expected = OS_SUCCESS; - int count = 0; - char Buf_send_c[16834] = {0}; - - /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection - */ - - /* Create a server task/thread */ - int32 status = OS_TaskCreate(&s_task_id, "ServerSingleWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, - OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + if (networkImplemented) { - strcpy(Buf_send_c, "16 KB buffer filler"); - actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); - - StateFlags = OS_STREAM_STATE_WRITABLE; + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + int32 expected = OS_SUCCESS; + int32 actual; + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + int32 status = OS_TaskCreate(&s_task_id, "ServerSingleRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + uint32 StateFlags; + expected = OS_ERROR_TIMEOUT; + StateFlags = OS_STREAM_STATE_READABLE; actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); - count++; - } - - status = OS_BinSemGive(bin_sem_id); - - if (count >= MAX_BUFFER_LOOP) - { - UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", - "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); - } - else - { - expected = OS_ERROR_TIMEOUT; /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + status = OS_BinSemGive(bin_sem_id); + expected = OS_SUCCESS; - StateFlags = OS_STREAM_STATE_WRITABLE; + StateFlags = OS_STREAM_STATE_READABLE; actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); /* Verify Outputs */ UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + UtAssert_True(StateFlags == OS_STREAM_STATE_READABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_READABLE", (unsigned int)StateFlags); } + else + { + UtAssert_Type(NA, false, "Network API not implemented"); + } } -void TestSelectMultipleWrite(void) +void TestSelectMultipleRead(void) { - /* - * Test Case For: - * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); - */ - OS_FdSet ReadSet; - OS_FdSet WriteSet; - int32 expected = OS_SUCCESS; - int32 actual; - int32 status; - uint32 StateFlags; - int count = 0; - char Buf_send_c[16834] = {0}; - - OS_SelectFdZero(&ReadSet); - OS_SelectFdZero(&WriteSet); - - /* - * Create a server thread, and connect client from - * this thread to server thread and verify connection - */ - - /* Create a server task/thread */ - status = OS_TaskCreate(&s_task_id, "ServerMultiWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c_socket_id, &s_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - status = OS_TaskCreate(&s2_task_id, "ServerMultiWrite2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), - OSAL_PRIORITY_C(50), 0); - UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); - - /* Connect to a server */ - actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); - UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); - - OS_SelectFdAdd(&WriteSet, c_socket_id); - OS_SelectFdAdd(&WriteSet, c2_socket_id); - - UtAssert_True(OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); - UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); - - while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + if (networkImplemented) { - strcpy(Buf_send_c, "16 KB buffer filler"); - actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + /* + * Test Case For: + * int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); + */ + OS_FdSet ReadSet; + OS_FdSet WriteSet; + int32 expected = OS_SUCCESS; + int32 actual; + int32 status; + + OS_SelectFdZero(&ReadSet); + OS_SelectFdZero(&WriteSet); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "ServerMultiRead", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + status = OS_TaskCreate(&s2_task_id, "ServerMultiRead2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + OS_SelectFdAdd(&ReadSet, c_socket_id); + OS_SelectFdAdd(&ReadSet, c2_socket_id); + + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); - StateFlags = OS_STREAM_STATE_WRITABLE; - actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); - count++; + UtAssert_True(!OS_SelectFdIsSet(&ReadSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); + UtAssert_True(OS_SelectFdIsSet(&ReadSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); } + else + { + UtAssert_Type(NA, false, "Network API not implemented"); + } +} - if (count >= MAX_BUFFER_LOOP) +void TestSelectSingleWrite(void) +{ + if (networkImplemented) { - UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", - "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + + int32 actual; + uint32 StateFlags; + int32 expected = OS_SUCCESS; + int count = 0; + char Buf_send_c[16834] = {0}; + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + int32 status = OS_TaskCreate(&s_task_id, "ServerSingleWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + { + strcpy(Buf_send_c, "16 KB buffer filler"); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + count++; + } + + status = OS_BinSemGive(bin_sem_id); + + if (count >= MAX_BUFFER_LOOP) + { + UtAssertEx( + false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", + "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); + } + else + { + expected = OS_ERROR_TIMEOUT; + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_ERROR_TIMEOUT", (long)actual); + UtAssert_True(StateFlags == 0, "OS_SelectSingle() (0x%x) == None", (unsigned int)StateFlags); + + expected = OS_SUCCESS; + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectSingle() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(StateFlags == OS_STREAM_STATE_WRITABLE, "OS_SelectSingle() (%x) == OS_STREAM_STATE_WRITABLE", + (unsigned int)StateFlags); + } } else { - actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); - /* Verify Outputs */ - UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_Type(NA, false, "Network API not implemented"); + } +} - UtAssert_True(!OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); - UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); +void TestSelectMultipleWrite(void) +{ + if (networkImplemented) + { + /* + * Test Case For: + * int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs); + */ + OS_FdSet ReadSet; + OS_FdSet WriteSet; + int32 expected = OS_SUCCESS; + int32 actual; + int32 status; + uint32 StateFlags; + int count = 0; + char Buf_send_c[16834] = {0}; + + OS_SelectFdZero(&ReadSet); + OS_SelectFdZero(&WriteSet); + + /* + * Create a server thread, and connect client from + * this thread to server thread and verify connection + */ + + /* Create a server task/thread */ + status = OS_TaskCreate(&s_task_id, "ServerMultiWrite", Server_Fn, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(16384), + OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c_socket_id, &s_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + status = OS_TaskCreate(&s2_task_id, "ServerMultiWrite2", Server_Fn2, OSAL_TASK_STACK_ALLOCATE, + OSAL_SIZE_C(16384), OSAL_PRIORITY_C(50), 0); + UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate() (%ld) == OS_SUCCESS", (long)status); + + /* Connect to a server */ + actual = OS_SocketConnect(c2_socket_id, &s2_addr, 10); + UtAssert_True(actual == expected, "OS_SocketConnect() (%ld) == OS_SUCCESS", (long)actual); + + OS_SelectFdAdd(&WriteSet, c_socket_id); + OS_SelectFdAdd(&WriteSet, c2_socket_id); + + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == true"); + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(1) == true"); + + while (actual != OS_ERROR_TIMEOUT && count < MAX_BUFFER_LOOP) + { + strcpy(Buf_send_c, "16 KB buffer filler"); + actual = OS_TimedWrite(c_socket_id, Buf_send_c, sizeof(Buf_send_c), 10); + + StateFlags = OS_STREAM_STATE_WRITABLE; + actual = OS_SelectSingle(c_socket_id, &StateFlags, 100); + + count++; + } + + if (count >= MAX_BUFFER_LOOP) + { + UtAssertEx( + false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__, "%s", + "Unable to cause OS_STREAM_STATE_WRITEABLE timeout with large looped writes, skipping verification"); + } + else + { + actual = OS_SelectMultiple(&ReadSet, &WriteSet, 100); + /* Verify Outputs */ + UtAssert_True(actual == expected, "OS_SelectMultiple() (%ld) == OS_SUCCESS", (long)actual); + + UtAssert_True(!OS_SelectFdIsSet(&WriteSet, c_socket_id), "OS_SelectFdIsSet(1) == false"); + UtAssert_True(OS_SelectFdIsSet(&WriteSet, c2_socket_id), "OS_SelectFdIsSet(2) == true"); + } + } + else + { + UtAssert_Type(NA, false, "Network API not implemented"); } } diff --git a/src/ut-stubs/osapi-utstub-file.c b/src/ut-stubs/osapi-utstub-file.c index 29a73f4c6..9fdc1f2c7 100644 --- a/src/ut-stubs/osapi-utstub-file.c +++ b/src/ut-stubs/osapi-utstub-file.c @@ -48,7 +48,7 @@ static int32 UT_GenericReadStub(const char *fname, UT_EntryKey_t fkey, void *buf int32 status; size_t CopySize; - status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF); + status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF, NULL); if (status == 0x7FFFFFFF) { @@ -86,7 +86,7 @@ static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const vo int32 status; size_t CopySize; - status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF); + status = UT_DefaultStubImpl(fname, fkey, 0x7FFFFFFF, NULL); if (status == 0x7FFFFFFF) { @@ -108,57 +108,6 @@ static int32 UT_GenericWriteStub(const char *fname, UT_EntryKey_t fkey, const vo return status; } -#ifndef OSAL_OMIT_DEPRECATED - -/***************************************************************************** - * - * Stub function for OS_creat() - * - *****************************************************************************/ -int32 OS_creat(const char *path, int32 access) -{ - UT_Stub_RegisterContext(UT_KEY(OS_creat), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_creat), access); - osal_id_t objid; - int32 status; - - status = UT_DEFAULT_IMPL(OS_creat); - - if (status == OS_SUCCESS) - { - objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); - status = OS_ObjectIdToInteger(objid); - } - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_open() - * - *****************************************************************************/ -int32 OS_open(const char *path, int32 access, uint32 mode) -{ - UT_Stub_RegisterContext(UT_KEY(OS_open), path); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_open), access); - UT_Stub_RegisterContextGenericArg(UT_KEY(OS_open), mode); - osal_id_t objid; - int32 status; - - status = UT_DEFAULT_IMPL(OS_open); - - if (status == OS_SUCCESS) - { - objid = UT_AllocStubObjId(OS_OBJECT_TYPE_OS_STREAM); - status = OS_ObjectIdToInteger(objid); - } - - return status; -} - -#endif - /***************************************************************************** * * Stub function for OS_OpenCreate() diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index 57393fc7a..38b3ebf5b 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -153,49 +153,6 @@ int32 OS_unmount(const char *mountpoint) return status; } -#ifndef OSAL_OMIT_DEPRECATED - -/***************************************************************************** - * - * Stub function for OS_fsBlocksFree() - * - *****************************************************************************/ -int32 OS_fsBlocksFree(const char *name) -{ - UT_Stub_RegisterContext(UT_KEY(OS_fsBlocksFree), name); - - int32 status; - - status = UT_DEFAULT_IMPL_RC(OS_fsBlocksFree, 100); - - return status; -} - -/***************************************************************************** - * - * Stub function for OS_fsBytesFree() - * - *****************************************************************************/ -int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) -{ - UT_Stub_RegisterContext(UT_KEY(OS_fsBytesFree), name); - UT_Stub_RegisterContext(UT_KEY(OS_fsBytesFree), bytes_free); - - int32 status; - - status = UT_DEFAULT_IMPL(OS_fsBytesFree); - - if (status == OS_SUCCESS && - UT_Stub_CopyToLocal(UT_KEY(OS_fsBytesFree), bytes_free, sizeof(*bytes_free)) < sizeof(*bytes_free)) - { - *bytes_free = 10000; - } - - return status; -} - -#endif /* OSAL_OMIT_DEPRECATED */ - /***************************************************************************** * * Stub function for OS_FileSysStatVolume() diff --git a/ut_assert/inc/utstubs.h b/ut_assert/inc/utstubs.h index ad7601218..828be7d2c 100644 --- a/ut_assert/inc/utstubs.h +++ b/ut_assert/inc/utstubs.h @@ -197,35 +197,6 @@ void UT_SetDefaultReturnValue(UT_EntryKey_t FuncKey, int32 Value); */ void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey); -#ifndef OSAL_OMIT_DEPRECATED -/** - * Enable or disable the forced failure mode for the given stub function - * - * This triggers a constant failure mode from the stub function, if implemented. - * The stub function will invoke a given failure path as defined by - * the stub implementation. - * - * A count of the number of times the failure mode is invoked will be maintained. - * - * \param FuncKey The stub function to add the return code to. - * \param Value Arbitrary failure mode value (may or may not be used by the stub) - * - * @deprecated replaced by UT_SetDefaultReturnValue - */ -void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value); - -/** - * Disable the forced failure mode for the given stub function - * - * This undoes the action of UT_SetDefaultReturnValue() - * - * \param FuncKey The stub function entry to clear. - * - * @deprecated replaced by UT_ClearDefaultReturnValue - */ -void UT_ClearForceFail(UT_EntryKey_t FuncKey); -#endif - /** * Set a Hook function for a particular call * @@ -315,7 +286,7 @@ void UT_Stub_CallOnce(void (*Func)(void)); bool UT_Stub_CheckDeferredRetcode(UT_EntryKey_t FuncKey, int32 *Retcode); /** - * Check for a forced failure mode entry for the given stub function + * Check for a default return value entry for the given stub function * * If a UT_SetDefaultReturnValue() option is in place for the given function this * will return true and increment the internal usage counter. @@ -324,7 +295,7 @@ bool UT_Stub_CheckDeferredRetcode(UT_EntryKey_t FuncKey, int32 *Retcode); * \param Value Set to the value supplied to UT_SetDefaultReturnValue() * \returns true if force fail mode is active */ -bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value); +bool UT_Stub_CheckDefaultReturnValue(UT_EntryKey_t FuncKey, int32 *Value); /** * Copies data from a test-supplied buffer to the local buffer diff --git a/ut_assert/src/utstubs.c b/ut_assert/src/utstubs.c index a4376b444..c270f4505 100644 --- a/ut_assert/src/utstubs.c +++ b/ut_assert/src/utstubs.c @@ -346,18 +346,6 @@ void UT_ClearDefaultReturnValue(UT_EntryKey_t FuncKey) } } -#ifndef OSAL_OMIT_DEPRECATED -void UT_SetForceFail(UT_EntryKey_t FuncKey, int32 Value) -{ - UT_SetDefaultReturnValue(FuncKey, Value); -} - -void UT_ClearForceFail(UT_EntryKey_t FuncKey) -{ - UT_ClearDefaultReturnValue(FuncKey); -} -#endif - bool UT_GetStubRetcodeAndCount(UT_EntryKey_t FuncKey, int32 *Retcode, int32 *Count) { UT_StubTableEntry_t *StubPtr; @@ -396,7 +384,7 @@ uint32 UT_GetStubCount(UT_EntryKey_t FuncKey) return Count; } -bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value) +bool UT_Stub_CheckDefaultReturnValue(UT_EntryKey_t FuncKey, int32 *Value) { bool Result = false; UT_StubTableEntry_t *StubPtr; @@ -404,9 +392,12 @@ bool UT_Stub_CheckForceFail(UT_EntryKey_t FuncKey, int32 *Value) StubPtr = UT_GetStubEntry(FuncKey, UT_ENTRYTYPE_FORCE_FAIL); if (StubPtr != NULL) { - /* For "force fail" entries, the count will reflect the number of times it was used */ + /* For default return value entries, the count will reflect the number of times it was used */ ++StubPtr->Data.Rc.Count; - *Value = StubPtr->Data.Rc.Value; + if (Value != NULL) + { + *Value = StubPtr->Data.Rc.Value; + } Result = true; } @@ -761,7 +752,7 @@ int32 UT_DefaultStubImplWithArgs(const char *FunctionName, UT_EntryKey_t FuncKey if (!UT_Stub_CheckDeferredRetcode(FuncKey, &Retcode)) { - if (!UT_Stub_CheckForceFail(FuncKey, &Retcode)) + if (!UT_Stub_CheckDefaultReturnValue(FuncKey, &Retcode)) { Retcode = DefaultRc; }