From 32a5f5fbb3ffe5683b9423c560b5c6c59f18715a Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Mon, 22 Feb 2021 14:18:18 -0500 Subject: [PATCH 1/7] Fix #780, restrict permissions on file create --- ut_assert/src/uttools.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ut_assert/src/uttools.c b/ut_assert/src/uttools.c index aeb21a461..534ad0e82 100644 --- a/ut_assert/src/uttools.c +++ b/ut_assert/src/uttools.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "common_types.h" #include "utassert.h" @@ -55,10 +56,17 @@ typedef struct bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length) { - FILE *fp; + FILE * fp; + struct stat dststat; if ((fp = fopen(Filename, "w"))) { + if (stat(Filename, &dststat) == 0) + { + chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)); + stat(Filename, &dststat); + } + fwrite(Memory, Length, 1, fp); fclose(fp); return (true); @@ -95,12 +103,18 @@ bool UtBinFile2Mem(void *Memory, const char *Filename, uint32 Length) bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length) { - FILE * fp; - uint32 i; - uint32 j; + FILE * fp; + uint32 i; + uint32 j; + struct stat dststat; if ((fp = fopen(Filename, "w"))) { + if (stat(Filename, &dststat) == 0) + { + chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)); + stat(Filename, &dststat); + } for (i = 0; i < Length; i += 16) { From bbce4beb1389bf8bd5f7b447382e7cd213ac3671 Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Tue, 23 Feb 2021 12:06:18 -0500 Subject: [PATCH 2/7] Fix #828, fix comment style --- src/tests/select-test/select-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/select-test/select-test.c b/src/tests/select-test/select-test.c index c9d773a55..251271f18 100644 --- a/src/tests/select-test/select-test.c +++ b/src/tests/select-test/select-test.c @@ -263,7 +263,7 @@ void Teardown_Single(void) void Teardown_Multi(void) { - // Server 1 is intentionaly left waiting so we close it out here. + /* Server 1 is intentionaly left waiting so we close it out here */ OS_close(s_socket_id); OS_TaskDelete(s_task_id); From b257683bb578c15407aabeb42e88d0f12f12ef53 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 11 Feb 2021 15:17:36 -0500 Subject: [PATCH 3/7] 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) From d1c4e8ff8ade263c14089a821267ff764420abbf Mon Sep 17 00:00:00 2001 From: Jake Hageman Date: Mon, 1 Mar 2021 09:21:16 -0500 Subject: [PATCH 4/7] Fix #833, Initialize file descriptor in OS_OpenCreate --- src/os/inc/osapi-file.h | 2 +- src/os/shared/src/osapi-file.c | 8 +++++--- src/tests/file-api-test/file-api-test.c | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/os/inc/osapi-file.h b/src/os/inc/osapi-file.h index a281413ac..413515876 100644 --- a/src/os/inc/osapi-file.h +++ b/src/os/inc/osapi-file.h @@ -125,7 +125,7 @@ typedef enum * of outputting the ID/descriptor separately from the return value, rather * than relying on the user to convert it back. * - * @param[out] filedes The handle ID + * @param[out] filedes The handle ID (OS_OBJECT_ID_UNDEFINED on failure) * @param[in] path File name to create or open * @param[in] flags The file permissions - see @ref OS_file_flag_t * @param[in] access Intended access mode - see @ref OSFileAccess diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index ebb9c569b..ba123c736 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -98,9 +98,8 @@ int32 OS_FileAPI_Init(void) * * Function: OS_OpenCreate * - * Purpose: Local helper routine, not part of OSAL API. - * Implements both "open" and "creat" file operations - * (The difference is a matter of what flags are passed in) + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail * *-----------------------------------------------------------------*/ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 access) @@ -113,6 +112,9 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc /* Check parameters */ OS_CHECK_POINTER(filedes); + /* Initialize file descriptor */ + *filedes = OS_OBJECT_ID_UNDEFINED; + /* ** Check for a valid access mode */ diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index b82867782..bfdf0b88f 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -173,8 +173,10 @@ void TestCreatRemove(void) UtAssert_True(status == OS_SUCCESS, "status after remove max name length file = %d", (int)status); /* try creating with file name too big, should fail */ + fd = ~OS_OBJECT_ID_UNDEFINED; status = OS_OpenCreate(&fd, longfilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); UtAssert_True(status < OS_SUCCESS, "status after create file name too long = %d", (int)status); + UtAssert_UINT32_EQ(fd, OS_OBJECT_ID_UNDEFINED); /* try removing with file name too big. Should Fail */ status = OS_remove(longfilename); @@ -233,8 +235,10 @@ void TestOpenClose(void) UtAssert_True(status != OS_SUCCESS, "status after close = %d", (int)status); /* open a file that was never in the system */ + fd = ~OS_OBJECT_ID_UNDEFINED; status = OS_OpenCreate(&fd, "/drive0/FileNotHere", OS_FILE_FLAG_NONE, OS_READ_ONLY); UtAssert_True(status < OS_SUCCESS, "status after open = %d", (int)status); + UtAssert_UINT32_EQ(fd, OS_OBJECT_ID_UNDEFINED); /* try removing the file from the drive to end the function */ status = OS_remove(filename); From 6197a52f6f9456f616e943e290dc0c90597b647d Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 17 Feb 2021 15:18:47 -0500 Subject: [PATCH 5/7] Fix #821, add accessor functions for version strings Adds 4 version API calls: const char *OS_GetVersionString(void); const char *OS_GetVersionCodeName(void); void OS_GetVersionNumber(uint8[4]); uint32 OS_GetBuildNumber(void); These return the values of current macros in osapi-version.h. The accessor function should be the preferred way to get the OSAL version info (vs. using macro directly) as it is evaluated at OSAL library compile time, rather than application compile time, and thus will remain correct in the event that OSAL is relinked without recompiling the application. --- CMakeLists.txt | 1 + src/os/inc/osapi-version.h | 94 +++++++++++- src/os/shared/src/osapi-version.c | 87 +++++++++++ src/unit-test-coverage/shared/CMakeLists.txt | 1 + .../shared/src/coveragetest-version.c | 143 ++++++++++++++++++ 5 files changed, 318 insertions(+), 8 deletions(-) create mode 100644 src/os/shared/src/osapi-version.c create mode 100644 src/unit-test-coverage/shared/src/coveragetest-version.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a9cfbd8e7..cad3c0324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,6 +249,7 @@ set(OSAL_SRCLIST src/os/shared/src/osapi-task.c src/os/shared/src/osapi-timebase.c src/os/shared/src/osapi-time.c + src/os/shared/src/osapi-version.c ) if (OSAL_CONFIG_DEBUG_PRINTF) diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index c907abf9f..d751f2745 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -27,6 +27,8 @@ #ifndef OSAPI_VERSION_H #define OSAPI_VERSION_H +#include "common_types.h" + /* * Development Build Macro Definitions */ @@ -38,11 +40,15 @@ */ #define OS_MAJOR_VERSION 5 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */ #define OS_MINOR_VERSION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */ -#define OS_REVISION \ - 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased \ - development version. */ +#define OS_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */ -#define OS_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */ +/*! + * @brief Mission revision. + * + * Set to 0 on OFFIFICIAL releases, and set to 255 (0xFF) on development versions. + * Values 1-254 are reserved for mission use to denote patches/customizations as needed. + */ +#define OS_MISSION_REV 0xFF /* * Tools to construct version string @@ -56,14 +62,19 @@ */ #define OS_VERSION OS_BUILD_BASELINE "+dev" OS_STR(OS_BUILD_NUMBER) +/*! @brief Version code name + * All modular components which are tested/validated together should share the same code name + */ +#define OS_VERSION_CODENAME "Bootes" + /*! @brief Development Build Version String. * @details Reports the current development build's baseline, number, and name. Also includes a note about the latest * official version. @n See @ref cfsversions for format differences between development and release versions. */ -#define OS_VERSION_STRING \ - " OSAL Development Build\n" \ - " " OS_VERSION " (Codename: Bootes)\n" /* Codename for current development */ \ - " Latest Official Version: osal v5.0.0" /* For full support please use official release version */ +#define OS_VERSION_STRING \ + " OSAL Development Build\n" \ + " " OS_VERSION " (Codename: " OS_VERSION_CODENAME ")\n" /* Codename for current development */ \ + " Latest Official Version: osal v5.0.0" /* For full support please use official release version */ /*! @brief Combines the revision components into a single value * @details Applications can check against this number @n @@ -72,6 +83,73 @@ OSAL 4.1 is present. */ #define OSAL_API_VERSION ((OS_MAJOR_VERSION * 10000) + (OS_MINOR_VERSION * 100) + OS_REVISION) +/* + * Functions to get OSAL version info + * + * It is preferable to use the functions below to retrieve the OSAL version + * at runtime, because if applications reference the macros above directly, the + * macro will only get evaluated when the _application_ is built. + * + * When using the functions below, the version gets evaluated when the OSAL library + * is built, and therefore if the OSAL library is re-linked without rebuilding the + * application itself, the version will still be correct. + */ + +/** + * Gets the OSAL version/baseline ID as a string + * + * This returns the content of the #OS_VERSION macro defined above, and is specifically + * just the baseline and development build ID (if applicable), without any extra info. + * + * \returns Basic version identifier. This is a fixed value string and is never NULL. + */ +const char *OS_GetVersionString(void); + +/** + * Gets the OSAL version code name + * + * All NASA CFE/CFS components (including CFE framework, OSAL and PSP) that work + * together will share the same code name. + * + * \returns OSAL code name. This is a fixed value string and is never NULL. + */ +const char *OS_GetVersionCodeName(void); + +/** + * \brief Obtain the OSAL numeric version number + * + * This retrieves the numeric OSAL version identifier as an array of 4 uint8 values. + * + * The array of numeric values is in order of precedence: + * [0] = Major Number + * [1] = Minor Number + * [2] = Revision Number + * [3] = Mission Revision + * + * The "Mission Revision" (last output) also indicates whether this is an + * official release, a patched release, or a development version. + * 0 indicates an official release + * 1-254 local patch level (reserved for mission use) + * 255 indicates a development build + * + * \param[out] VersionNumbers A fixed-size array to be filled with the version numbers + */ +void OS_GetVersionNumber(uint8 VersionNumbers[4]); + +/** + * \brief Obtain the OSAL library numeric build number + * + * The build number is a monotonically increasing number that (coarsely) + * reflects the number of commits/changes that have been merged since the + * epoch release. During development cycles this number should increase + * after each subsequent merge/modification. + * + * Like other version information, this is a fixed number assigned at compile time. + * + * \returns The OSAL library build number + */ +uint32 OS_GetBuildNumber(void); + #endif /* OSAPI_VERSION_H */ /************************/ diff --git a/src/os/shared/src/osapi-version.c b/src/os/shared/src/osapi-version.c new file mode 100644 index 000000000..610d1a6a4 --- /dev/null +++ b/src/os/shared/src/osapi-version.c @@ -0,0 +1,87 @@ +/* + * 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-version.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + * Defines functions that return version information + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ +#include + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionString + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *OS_GetVersionString(void) +{ + return OS_VERSION; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionCodeName + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *OS_GetVersionCodeName(void) +{ + return OS_VERSION_CODENAME; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionNumber + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void OS_GetVersionNumber(uint8 VersionNumbers[4]) +{ + VersionNumbers[0] = OS_MAJOR_VERSION; + VersionNumbers[1] = OS_MINOR_VERSION; + VersionNumbers[2] = OS_REVISION; + VersionNumbers[3] = OS_MISSION_REV; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetBuildNumber + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 OS_GetBuildNumber(void) +{ + return OS_BUILD_NUMBER; +} diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 9f9211880..defe74c08 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -23,6 +23,7 @@ set(MODULE_LIST task timebase time + version ) set(SHARED_COVERAGE_LINK_LIST diff --git a/src/unit-test-coverage/shared/src/coveragetest-version.c b/src/unit-test-coverage/shared/src/coveragetest-version.c new file mode 100644 index 000000000..20d2688c9 --- /dev/null +++ b/src/unit-test-coverage/shared/src/coveragetest-version.c @@ -0,0 +1,143 @@ +/* + * 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-version.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + * Exercise the "GetVersion" functions. These functions do not have any actual + * logic, they just directly return fixed strings, but they should be called as + * part of unit test for coverage reasons. + * + * The strings are free-form and no specific format is checked, the only real + * requirement is that they are not NULL. + */ +#include "os-shared-coveragetest.h" + +#include "osapi-version.h" + +/* +********************************************************************************** +** PUBLIC API FUNCTIONS +********************************************************************************** +*/ + +void Test_OS_GetVersionString(void) +{ + /* + * Test Case For: + * const char *OS_GetVersionString(void) + */ + const char *Result; + + Result = OS_GetVersionString(); + UtAssert_NOT_NULL(Result); + + /* + * Display the version description string, just for informational purposes + */ + UtPrintf("OS_GetVersionString() Returned: %s\n", Result); +} + +void Test_OS_GetVersionCodeName(void) +{ + /* + * Test Case For: + * const char *OS_GetVersionCodeName(void) + */ + const char *Result; + + Result = OS_GetVersionCodeName(); + UtAssert_NOT_NULL(Result); + + /* + * Display the code name string, just for informational purposes + */ + UtPrintf("OS_GetVersionCodeName() Returned: %s\n", Result); +} + +void Test_OS_GetVersionNumber(void) +{ + /* + * Test Case For: + * void OS_GetVersionNumber(uint8 VersionNumbers[4]) + */ + uint8 VersionNum[4] = {0}; + + OS_GetVersionNumber(VersionNum); + + /* + * This should output the same info as the version macros + */ + UtAssert_INT32_EQ(VersionNum[0], OS_MAJOR_VERSION); + UtAssert_INT32_EQ(VersionNum[1], OS_MINOR_VERSION); + UtAssert_INT32_EQ(VersionNum[2], OS_REVISION); + UtAssert_INT32_EQ(VersionNum[3], OS_MISSION_REV); + + /* + * Display the version number, just for informational purposes + */ + UtPrintf("OS_GetVersionNumber() Returned: %u.%u.%u.%u\n", (unsigned int)VersionNum[0], (unsigned int)VersionNum[1], + (unsigned int)VersionNum[2], (unsigned int)VersionNum[3]); +} + +void Test_OS_GetBuildNumber(void) +{ + /* + * Test Case For: + * uint32 OS_GetBuildNumber(void) + */ + uint32 Result; + + Result = OS_GetBuildNumber(); + UtAssert_NONZERO(Result); + + /* + * Display the build number, just for informational purposes + */ + UtPrintf("Test_OS_GetBuildNumber() Returned: %lu\n", (unsigned long)Result); +} + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) {} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) {} + +/* + * Register the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_GetVersionString); + ADD_TEST(OS_GetVersionCodeName); + ADD_TEST(OS_GetVersionNumber); + ADD_TEST(OS_GetBuildNumber); +} From 7c47365b2c374c274c0ee39b2825afdfa9591656 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 1 Mar 2021 22:41:20 -0500 Subject: [PATCH 6/7] Fix #821, add ut stubs for version API --- src/ut-stubs/CMakeLists.txt | 1 + src/ut-stubs/osapi-utstub-version.c | 122 ++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/ut-stubs/osapi-utstub-version.c diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index 52ec4d5d2..1e9eefbba 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(ut_osapi_stubs STATIC osapi-utstub-task.c osapi-utstub-time.c osapi-utstub-timebase.c + osapi-utstub-version.c ) # Some of the internal API definitions in stubs are based on diff --git a/src/ut-stubs/osapi-utstub-version.c b/src/ut-stubs/osapi-utstub-version.c new file mode 100644 index 000000000..eec340117 --- /dev/null +++ b/src/ut-stubs/osapi-utstub-version.c @@ -0,0 +1,122 @@ +/* + * 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_stubs.c + * + * Created on: Feb 25, 2015 + * Author: joseph.p.hickey@nasa.gov + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "osapi-version.h" /* OSAL public API for this subsystem */ +#include "utstub-helpers.h" + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionString + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *OS_GetVersionString(void) +{ + static const char DEFAULT[] = "UT"; + void *Buffer; + const char *RetVal; + + UT_GetDataBuffer(UT_KEY(OS_GetVersionString), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionCodeName + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +const char *OS_GetVersionCodeName(void) +{ + static const char DEFAULT[] = "UT"; + void *Buffer; + const char *RetVal; + + UT_GetDataBuffer(UT_KEY(OS_GetVersionCodeName), &Buffer, NULL, NULL); + if (Buffer == NULL) + { + RetVal = DEFAULT; + } + else + { + RetVal = Buffer; + } + + return RetVal; +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetVersionNumber + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +void OS_GetVersionNumber(uint8 VersionNumbers[4]) +{ + UT_Stub_RegisterContext(UT_KEY(OS_GetVersionNumber), VersionNumbers); + UT_DEFAULT_IMPL(VersionNumbers); +} + +/*---------------------------------------------------------------- + * + * Function: OS_GetBuildNumber + * + * Purpose: Implemented per public OSAL API + * See description in API and header file for detail + * + *-----------------------------------------------------------------*/ +uint32 OS_GetBuildNumber(void) +{ + int32 status; + + status = UT_DEFAULT_IMPL(OS_GetBuildNumber); + + return status; +} + From 75105a89214434e25b6850ca76f09b1c70830b52 Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Thu, 4 Mar 2021 12:14:30 -0500 Subject: [PATCH 7/7] Bump to v5.1.0-rc1+dev293 --- README.md | 16 ++++++++++++++++ src/os/inc/osapi-version.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b3857e49..befb370c2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,22 @@ The autogenerated OSAL user's guide can be viewed at + + + ### Development Build: v5.1.0-rc1+dev280 - Makes tests skip after getting their first not implemented error. diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index d751f2745..5eafadf8d 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -32,7 +32,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 280 +#define OS_BUILD_NUMBER 293 #define OS_BUILD_BASELINE "v5.1.0-rc1" /*