From b257683bb578c15407aabeb42e88d0f12f12ef53 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 11 Feb 2021 15:17:36 -0500 Subject: [PATCH] Fix #795, Add missing files to VxWorks coverage --- src/os/portable/os-impl-bsd-sockets.c | 38 ++++---- .../portable/src/coveragetest-bsd-sockets.c | 89 +++++++++++++++++++ .../portable/src/coveragetest-no-network.c | 63 +++++++++++++ .../portable/src/coveragetest-no-sockets.c | 73 +++++++++++++++ .../portable/src/coveragetest-no-symtab.c | 64 +++++++++++++ .../ut-stubs/CMakeLists.txt | 5 +- .../ut-stubs/inc/OCS_sys_socket.h | 35 +++++++- .../ut-stubs/inc/OCS_sys_types.h | 15 ++-- .../ut-stubs/override_inc/sys/socket.h | 38 +++++--- .../ut-stubs/override_inc/sys/types.h | 1 + .../ut-stubs/src/arpa-inet-stubs.c | 47 ++++++++++ .../ut-stubs/src/netinet-in-stubs.c | 46 ++++++++++ ...{bsd-select-stubs.c => sys-select-stubs.c} | 0 .../ut-stubs/src/sys-socket-stubs.c | 72 +++++++++++++++ src/unit-test-coverage/vxworks/CMakeLists.txt | 11 ++- 15 files changed, 553 insertions(+), 44 deletions(-) create mode 100644 src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c create mode 100644 src/unit-test-coverage/portable/src/coveragetest-no-network.c create mode 100644 src/unit-test-coverage/portable/src/coveragetest-no-sockets.c create mode 100644 src/unit-test-coverage/portable/src/coveragetest-no-symtab.c create mode 100644 src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c create mode 100644 src/unit-test-coverage/ut-stubs/src/netinet-in-stubs.c rename src/unit-test-coverage/ut-stubs/src/{bsd-select-stubs.c => sys-select-stubs.c} (100%) create mode 100644 src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index 8b66ca1b1..59bc5d26a 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -66,10 +66,10 @@ typedef union { char data[OS_SOCKADDR_MAX_LEN]; - struct sockaddr sockaddr; - struct sockaddr_in sockaddr_in; + struct sockaddr sa; + struct sockaddr_in sa_in; #ifdef OS_NETWORK_SUPPORTS_IPV6 - struct sockaddr_in6 sockaddr_in6; + struct sockaddr_in6 sa_in6; #endif } OS_SockAddr_Accessor_t; @@ -565,8 +565,8 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) return OS_ERR_NOT_IMPLEMENTED; } - Addr->ActualLength = OSAL_SIZE_C(addrlen); - Accessor->sockaddr.sa_family = sa_family; + Addr->ActualLength = OSAL_SIZE_C(addrlen); + Accessor->sa.sa_family = sa_family; return OS_SUCCESS; } /* end OS_SocketAddrInit_Impl */ @@ -586,14 +586,14 @@ int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_ Accessor = (const OS_SockAddr_Accessor_t *)&Addr->AddrData; - switch (Accessor->sockaddr.sa_family) + switch (Accessor->sa.sa_family) { case AF_INET: - addrbuffer = &Accessor->sockaddr_in.sin_addr; + addrbuffer = &Accessor->sa_in.sin_addr; break; #ifdef OS_NETWORK_SUPPORTS_IPV6 case AF_INET6: - addrbuffer = &Accessor->sockaddr_in6.sin6_addr; + addrbuffer = &Accessor->sa_in6.sin6_addr; break; #endif default: @@ -601,7 +601,7 @@ int32 OS_SocketAddrToString_Impl(char *buffer, size_t buflen, const OS_SockAddr_ break; } - if (inet_ntop(Accessor->sockaddr.sa_family, addrbuffer, buffer, buflen) == NULL) + if (inet_ntop(Accessor->sa.sa_family, addrbuffer, buffer, buflen) == NULL) { return OS_ERROR; } @@ -624,14 +624,14 @@ int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string) Accessor = (OS_SockAddr_Accessor_t *)&Addr->AddrData; - switch (Accessor->sockaddr.sa_family) + switch (Accessor->sa.sa_family) { case AF_INET: - addrbuffer = &Accessor->sockaddr_in.sin_addr; + addrbuffer = &Accessor->sa_in.sin_addr; break; #ifdef OS_NETWORK_SUPPORTS_IPV6 case AF_INET6: - addrbuffer = &Accessor->sockaddr_in6.sin6_addr; + addrbuffer = &Accessor->sa_in6.sin6_addr; break; #endif default: @@ -639,7 +639,7 @@ int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string) break; } - if (inet_pton(Accessor->sockaddr.sa_family, string, addrbuffer) < 0) + if (inet_pton(Accessor->sa.sa_family, string, addrbuffer) < 0) { return OS_ERROR; } @@ -662,14 +662,14 @@ int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr) Accessor = (const OS_SockAddr_Accessor_t *)&Addr->AddrData; - switch (Accessor->sockaddr.sa_family) + switch (Accessor->sa.sa_family) { case AF_INET: - sa_port = Accessor->sockaddr_in.sin_port; + sa_port = Accessor->sa_in.sin_port; break; #ifdef OS_NETWORK_SUPPORTS_IPV6 case AF_INET6: - sa_port = Accessor->sockaddr_in6.sin6_port; + sa_port = Accessor->sa_in6.sin6_port; break; #endif default: @@ -698,14 +698,14 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum) sa_port = htons(PortNum); Accessor = (OS_SockAddr_Accessor_t *)&Addr->AddrData; - switch (Accessor->sockaddr.sa_family) + switch (Accessor->sa.sa_family) { case AF_INET: - Accessor->sockaddr_in.sin_port = sa_port; + Accessor->sa_in.sin_port = sa_port; break; #ifdef OS_NETWORK_SUPPORTS_IPV6 case AF_INET6: - Accessor->sockaddr_in6.sin6_port = sa_port; + Accessor->sa_in6.sin6_port = sa_port; break; #endif default: diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c new file mode 100644 index 000000000..7b4bc3141 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c @@ -0,0 +1,89 @@ +/* + * 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. + */ + +/** + * \brief Coverage test for no network implementation + * \ingroup portable + */ + +#include "os-portable-coveragetest.h" +#include "os-shared-sockets.h" +#include "os-shared-idmap.h" +#include "os-shared-file.h" + +#include "OCS_sys_socket.h" + +void Test_OS_SocketOpen_Impl(void) +{ + OS_object_token_t token = {0}; + + /* Set up token for index 0 */ + token.obj_idx = UT_INDEX_0; + + /* Invalid socket type */ + OS_stream_table[0].socket_type = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_ERR_NOT_IMPLEMENTED); + + /* Invalid domain type */ + OS_stream_table[0].socket_type = OS_SocketType_DATAGRAM; + OS_stream_table[0].socket_domain = -1; + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_ERR_NOT_IMPLEMENTED); + + /* Socket error */ + OS_stream_table[0].socket_domain = OS_SocketDomain_INET; + UT_SetDeferredRetcode(UT_KEY(OCS_socket), 1, -1); + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (&token), OS_ERROR); + + /* Success case */ + 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); +} + +/* ------------------- 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); + memset(OS_stream_table, 0, sizeof(OS_stream_table)); +} + +/* + * 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_SocketOpen_Impl); +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-network.c b/src/unit-test-coverage/portable/src/coveragetest-no-network.c new file mode 100644 index 000000000..dfc7f5284 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-network.c @@ -0,0 +1,63 @@ +/* + * 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. + */ + +/** + * \brief Coverage test for no network implementation + * \ingroup portable + */ + +#include "os-portable-coveragetest.h" +#include "os-shared-network.h" + +void Test_No_Network(void) +{ + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl, (NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName_Impl, (NULL, 0), OS_ERR_NOT_IMPLEMENTED); +} + +/* ------------------- 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(No_Network); +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c new file mode 100644 index 000000000..34977314c --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c @@ -0,0 +1,73 @@ +/* + * 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. + */ + +/** + * \brief Coverage test for no socket implementation + * \ingroup portable + */ + +#include "os-portable-coveragetest.h" +#include "os-shared-sockets.h" + +void Test_No_Sockets(void) +{ + OSAPI_TEST_FUNCTION_RC(OS_SocketOpen_Impl, (NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketBind_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketConnect_Impl, (NULL, NULL, 0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketAccept_Impl, (NULL, NULL, NULL, 0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketRecvFrom_Impl, (NULL, NULL, 0, NULL, 0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketSendTo_Impl, (NULL, NULL, 0, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketGetInfo_Impl, (NULL, NULL), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrInit_Impl, (NULL, 0), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrToString_Impl, (NULL, 0, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrFromString_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrGetPort_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SocketAddrSetPort_Impl, (NULL, 0), OS_ERR_NOT_IMPLEMENTED); +} + +/* ------------------- 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(No_Sockets); +} diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c new file mode 100644 index 000000000..ad7009970 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.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. + */ + +/** + * \brief Coverage test for no symtab implementation + * \ingroup portable + */ + +#include "os-portable-coveragetest.h" +#include "os-shared-module.h" + +void Test_No_Symtab(void) +{ + OSAPI_TEST_FUNCTION_RC(OS_GlobalSymbolLookup_Impl, (NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_ModuleSymbolLookup_Impl, (NULL, NULL, NULL), OS_ERR_NOT_IMPLEMENTED); + OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl, (NULL, 0), OS_ERR_NOT_IMPLEMENTED); +} + +/* ------------------- 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(No_Symtab); +} diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index ccc6bcc18..ba4714dbb 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -36,11 +36,12 @@ # the OCS functions that are actually used. # add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL - src/bsd-select-stubs.c + src/arpa-inet-stubs.c src/libc-ctype-stubs.c src/libc-stdio-stubs.c src/libc-stdlib-stubs.c src/libc-string-stubs.c + src/netinet-in-stubs.c src/posix-dirent-stubs.c src/posix-dlfcn-stubs.c src/posix-errno-stubs.c @@ -54,6 +55,8 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/posix-stat-stubs.c src/posix-time-stubs.c src/posix-unistd-stubs.c + src/sys-socket-stubs.c + src/sys-select-stubs.c src/vxworks-ataDrv-stubs.c src/vxworks-dosFsLib-stubs.c src/vxworks-errnoLib-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h index 35e079f03..098c1e16d 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_socket.h @@ -32,11 +32,42 @@ /* ----------------------------------------- */ /* types normally defined in sys/socket.h */ /* ----------------------------------------- */ -typedef size_t OCS_socklen_t; +typedef size_t OCS_socklen_t; +typedef unsigned short int OCS_sa_family_t; struct OCS_sockaddr { - char sa[4]; + OCS_sa_family_t sa_family; +}; + +struct OCS_sockaddr_in +{ + OCS_sa_family_t sa_family; + uint16_t sin_port; + uint32_t sin_addr; +}; + +struct OCS_sockaddr_in6 +{ + OCS_sa_family_t sa_family; + uint16_t sin6_port; + uint32_t sin6_addr[4]; +}; + +enum +{ + OCS_EINPROGRESS = -2, + OCS_EWOULDBLOCK, + OCS_AF_INET, + OCS_AF_INET6, + OCS_SOCK_DGRAM, + OCS_SOCK_STREAM, + OCS_IPPROTO_UDP, + OCS_IPPROTO_TCP, + OCS_SOL_SOCKET, + OCS_SO_REUSEADDR, + OCS_SO_ERROR, + OCS_MSG_DONTWAIT }; /* ----------------------------------------- */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h index c3db9b65f..e89672682 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_types.h @@ -31,13 +31,14 @@ /* ----------------------------------------- */ /* types normally defined in sys/types.h */ /* ----------------------------------------- */ -typedef ptrdiff_t OCS_ssize_t; -typedef long OCS_off_t; -typedef unsigned int OCS_mode_t; -typedef long OCS_time_t; -typedef int OCS_pid_t; -typedef int OCS_gid_t; -typedef int OCS_uid_t; +typedef ptrdiff_t OCS_ssize_t; +typedef long OCS_off_t; +typedef unsigned int OCS_mode_t; +typedef long OCS_time_t; +typedef int OCS_pid_t; +typedef int OCS_gid_t; +typedef int OCS_uid_t; +typedef unsigned short int OCS_u_short; /* ----------------------------------------- */ /* prototypes normally declared in sys/types.h */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h index 11128a920..155f1e100 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/socket.h @@ -27,16 +27,32 @@ /* ----------------------------------------- */ /* mappings for declarations in sys/socket.h */ /* ----------------------------------------- */ -#define socklen_t OCS_socklen_t -#define sockaddr OCS_sockaddr -#define accept OCS_accept -#define bind OCS_bind -#define connect OCS_connect -#define getsockopt OCS_getsockopt -#define listen OCS_listen -#define recvfrom OCS_recvfrom -#define sendto OCS_sendto -#define setsockopt OCS_setsockopt -#define socket OCS_socket +#define socklen_t OCS_socklen_t +#define sockaddr OCS_sockaddr +#define sockaddr_in OCS_sockaddr_in +#define sockaddr_in6 OCS_sockaddr_in6 +#define sa_family_t OCS_sa_family_t +#define accept OCS_accept +#define bind OCS_bind +#define connect OCS_connect +#define getsockopt OCS_getsockopt +#define listen OCS_listen +#define recvfrom OCS_recvfrom +#define sendto OCS_sendto +#define setsockopt OCS_setsockopt +#define socket OCS_socket + +#define EINPROGRESS OCS_EINPROGRESS +#define EWOULDBLOCK OCS_EWOULDBLOCK +#define AF_INET OCS_AF_INET +#define AF_INET6 OCS_AF_INET6 +#define SOCK_DGRAM OCS_SOCK_DGRAM +#define SOCK_STREAM OCS_SOCK_STREAM +#define IPPROTO_UDP OCS_IPPROTO_UDP +#define IPPROTO_TCP OCS_IPPROTO_TCP +#define SOL_SOCKET OCS_SOL_SOCKET +#define SO_REUSEADDR OCS_SO_REUSEADDR +#define SO_ERROR OCS_SO_ERROR +#define MSG_DONTWAIT OCS_MSG_DONTWAIT #endif /* OSAL_OVERRIDE_SYS_SOCKET_H */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h index c1cd599f8..a08b204d5 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/types.h @@ -33,5 +33,6 @@ #define pid_t OCS_pid_t #define gid_t OCS_gid_t #define uid_t OCS_uid_t +#define u_short OCS_u_short #endif /* OSAL_OVERRIDE_SYS_TYPES_H */ diff --git a/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c b/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c new file mode 100644 index 000000000..d88be9ecb --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/arpa-inet-stubs.c @@ -0,0 +1,47 @@ +/* + * 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. + */ + +/** + * \brief Stubs for arpa/inet.h + * \ingroup ut-stubs + */ +#include +#include "utstubs.h" +#include + +const char *OCS_inet_ntop(int af, const void *cp, char *buf, size_t len) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OCS_inet_ntop); + + if (Status == 0) + { + /* "nominal" response */ + return inet_ntop(af, cp, buf, len); + } + + return (char *)0; +} + +int OCS_inet_pton(int af, const char *cp, void *buf) +{ + return UT_DEFAULT_IMPL(OCS_inet_pton); +} diff --git a/src/unit-test-coverage/ut-stubs/src/netinet-in-stubs.c b/src/unit-test-coverage/ut-stubs/src/netinet-in-stubs.c new file mode 100644 index 000000000..18d0351b0 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/netinet-in-stubs.c @@ -0,0 +1,46 @@ +/* + * 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. + */ + +/** + * \brief Stubs for netinet/in.h + * \ingroup ut-stubs + */ +#include "utstubs.h" +#include + +uint16_t OCS_htons(uint16_t hostshort) +{ + return UT_DEFAULT_IMPL(OCS_htons); +} + +uint16_t OCS_ntohs(uint16_t netshort) +{ + return UT_DEFAULT_IMPL(OCS_ntohs); +} + +uint32_t OCS_htonl(uint32_t hostlong) +{ + return UT_DEFAULT_IMPL(OCS_htonl); +} + +uint32_t OCS_ntohl(uint32_t netlong) +{ + return UT_DEFAULT_IMPL(OCS_ntohl); +} diff --git a/src/unit-test-coverage/ut-stubs/src/bsd-select-stubs.c b/src/unit-test-coverage/ut-stubs/src/sys-select-stubs.c similarity index 100% rename from src/unit-test-coverage/ut-stubs/src/bsd-select-stubs.c rename to src/unit-test-coverage/ut-stubs/src/sys-select-stubs.c diff --git a/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c b/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c new file mode 100644 index 000000000..88448c9c0 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/sys-socket-stubs.c @@ -0,0 +1,72 @@ +/* + * 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. + */ + +/** + * \brief Stubs for sys/sockets.h + * \ingroup ut-stubs + */ +#include "utstubs.h" +#include + +int OCS_accept(int fd, struct OCS_sockaddr *addr, OCS_socklen_t *addr_len) +{ + return UT_DEFAULT_IMPL(OCS_accept); +} + +int OCS_bind(int fd, const struct OCS_sockaddr *addr, OCS_socklen_t len) +{ + return UT_DEFAULT_IMPL(OCS_bind); +} + +int OCS_connect(int fd, const struct OCS_sockaddr *addr, OCS_socklen_t len) +{ + return UT_DEFAULT_IMPL(OCS_connect); +} + +int OCS_getsockopt(int fd, int level, int optname, void *optval, OCS_socklen_t *optlen) +{ + return UT_DEFAULT_IMPL(OCS_getsockopt); +} + +int OCS_listen(int fd, int n) +{ + return UT_DEFAULT_IMPL(OCS_listen); +} + +OCS_ssize_t OCS_recvfrom(int fd, void *buf, size_t n, int flags, struct OCS_sockaddr *addr, OCS_socklen_t *addr_len) +{ + return UT_DEFAULT_IMPL(OCS_recvfrom); +} + +OCS_ssize_t OCS_sendto(int fd, const void *buf, size_t n, int flags, const struct OCS_sockaddr *addr, + OCS_socklen_t addr_len) +{ + return UT_DEFAULT_IMPL(OCS_sendto); +} + +int OCS_setsockopt(int fd, int level, int optname, const void *optval, OCS_socklen_t optlen) +{ + return UT_DEFAULT_IMPL(OCS_setsockopt); +} + +int OCS_socket(int domain, int type, int protocol) +{ + return UT_DEFAULT_IMPL(OCS_socket); +} diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index 5bc877276..ec994c992 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -28,13 +28,13 @@ set(VXWORKS_PORTABLE_BLOCK_LIST console-bsp bsd-select - #bsd-sockets + bsd-sockets no-loader no-shell - #no-symtab - #no-network - #no-sockets + no-symtab + no-network + no-sockets ) @@ -76,3 +76,6 @@ foreach(MODNAME ${VXWORKS_PORTABLE_BLOCK_LIST}) ) endforeach(MODNAME ${VXWORKS_PORTABLE_BLOCK_LIST}) +# Custom flags for specific tests to be able to cover all code +set_property(SOURCE ${OSAL_SOURCE_DIR}/src/os/portable/os-impl-bsd-sockets.c + APPEND PROPERTY COMPILE_DEFINITIONS OS_NETWORK_SUPPORTS_IPV6)