From e9c4ad4ff9d8d38b4c7ea648d703a6a45477af42 Mon Sep 17 00:00:00 2001 From: Haley Cao Date: Mon, 13 Jan 2020 20:49:37 +0000 Subject: [PATCH] Add OMRSock tests in omrsockTest.cpp to test OMRSock PTB 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 Signed-off-by: Haley Cao --- fvtest/porttest/CMakeLists.txt | 5 ++-- fvtest/porttest/makefile | 7 ++++-- fvtest/porttest/omrsockTest.cpp | 42 +++++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/fvtest/porttest/CMakeLists.txt b/fvtest/porttest/CMakeLists.txt index a7bf4b6cc72..1bc675c51c8 100644 --- a/fvtest/porttest/CMakeLists.txt +++ b/fvtest/porttest/CMakeLists.txt @@ -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 @@ -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 ) diff --git a/fvtest/porttest/makefile b/fvtest/porttest/makefile index 550e4451c6c..57965fc4208 100644 --- a/fvtest/porttest/makefile +++ b/fvtest/porttest/makefile @@ -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 @@ -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 diff --git a/fvtest/porttest/omrsockTest.cpp b/fvtest/porttest/omrsockTest.cpp index 3d7d02ec7d9..10e48afd299 100644 --- a/fvtest/porttest/omrsockTest.cpp +++ b/fvtest/porttest/omrsockTest.cpp @@ -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 @@ -23,6 +23,7 @@ #if defined(OMR_PORT_SOCKET_SUPPORT) #include "omrport.h" #include "omrportsock.h" +#include "omrportsocktypes.h" #include "testHelpers.hpp" /** @@ -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; } /** @@ -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; } /** @@ -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); } /** @@ -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); } /** @@ -104,7 +132,7 @@ TEST(PortSockTest, per_thread_buffer_functionality) */ TEST(PortSockTest, getaddrinfo_creation_and_extraction) { - /* Unimplemented. */ + /* Unimplemented. */ } /** @@ -122,7 +150,7 @@ TEST(PortSockTest, getaddrinfo_creation_and_extraction) */ TEST(PortSockTest, two_socket_communication) { - /* Unimplemented. */ + /* Unimplemented. */ } #endif /* defined(OMR_PORT_SOCKET_SUPPORT) */