Skip to content

Commit

Permalink
Add OMRSock tests in omrsockTest.cpp to test OMRSock PTB
Browse files Browse the repository at this point in the history
Added to tests per_thread_buffer_functionality and library_function_pointers_not_null

- Modified build for omrsockTest.cpp so that only Unix systems
  run the tests.
- Test that all OMRSOCK API functions exists.
- Test omrsock PTB indirectly by using
  sock_getaddrinfo_create_hints to set up hints and then check
  if it exists.

Issue: #4102

co-authored-by: Babneet Singh <sbabneet@ca.ibm.com>

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed Jan 27, 2020
1 parent 6ace67c commit e9c4ad4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
5 changes: 3 additions & 2 deletions fvtest/porttest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -42,7 +42,8 @@ if(OMR_OPT_CUDA)
)
endif()

if(OMR_PORT_SOCKET_SUPPORT)
# TODO: Remove AND (NOT OMR_HOST_OS STREQUAL "win") after OMRSOCK API is implemented on Windows.
if((OMR_PORT_SOCKET_SUPPORT) AND (NOT OMR_HOST_OS STREQUAL "win"))
set(socketSources
omrsockTest.cpp
)
Expand Down
7 changes: 5 additions & 2 deletions fvtest/porttest/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2015, 2016 IBM Corp. and others
# Copyright (c) 2015, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -54,7 +54,10 @@ OBJECTS := \
main_function

ifeq (1,$(OMR_PORT_SOCKET_SUPPORT))
OBJECTS += omrsockTest
# TODO: Remove ifneq (win,$(OMR_HOST_OS)) after OMRSOCK API is implemented on Windows.
ifneq (win,$(OMR_HOST_OS))
OBJECTS += omrsockTest
endif
endif

vpath main_function.cpp $(top_srcdir)/util/main_function
Expand Down
42 changes: 35 additions & 7 deletions fvtest/porttest/omrsockTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -23,6 +23,7 @@
#if defined(OMR_PORT_SOCKET_SUPPORT)
#include "omrport.h"
#include "omrportsock.h"
#include "omrportsocktypes.h"
#include "testHelpers.hpp"

/**
Expand All @@ -41,7 +42,7 @@
int32_t
start_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char *port, int32_t family, omrsock_socket_t *serverSocket, omrsock_sockaddr_t serverAddr)
{
return OMRPORT_ERROR_NOTEXIST;
return OMRPORT_ERROR_NOTEXIST;
}

/**
Expand All @@ -59,7 +60,7 @@ start_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char
int32_t
connect_client_to_server(struct OMRPortLibrary *portLibrary, const char *addrStr, const char *port, int32_t family, omrsock_socket_t *sessionClientSocket, omrsock_sockaddr_t sessionClientAddr)
{
return OMRPORT_ERROR_NOTEXIST;
return OMRPORT_ERROR_NOTEXIST;
}

/**
Expand All @@ -72,7 +73,24 @@ connect_client_to_server(struct OMRPortLibrary *portLibrary, const char *addrStr
*/
TEST(PortSockTest, library_function_pointers_not_null)
{
/* Unimplemented. */
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());

EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_create_hints, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_length, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_family, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_socktype, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_getaddrinfo_protocol, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_freeaddrinfo, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_socket, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_bind, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_listen, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_accept, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_send, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_sendto, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_recv, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_recvfrom, (void *)NULL);
EXPECT_NE(OMRPORTLIB->sock_close, (void *)NULL);
}

/**
Expand All @@ -83,7 +101,17 @@ TEST(PortSockTest, library_function_pointers_not_null)
*/
TEST(PortSockTest, per_thread_buffer_functionality)
{
/* Unimplemented. */
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());

omrsock_addrinfo_t hints = NULL;
int32_t family = 0;
int32_t sockType = 1;
int32_t protocol = 1;
int32_t flags = 0;

OMRPORTLIB->sock_getaddrinfo_create_hints(OMRPORTLIB, &hints, family, sockType, protocol, flags);

ASSERT_NE(hints, (void *)NULL);
}

/**
Expand All @@ -104,7 +132,7 @@ TEST(PortSockTest, per_thread_buffer_functionality)
*/
TEST(PortSockTest, getaddrinfo_creation_and_extraction)
{
/* Unimplemented. */
/* Unimplemented. */
}

/**
Expand All @@ -122,7 +150,7 @@ TEST(PortSockTest, getaddrinfo_creation_and_extraction)
*/
TEST(PortSockTest, two_socket_communication)
{
/* Unimplemented. */
/* Unimplemented. */
}

#endif /* defined(OMR_PORT_SOCKET_SUPPORT) */

0 comments on commit e9c4ad4

Please sign in to comment.