From 0531bcab5703bd74af2c34b8814903b9298dc0be Mon Sep 17 00:00:00 2001 From: Jake Hageman Date: Wed, 15 Sep 2021 11:15:43 -0400 Subject: [PATCH 1/6] Fix #1148, Enable symbol api test and MIR dump too large --- src/tests/symbol-api-test/symbol-api-test.c | 46 +++++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/tests/symbol-api-test/symbol-api-test.c b/src/tests/symbol-api-test/symbol-api-test.c index bfe43ea0d..9546824e3 100644 --- a/src/tests/symbol-api-test/symbol-api-test.c +++ b/src/tests/symbol-api-test/symbol-api-test.c @@ -32,7 +32,6 @@ void TestSymbolApi(void) { -#ifdef OS_INCLUDE_MODULE_LOADER int32 status; cpuaddr SymAddress; @@ -50,7 +49,11 @@ void TestSymbolApi(void) status = OS_SymbolTableDump("/ram/SymbolTable32k.dat", 32768); if (status == OS_ERR_NOT_IMPLEMENTED) { - UtAssert_NA("Module API not implemented"); + UtAssert_NA("OS_SymbolTableDump API not implemented"); + } + else if (status == OS_ERR_OUTPUT_TOO_LARGE) + { + UtAssert_MIR("32k too small for OS_SymbolTableDump"); } else { @@ -64,7 +67,11 @@ void TestSymbolApi(void) status = OS_SymbolTableDump("/ram/SymbolTable128k.dat", 131072); if (status == OS_ERR_NOT_IMPLEMENTED) { - UtAssert_NA("Module API not implemented"); + UtAssert_NA("OS_SymbolTableDump API not implemented"); + } + else if (status == OS_ERR_OUTPUT_TOO_LARGE) + { + UtAssert_MIR("128k too small for OS_SymbolTableDump"); } else { @@ -78,7 +85,11 @@ void TestSymbolApi(void) status = OS_SymbolTableDump("/ram/SymbolTable512k.dat", 524288); if (status == OS_ERR_NOT_IMPLEMENTED) { - UtAssert_NA("Module API not implemented"); + UtAssert_NA("OS_SymbolTableDump API not implemented"); + } + else if (status == OS_ERR_OUTPUT_TOO_LARGE) + { + UtAssert_MIR("512k too small for OS_SymbolTableDump"); } else { @@ -89,20 +100,29 @@ void TestSymbolApi(void) ** Test the symbol lookup */ status = OS_SymbolLookup(&SymAddress, "OS_Application_Startup"); - UtAssert_True(status == OS_SUCCESS, "OS_SymbolLookup(OS_Application_Startup) = %d, Addr = %lx", (int)status, - (unsigned long)SymAddress); + if (status == OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_NA("OS_SymbolLookup API not implemented"); + } + else + { + UtAssert_True(status == OS_SUCCESS, "OS_SymbolLookup(OS_Application_Startup) = %d, Addr = %lx", (int)status, + (unsigned long)SymAddress); + } /* ** Test a symbol lookup that does not exist */ status = OS_SymbolLookup(&SymAddress, "ShouldNotExist"); - UtAssert_True(status != OS_SUCCESS, "OS_SymbolLookup(ShouldNotExist) = %d, Addr = %lx", (int)status, - (unsigned long)SymAddress); - -#else - /* If the module loader is not present, generate an N/A test case just to indicate that the test ran */ - UtAssert_True(1, "Module loader not present"); -#endif + if (status == OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_NA("OS_SymbolLookup API not implemented"); + } + else + { + UtAssert_True(status != OS_SUCCESS, "OS_SymbolLookup(ShouldNotExist) = %d, Addr = %lx", (int)status, + (unsigned long)SymAddress); + } } /* end TestSymbolApi */ void UtTest_Setup(void) From 0f5454d017eec45f4da9ba515e8afe8406fd4bcf Mon Sep 17 00:00:00 2001 From: Jake Hageman Date: Wed, 15 Sep 2021 16:56:29 -0400 Subject: [PATCH 2/6] Fix #1148, MIR symbol name too long in symbol-api-test --- src/tests/symbol-api-test/symbol-api-test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tests/symbol-api-test/symbol-api-test.c b/src/tests/symbol-api-test/symbol-api-test.c index 9546824e3..e762dd946 100644 --- a/src/tests/symbol-api-test/symbol-api-test.c +++ b/src/tests/symbol-api-test/symbol-api-test.c @@ -55,6 +55,10 @@ void TestSymbolApi(void) { UtAssert_MIR("32k too small for OS_SymbolTableDump"); } + else if (status == OS_ERR_NAME_TOO_LONG) + { + UtAssert_MIR("OS_SymbolTableDump name to long, consider increasing OSAL_CONFIG_MAX_SYM_LEN"); + } else { UtAssert_True(status == OS_SUCCESS, "status after 32k OS_SymbolTableDump = %d", (int)status); @@ -73,6 +77,10 @@ void TestSymbolApi(void) { UtAssert_MIR("128k too small for OS_SymbolTableDump"); } + else if (status == OS_ERR_NAME_TOO_LONG) + { + UtAssert_MIR("OS_SymbolTableDump name to long, consider increasing OSAL_CONFIG_MAX_SYM_LEN"); + } else { UtAssert_True(status == OS_SUCCESS, "status after 128k OS_SymbolTableDump = %d", (int)status); @@ -91,6 +99,10 @@ void TestSymbolApi(void) { UtAssert_MIR("512k too small for OS_SymbolTableDump"); } + else if (status == OS_ERR_NAME_TOO_LONG) + { + UtAssert_MIR("OS_SymbolTableDump name to long, consider increasing OSAL_CONFIG_MAX_SYM_LEN"); + } else { UtAssert_True(status == OS_SUCCESS, "status after 512k OS_SymbolTableDump = %d", (int)status); From 6fd967c3b9ef2c9635a55c12480043b9a325f59c Mon Sep 17 00:00:00 2001 From: Jake Hageman Date: Wed, 15 Sep 2021 17:08:36 -0400 Subject: [PATCH 3/6] Fix #1151, MIR symbol too long or table to long for osloader test --- .../osloader-test/ut_osloader_symtable_test.c | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index 1a5f8bc88..d96d9fe1a 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -177,6 +177,7 @@ void UT_os_module_symbol_lookup_test() **--------------------------------------------------------------------------------*/ void UT_os_symbol_table_dump_test() { + int32 status; /* * Note that even if the functionality is not implemented, * the API still validates the input pointers (not null) and @@ -196,7 +197,25 @@ void UT_os_symbol_table_dump_test() /*-----------------------------------------------------*/ /* #3 Nominal */ - if (UT_NOMINAL_OR_NOTIMPL(OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolReal.dat", UT_SYMTABLE_SIZE_LIMIT))) + status = OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolReal.dat", UT_SYMTABLE_SIZE_LIMIT); + if (status == OS_ERR_NOT_IMPLEMENTED) + { + UtAssert_NA("OS_SymbolTableDump API not implemented"); + } + else if (status == OS_ERR_OUTPUT_TOO_LARGE) + { + UtAssert_MIR("UT_SYMTABLE_SIZE_LIMIT too small for OS_SymbolTableDump"); + } + else if (status == OS_ERR_NAME_TOO_LONG) + { + UtAssert_MIR("OSAL_CONFIG_MAX_SYM_LEN too small for OS_SymbolTableDump"); + } + else + { + UtAssert_True(status == OS_SUCCESS, "status after 128k OS_SymbolTableDump = %d", (int)status); + } + + if (status == OS_SUCCESS) { UT_RETVAL(OS_SymbolTableDump(UT_OS_GENERIC_MODULE_DIR "SymbolZero.dat", 0), OS_ERR_OUTPUT_TOO_LARGE); } From 52afadadee67bf01e5a08da9d91e864b39ef935d Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 20 Sep 2021 16:19:00 -0400 Subject: [PATCH 4/6] Fix #1154, add bsp-specific configuration flag registry Adds a simple BSP API to get/set integer flags for each resource type. All bits are platform-defined, so this can be used to store any arbitrary platform flag. Initial use case is for setting task flags on vxWorks platforms which require a certain task flag to be set. --- CMakeLists.txt | 1 + src/bsp/shared/inc/bsp-impl.h | 9 +++ src/bsp/shared/src/bsp_default_resourcecfg.c | 65 ++++++++++++++++++++ src/os/inc/osapi-bsp.h | 16 +++++ src/os/vxworks/src/os-impl-tasks.c | 3 +- src/ut-stubs/osapi-bsp-stubs.c | 29 +++++++++ 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/bsp/shared/src/bsp_default_resourcecfg.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 519183d1e..a2648e725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,7 @@ set(BSP_SRCLIST src/bsp/shared/src/bsp_default_app_run.c src/bsp/shared/src/bsp_default_app_startup.c src/bsp/shared/src/bsp_default_symtab.c + src/bsp/shared/src/bsp_default_resourcecfg.c ) # Define the external "osal_bsp" static library target diff --git a/src/bsp/shared/inc/bsp-impl.h b/src/bsp/shared/inc/bsp-impl.h index d2e7cfcbc..2604dea18 100644 --- a/src/bsp/shared/inc/bsp-impl.h +++ b/src/bsp/shared/inc/bsp-impl.h @@ -47,6 +47,7 @@ #include "osapi-common.h" #include "osapi-bsp.h" #include "osapi-error.h" +#include "osapi-idmap.h" /* * A set of simplified console control options @@ -97,6 +98,14 @@ typedef struct char ** ArgV; /* strings for boot/startup parameters */ int32 AppStatus; /* value which can be returned to the OS (0=nominal) */ osal_blockcount_t MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */ + + /* + * Configuration registry - abstract integer flags to select platform-specific options + * for each resource type. Flags are all platform-defined, and not every platform uses this + * feature. + */ + uint32 ResoureConfig[OS_OBJECT_TYPE_USER]; + } OS_BSP_GlobalData_t; /* diff --git a/src/bsp/shared/src/bsp_default_resourcecfg.c b/src/bsp/shared/src/bsp_default_resourcecfg.c new file mode 100644 index 000000000..69f0807bc --- /dev/null +++ b/src/bsp/shared/src/bsp_default_resourcecfg.c @@ -0,0 +1,65 @@ +/* + * 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: bsp_default_resourcecfg.c + * + * Purpose: + * Simple integer key/value table lookup to allow BSP-specific flags/options + * to be set for various resource types. Meanings are all platform-defined. + * + */ + +#include "osapi-idmap.h" +#include "bsp-impl.h" + +/* --------------------------------------------------------- + OS_BSP_SetResourceTypeConfig() + + Helper function to register BSP-specific options. + --------------------------------------------------------- */ +void OS_BSP_SetResourceTypeConfig(uint32 ResourceType, uint32 ConfigOptionValue) +{ + if (ResourceType < OS_OBJECT_TYPE_USER) + { + OS_BSP_Global.ResoureConfig[ResourceType] = ConfigOptionValue; + } +} + +/* --------------------------------------------------------- + OS_BSP_GetResourceTypeConfig() + + Helper function to register BSP-specific options. + --------------------------------------------------------- */ +uint32 OS_BSP_GetResourceTypeConfig(uint32 ResourceType) +{ + uint32 ConfigOptionValue; + + if (ResourceType < OS_OBJECT_TYPE_USER) + { + ConfigOptionValue = OS_BSP_Global.ResoureConfig[ResourceType]; + } + else + { + ConfigOptionValue = 0; + } + + return ConfigOptionValue; +} diff --git a/src/os/inc/osapi-bsp.h b/src/os/inc/osapi-bsp.h index 4f4c7ee18..eac7f8c03 100644 --- a/src/os/inc/osapi-bsp.h +++ b/src/os/inc/osapi-bsp.h @@ -44,6 +44,22 @@ * @{ */ +/*---------------------------------------------------------------- + Function: OS_BSP_SetResourceTypeConfig + + Purpose: Sets BSP/platform-specific flags for the given resource type + Flags and bit meanings are all platform defined. + ------------------------------------------------------------------*/ +void OS_BSP_SetResourceTypeConfig(uint32 ResourceType, uint32 ConfigOptionValue); + +/*---------------------------------------------------------------- + Function: OS_BSP_SetResourceTypeConfig + + Purpose: Gets BSP/platform-specific flags for the given resource type + Flags and bit meanings are all platform defined. + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetResourceTypeConfig(uint32 ResourceType); + /*---------------------------------------------------------------- Function: OS_BSP_GetArgC diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c index e05524f33..07dae3c5a 100644 --- a/src/os/vxworks/src/os-impl-tasks.c +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -34,6 +34,7 @@ #include "os-shared-task.h" #include "os-shared-idmap.h" #include "os-shared-timebase.h" +#include "osapi-bsp.h" #include #include @@ -132,7 +133,7 @@ int32 OS_TaskCreate_Impl(const OS_object_token_t *token, uint32 flags) /* see if the user wants floating point enabled. If * so, then se the correct option. */ - vxflags = 0; + vxflags = OS_BSP_GetResourceTypeConfig(OS_OBJECT_TYPE_OS_TASK); if (flags & OS_FP_ENABLED) { vxflags |= VX_FP_TASK; diff --git a/src/ut-stubs/osapi-bsp-stubs.c b/src/ut-stubs/osapi-bsp-stubs.c index 6e8347327..e70a7637a 100644 --- a/src/ut-stubs/osapi-bsp-stubs.c +++ b/src/ut-stubs/osapi-bsp-stubs.c @@ -55,6 +55,22 @@ char *const *OS_BSP_GetArgV(void) return UT_GenStub_GetReturnValue(OS_BSP_GetArgV, char *const *); } +/* + * ---------------------------------------------------- + * Generated stub function for OS_BSP_GetResourceTypeConfig() + * ---------------------------------------------------- + */ +uint32 OS_BSP_GetResourceTypeConfig(uint32 ResourceType) +{ + UT_GenStub_SetupReturnBuffer(OS_BSP_GetResourceTypeConfig, uint32); + + UT_GenStub_AddParam(OS_BSP_GetResourceTypeConfig, uint32, ResourceType); + + UT_GenStub_Execute(OS_BSP_GetResourceTypeConfig, Basic, NULL); + + return UT_GenStub_GetReturnValue(OS_BSP_GetResourceTypeConfig, uint32); +} + /* * ---------------------------------------------------- * Generated stub function for OS_BSP_SetExitCode() @@ -66,3 +82,16 @@ void OS_BSP_SetExitCode(int32 code) UT_GenStub_Execute(OS_BSP_SetExitCode, Basic, NULL); } + +/* + * ---------------------------------------------------- + * Generated stub function for OS_BSP_SetResourceTypeConfig() + * ---------------------------------------------------- + */ +void OS_BSP_SetResourceTypeConfig(uint32 ResourceType, uint32 ConfigOptionValue) +{ + UT_GenStub_AddParam(OS_BSP_SetResourceTypeConfig, uint32, ResourceType); + UT_GenStub_AddParam(OS_BSP_SetResourceTypeConfig, uint32, ConfigOptionValue); + + UT_GenStub_Execute(OS_BSP_SetResourceTypeConfig, Basic, NULL); +} From 009abc1303cd5350aa3c99ad233185de84a71d74 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 20 Sep 2021 20:40:12 -0400 Subject: [PATCH 5/6] Fix #1153, add os-specifc socket flag function Adds the capability for the bsd sockets implementation to use a function provided by the OS layer to set the socket flags. This allows VxWorks to have an alternative implementation that uses ioctl rather than fcntl to set the flags. --- src/os/portable/os-impl-bsd-sockets.c | 93 ++++++++++--------- src/os/shared/inc/os-shared-sockets.h | 1 + src/os/vxworks/CMakeLists.txt | 1 + src/os/vxworks/inc/os-impl-sockets.h | 23 ++--- src/os/vxworks/src/os-impl-sockets.c | 64 +++++++++++++ .../portable/src/coveragetest-bsd-sockets.c | 34 +++---- .../ut-stubs/inc/OCS_ioLib.h | 1 + .../ut-stubs/override_inc/ioLib.h | 1 + .../src/os-shared-sockets-impl-stubs.c | 12 +++ src/unit-test-coverage/vxworks/CMakeLists.txt | 1 + .../vxworks/adaptors/CMakeLists.txt | 1 + .../vxworks/adaptors/inc/ut-adaptor-sockets.h | 35 +++++++ .../vxworks/adaptors/src/ut-adaptor-sockets.c | 44 +++++++++ .../vxworks/src/coveragetest-sockets.c | 68 ++++++++++++++ .../vxworks/ut-stubs/CMakeLists.txt | 1 + .../src/vxworks-os-impl-sockets-stubs.c | 33 +++++++ 16 files changed, 338 insertions(+), 75 deletions(-) create mode 100644 src/os/vxworks/src/os-impl-sockets.c create mode 100644 src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-sockets.h create mode 100644 src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-sockets.c create mode 100644 src/unit-test-coverage/vxworks/src/coveragetest-sockets.c create mode 100644 src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-sockets-stubs.c diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index cb31211a6..1d8d8f4f5 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -63,6 +63,22 @@ DEFINES ****************************************************************************************/ +/* + * The OS layer may define a macro to set the proper flags on newly-opened sockets. + * If not set, then a default implementation is used, which uses fcntl() to set O_NONBLOCK + */ +#ifndef OS_IMPL_SOCKET_FLAGS +#ifdef O_NONBLOCK +#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK +#else +#define OS_IMPL_SOCKET_FLAGS 0 /* do not set any flags */ +#endif +#endif + +#ifndef OS_IMPL_SET_SOCKET_FLAGS +#define OS_IMPL_SET_SOCKET_FLAGS(tok) OS_SetSocketDefaultFlags_Impl(tok) +#endif + typedef union { char data[OS_SOCKADDR_MAX_LEN]; @@ -82,6 +98,37 @@ typedef union */ CompileTimeAssert(sizeof(OS_SockAddr_Accessor_t) == OS_SOCKADDR_MAX_LEN, SockAddrSize); +/* + * Default flags implementation: Set the O_NONBLOCK flag via fcntl(). + * An implementation can also elect custom configuration by setting + * the OS_IMPL_SET_SOCKET_FLAGS macro to point to an alternate function. + */ +void OS_SetSocketDefaultFlags_Impl(const OS_object_token_t *token) +{ + OS_impl_file_internal_record_t *impl; + int os_flags; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + + os_flags = fcntl(impl->fd, F_GETFL); + if (os_flags == -1) + { + /* No recourse if F_GETFL fails - just report the error and move on. */ + OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno)); + } + else + { + os_flags |= OS_IMPL_SOCKET_FLAGS; + if (fcntl(impl->fd, F_SETFL, os_flags) == -1) + { + /* No recourse if F_SETFL fails - just report the error and move on. */ + OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno)); + } + } + + impl->selectable = true; +} + /**************************************************************************************** Sockets API ***************************************************************************************/ @@ -160,23 +207,7 @@ int32 OS_SocketOpen_Impl(const OS_object_token_t *token) * nonblock mode does improve robustness in the event that multiple tasks * attempt to accept new connections from the same server socket at the same time. */ - os_flags = fcntl(impl->fd, F_GETFL); - if (os_flags == -1) - { - /* No recourse if F_GETFL fails - just report the error and move on. */ - OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno)); - } - else - { - os_flags |= OS_IMPL_SOCKET_FLAGS; - if (fcntl(impl->fd, F_SETFL, os_flags) == -1) - { - /* No recourse if F_SETFL fails - just report the error and move on. */ - OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno)); - } - } - - impl->selectable = OS_IMPL_SOCKET_SELECTABLE; + OS_IMPL_SET_SOCKET_FLAGS(token); return OS_SUCCESS; } /* end OS_SocketOpen_Impl */ @@ -397,7 +428,6 @@ int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_ int32 return_code; uint32 operation; socklen_t addrlen; - int os_flags; OS_impl_file_internal_record_t *sock_impl; OS_impl_file_internal_record_t *conn_impl; @@ -432,32 +462,7 @@ int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_ { Addr->ActualLength = addrlen; - /* - * Set the standard options on the filehandle by default -- - * this may set it to non-blocking mode if the implementation supports it. - * any blocking would be done explicitly via the select() wrappers - * - * NOTE: The implementation still generally works without this flag set, but - * nonblock mode does improve robustness in the event that multiple tasks - * attempt to read from the same socket at the same time. - */ - os_flags = fcntl(conn_impl->fd, F_GETFL); - if (os_flags == -1) - { - /* No recourse if F_GETFL fails - just report the error and move on. */ - OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno)); - } - else - { - os_flags |= OS_IMPL_SOCKET_FLAGS; - if (fcntl(conn_impl->fd, F_SETFL, os_flags) == -1) - { - /* No recourse if F_SETFL fails - just report the error and move on. */ - OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno)); - } - } - - conn_impl->selectable = OS_IMPL_SOCKET_SELECTABLE; + OS_IMPL_SET_SOCKET_FLAGS(conn_token); } } } diff --git a/src/os/shared/inc/os-shared-sockets.h b/src/os/shared/inc/os-shared-sockets.h index 032339fa5..3d9933eab 100644 --- a/src/os/shared/inc/os-shared-sockets.h +++ b/src/os/shared/inc/os-shared-sockets.h @@ -188,5 +188,6 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum); * Not normally called outside the local unit, except during unit test */ void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name); +void OS_SetSocketDefaultFlags_Impl(const OS_object_token_t *token); #endif /* OS_SHARED_SOCKETS_H */ diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt index 912f3e74c..fb4f56c36 100644 --- a/src/os/vxworks/CMakeLists.txt +++ b/src/os/vxworks/CMakeLists.txt @@ -65,6 +65,7 @@ if (OSAL_CONFIG_INCLUDE_NETWORK) list(APPEND VXWORKS_IMPL_SRCLIST src/os-impl-network.c ../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation + src/os-impl-sockets.c # Additional vxworks-specific code to handle socket flags ) else() list(APPEND VXWORKS_IMPL_SRCLIST diff --git a/src/os/vxworks/inc/os-impl-sockets.h b/src/os/vxworks/inc/os-impl-sockets.h index bf7c716f6..6b1a05d5a 100644 --- a/src/os/vxworks/inc/os-impl-sockets.h +++ b/src/os/vxworks/inc/os-impl-sockets.h @@ -29,6 +29,7 @@ #define OS_IMPL_SOCKETS_H #include "os-impl-io.h" +#include "os-shared-globaldefs.h" #include #include @@ -37,25 +38,19 @@ #include #include #include +#include /* - * Socket descriptors should be usable with the select() API + * Override the socket flag set routine on this platform. + * This is required because some versions of VxWorks do not support + * the standard POSIX fcntl() opcodes, and must use ioctl() instead. */ -#define OS_IMPL_SOCKET_SELECTABLE true - -/* - * Use the O_NONBLOCK flag on sockets - * - * NOTE: the fcntl() F_GETFL/F_SETFL opcodes that set descriptor flags may not - * work correctly on some version of VxWorks. - * - * This flag is not strictly required, things still mostly work without it, - * but lack of this mode does introduce some potential race conditions if more - * than one task attempts to use the same descriptor handle at the same time. - */ -#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK +#define OS_IMPL_SET_SOCKET_FLAGS(impl) OS_VxWorks_SetSocketFlags_Impl(impl) /* The "in.h" header file supplied in VxWorks 6.9 is missing the "in_port_t" typedef */ typedef u_short in_port_t; +/* VxWorks-specific helper function to configure the socket flags on a connection */ +void OS_VxWorks_SetSocketFlags_Impl(const OS_object_token_t *token); + #endif /* OS_IMPL_SOCKETS_H */ diff --git a/src/os/vxworks/src/os-impl-sockets.c b/src/os/vxworks/src/os-impl-sockets.c new file mode 100644 index 000000000..5b51ecd02 --- /dev/null +++ b/src/os/vxworks/src/os-impl-sockets.c @@ -0,0 +1,64 @@ +/* + * 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 os-impl-sockets.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-vxworks.h" +#include "os-shared-idmap.h" +#include "os-impl-io.h" +#include "os-impl-sockets.h" + +/**************************************************************************************** + INITIALIZATION FUNCTION + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +void OS_VxWorks_SetSocketFlags_Impl(const OS_object_token_t *token) +{ + OS_impl_file_internal_record_t *impl; + int os_flags; + + impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token); + + /* Use ioctl/FIONBIO on this platform, rather than standard fcntl() */ + os_flags = 1; + if (ioctl(impl->fd, FIONBIO, &os_flags) == -1) + { + /* No recourse if ioctl fails - just report the error and move on. */ + OS_DEBUG("ioctl(FIONBIO): %s\n", strerror(errno)); + } + + impl->selectable = true; +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c index 7abcd2bbe..9322fa2bc 100644 --- a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c @@ -100,21 +100,34 @@ void Test_OS_SocketOpen_Impl(void) OS_stream_table[0].socket_type = OS_SocketType_STREAM; OS_stream_table[0].socket_domain = OS_SocketDomain_INET6; OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_SUCCESS); - UtAssert_True(UT_PortablePosixIOTest_Get_Selectable(token.obj_idx), "Socket is selectable"); +} + +void Test_OS_SetSocketDefaultFlags_Impl(void) +{ + OS_object_token_t token = {0}; /* Failure in fcntl() GETFL */ UT_PortablePosixIOTest_ResetImpl(token.obj_idx); UT_ResetState(UT_KEY(OCS_fcntl)); UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 1, -1); - OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_SUCCESS); + UtAssert_VOIDCALL(OS_SetSocketDefaultFlags_Impl(&token)); UtAssert_STUB_COUNT(OCS_fcntl, 1); + UtAssert_True(UT_PortablePosixIOTest_Get_Selectable(token.obj_idx), "Socket is selectable"); /* Failure in fcntl() SETFL */ UT_PortablePosixIOTest_ResetImpl(token.obj_idx); UT_ResetState(UT_KEY(OCS_fcntl)); UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 2, -1); - OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_SUCCESS); + UtAssert_VOIDCALL(OS_SetSocketDefaultFlags_Impl(&token)); + UtAssert_STUB_COUNT(OCS_fcntl, 2); + UtAssert_True(UT_PortablePosixIOTest_Get_Selectable(token.obj_idx), "Socket is selectable"); + + /* Nominal path */ + UT_PortablePosixIOTest_ResetImpl(token.obj_idx); + UT_ResetState(UT_KEY(OCS_fcntl)); + UtAssert_VOIDCALL(OS_SetSocketDefaultFlags_Impl(&token)); UtAssert_STUB_COUNT(OCS_fcntl, 2); + UtAssert_True(UT_PortablePosixIOTest_Get_Selectable(token.obj_idx), "Socket is selectable"); } void Test_OS_SocketBind_Impl(void) @@ -255,20 +268,6 @@ void Test_OS_SocketAccept_Impl(void) /* Success case */ OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); - - /* Failure in fcntl() GETFL */ - UT_PortablePosixIOTest_ResetImpl(conn_token.obj_idx); - UT_ResetState(UT_KEY(OCS_fcntl)); - UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 1, -1); - OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); - UtAssert_STUB_COUNT(OCS_fcntl, 1); - - /* Failure in fcntl() SETFL */ - UT_PortablePosixIOTest_ResetImpl(conn_token.obj_idx); - UT_ResetState(UT_KEY(OCS_fcntl)); - UT_SetDeferredRetcode(UT_KEY(OCS_fcntl), 2, -1); - OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (&sock_token, &conn_token, &addr, 0), OS_SUCCESS); - UtAssert_STUB_COUNT(OCS_fcntl, 2); } void Test_OS_SocketRecvFrom_Impl(void) @@ -484,6 +483,7 @@ void Osapi_Test_Teardown(void) {} void UtTest_Setup(void) { ADD_TEST(OS_SocketOpen_Impl); + ADD_TEST(OS_SetSocketDefaultFlags_Impl); ADD_TEST(OS_SocketBind_Impl); ADD_TEST(OS_SocketConnect_Impl); ADD_TEST(OS_SocketShutdown_Impl); diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h index f864eb8a4..43cced0db 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_ioLib.h @@ -37,6 +37,7 @@ #define OCS_FIOCHKDSK 0x1E01 #define OCS_FIOUNMOUNT 0x1E02 +#define OCS_FIONBIO 0x1E03 /* ----------------------------------------- */ /* types normally defined in ioLib.h */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h b/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h index a9ba0f0cc..2fdfe6419 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/ioLib.h @@ -37,6 +37,7 @@ #define FIOCHKDSK OCS_FIOCHKDSK #define FIOUNMOUNT OCS_FIOUNMOUNT +#define FIONBIO OCS_FIONBIO #define ioctl OCS_ioctl #endif /* OVERRIDE_IOLIB_H */ diff --git a/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c index 227fcde60..6ffd258f0 100644 --- a/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/os-shared-sockets-impl-stubs.c @@ -27,6 +27,18 @@ #include "os-shared-sockets.h" #include "utgenstub.h" +/* + * ---------------------------------------------------- + * Generated stub function for OS_SetSocketDefaultFlags_Impl() + * ---------------------------------------------------- + */ +void OS_SetSocketDefaultFlags_Impl(const OS_object_token_t *token) +{ + UT_GenStub_AddParam(OS_SetSocketDefaultFlags_Impl, const OS_object_token_t *, token); + + UT_GenStub_Execute(OS_SetSocketDefaultFlags_Impl, Basic, NULL); +} + /* * ---------------------------------------------------- * Generated stub function for OS_SocketAccept_Impl() diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index b97b2edd1..0124d3e23 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -15,6 +15,7 @@ set(VXWORKS_MODULE_LIST network queues shell + sockets symtab tasks timebase diff --git a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt index eb22c05de..b0789bdb6 100644 --- a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(ut-adaptor-${SETNAME} STATIC src/ut-adaptor-mutex.c src/ut-adaptor-queues.c src/ut-adaptor-filetable-stub.c + src/ut-adaptor-sockets.c src/ut-adaptor-symtab.c src/ut-adaptor-tasks.c src/ut-adaptor-timebase.c diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-sockets.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-sockets.h new file mode 100644 index 000000000..755fe063e --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-sockets.h @@ -0,0 +1,35 @@ +/* + * 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 + * \ingroup adaptors + * + * Declarations and prototypes for ut-adaptor-symtab + */ + +#ifndef UT_ADAPTOR_SOCKETS_H +#define UT_ADAPTOR_SOCKETS_H + +#include "common_types.h" + +void UT_SocketTest_CallVxWorksSetFlags_Impl(uint32 index); + +#endif /* UT_ADAPTOR_SOCKETS_H */ diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-sockets.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-sockets.c new file mode 100644 index 000000000..d13d0f39e --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-sockets.c @@ -0,0 +1,44 @@ +/* + * 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 ut-adaptor-sockets.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-sockets.h" + +#include "os-vxworks.h" +#include "os-shared-idmap.h" +#include "os-impl-sockets.h" + +/* + * A UT-specific wrapper function to invoke the VxWorks "SetFlag" helper + */ +void UT_SocketTest_CallVxWorksSetFlags_Impl(uint32 index) +{ + OS_object_token_t token = {.obj_idx = index}; + + OS_VxWorks_SetSocketFlags_Impl(&token); +} diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-sockets.c b/src/unit-test-coverage/vxworks/src/coveragetest-sockets.c new file mode 100644 index 000000000..f83b11db3 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-sockets.c @@ -0,0 +1,68 @@ +/* + * 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 coveragetest-no-module.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-sockets.h" + +#include "OCS_ioLib.h" + +void Test_OS_VxWorks_SetSocketFlags_Impl(void) +{ + UtAssert_VOIDCALL(UT_SocketTest_CallVxWorksSetFlags_Impl(0)); + + UT_SetDefaultReturnValue(UT_KEY(OCS_ioctl), OCS_ERROR); + UtAssert_VOIDCALL(UT_SocketTest_CallVxWorksSetFlags_Impl(0)); +} + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) {} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_SetSocketFlags_Impl); +} diff --git a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt index f19cd1b93..c24c1d8e5 100644 --- a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt @@ -8,6 +8,7 @@ add_library(ut_vxworks_impl_stubs src/vxworks-os-impl-module-stubs.c src/vxworks-os-impl-mutex-stubs.c src/vxworks-os-impl-queue-stubs.c + src/vxworks-os-impl-sockets-stubs.c src/vxworks-os-impl-task-stubs.c src/vxworks-os-impl-timer-stubs.c ) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-sockets-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-sockets-stubs.c new file mode 100644 index 000000000..0c68f6524 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-sockets-stubs.c @@ -0,0 +1,33 @@ +/* + * 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 vxworks-os-impl-socket-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include "os-shared-idmap.h" + +void OS_VxWorks_SetSocketFlags_Impl(const OS_object_token_t *token) {} From 9bac3612c61b3dfe3ed5b8ef601f8eece02d8fb3 Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:07:34 -0400 Subject: [PATCH 6/6] IC:2021-09-21, v5.1.0-rc1+dev619 --- README.md | 7 +++++++ src/os/inc/osapi-version.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f05ba709e..7d1deac5e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,13 @@ The autogenerated OSAL user's guide can be viewed at and ### Development Build: v5.1.0-rc1+dev604 - Add typecast to memchr call diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 62fe1162e..9c1ad5b6e 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -36,7 +36,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 604 +#define OS_BUILD_NUMBER 619 #define OS_BUILD_BASELINE "v5.1.0-rc1" /*