Skip to content

Commit

Permalink
Fix #795, Add missing files to VxWorks coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Feb 25, 2021
1 parent ff4f523 commit b257683
Show file tree
Hide file tree
Showing 15 changed files with 553 additions and 44 deletions.
38 changes: 19 additions & 19 deletions src/os/portable/os-impl-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */
Expand All @@ -586,22 +586,22 @@ 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:
return OS_ERR_BAD_ADDRESS;
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;
}
Expand All @@ -624,22 +624,22 @@ 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:
return OS_ERR_BAD_ADDRESS;
break;
}

if (inet_pton(Accessor->sockaddr.sa_family, string, addrbuffer) < 0)
if (inet_pton(Accessor->sa.sa_family, string, addrbuffer) < 0)
{
return OS_ERROR;
}
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
89 changes: 89 additions & 0 deletions src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c
Original file line number Diff line number Diff line change
@@ -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);
}
63 changes: 63 additions & 0 deletions src/unit-test-coverage/portable/src/coveragetest-no-network.c
Original file line number Diff line number Diff line change
@@ -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);
}
73 changes: 73 additions & 0 deletions src/unit-test-coverage/portable/src/coveragetest-no-sockets.c
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit b257683

Please sign in to comment.