Skip to content

Commit

Permalink
Merge pull request nasa#925 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
HOTFIX: osal Integration candidate 2021-03-23
  • Loading branch information
astrogeco authored Mar 23, 2021
2 parents 4062fe6 + 97c23c9 commit 53f7f61
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF
## Version History


### Development Build: v5.1.0-rc1+dev347
### Development Build: v5.1.0-rc1+dev350

- Moves copyblock size to a macro and add comments. Defines `OS_CP_BLOCK_SIZE` and adds clear documentation that it could be adjusted for page size, performance, etc.
- Removes while loop
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/*
* Development Build Macro Definitions
*/
#define OS_BUILD_NUMBER 347
#define OS_BUILD_NUMBER 350
#define OS_BUILD_BASELINE "v5.1.0-rc1"

/*
Expand Down
44 changes: 36 additions & 8 deletions src/os/portable/os-impl-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,24 @@ int32 OS_SocketOpen_Impl(const OS_object_token_t *token)
* any blocking would be done explicitly via the select() wrappers
*/
os_flags = fcntl(impl->fd, F_GETFL);
os_flags |= OS_IMPL_SOCKET_FLAGS;
fcntl(impl->fd, F_SETFL, os_flags);

impl->selectable = ((os_flags & O_NONBLOCK) != 0);
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));
}
else
{
impl->selectable = ((os_flags & O_NONBLOCK) != 0);
}
}

return OS_SUCCESS;
} /* end OS_SocketOpen_Impl */
Expand Down Expand Up @@ -379,10 +393,24 @@ int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_
* any blocking would be done explicitly via the select() wrappers
*/
os_flags = fcntl(conn_impl->fd, F_GETFL);
os_flags |= OS_IMPL_SOCKET_FLAGS;
fcntl(conn_impl->fd, F_SETFL, os_flags);

conn_impl->selectable = ((os_flags & O_NONBLOCK) != 0);
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));
}
else
{
conn_impl->selectable = ((os_flags & O_NONBLOCK) != 0);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
*****************************************************/
void UT_PortablePosixIOTest_Set_Selectable(osal_index_t local_id, bool is_selectable);
void UT_PortablePosixIOTest_Set_FD(osal_index_t local_id, int fd);
bool UT_PortablePosixIOTest_Get_Selectable(osal_index_t local_id);
void UT_PortablePosixIOTest_ResetImpl(osal_index_t local_id);

#endif /* UT_ADAPTOR_PORTABLE_POSIX_IO_H */
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@

#include "os-impl-io.h"

void UT_PortablePosixIOTest_ResetImpl(osal_index_t local_id)
{
OS_impl_filehandle_table[local_id].fd = -1;
OS_impl_filehandle_table[local_id].selectable = false;
}

void UT_PortablePosixIOTest_Set_Selectable(osal_index_t local_id, bool is_selectable)
{
OS_impl_filehandle_table[local_id].selectable = is_selectable;
Expand All @@ -40,3 +46,8 @@ void UT_PortablePosixIOTest_Set_FD(osal_index_t local_id, int fd)
{
OS_impl_filehandle_table[local_id].fd = fd;
}

bool UT_PortablePosixIOTest_Get_Selectable(osal_index_t local_id)
{
return OS_impl_filehandle_table[local_id].selectable;
}
23 changes: 23 additions & 0 deletions src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
#include "os-shared-file.h"

#include "OCS_sys_socket.h"
#include "OCS_fcntl.h"

#include "ut-adaptor-portable-posix-io.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;
UT_PortablePosixIOTest_ResetImpl(token.obj_idx);

/* Invalid socket type */
OS_stream_table[0].socket_type = -1;
Expand All @@ -55,6 +59,25 @@ 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");

/* 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_STUB_COUNT(OCS_fcntl, 1);
UtAssert_True(!UT_PortablePosixIOTest_Get_Selectable(token.obj_idx),
"Socket not selectable without O_NONBLOCK flag");

/* 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_STUB_COUNT(OCS_fcntl, 2);
UtAssert_True(!UT_PortablePosixIOTest_Get_Selectable(token.obj_idx),
"Socket not selectable without O_NONBLOCK flag");
}

/* ------------------- End of test cases --------------------------------------*/
Expand Down

0 comments on commit 53f7f61

Please sign in to comment.