8198834: (ch) Enable java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java on linux-x64
authorbpb
Mon, 05 Mar 2018 08:27:42 -0800
changeset 49128 97288886180c
parent 49127 73385a708426
child 49129 fb9f590b9eee
8198834: (ch) Enable java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java on linux-x64 Summary: Move to using centralized native build and remove obsolete .so files Reviewed-by: alanb, erikj
make/test/JtregNativeJdk.gmk
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.c
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Makefile
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/README
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/linux-i586/libLauncher.so
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/solaris-amd64/libLauncher.so
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/solaris-sparcv9/libLauncher.so
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c
--- a/make/test/JtregNativeJdk.gmk	Sun Mar 04 18:46:07 2018 -0800
+++ b/make/test/JtregNativeJdk.gmk	Mon Mar 05 08:27:42 2018 -0800
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -50,6 +50,7 @@
 
 ifneq ($(OPENJDK_TARGET_OS), windows)
     BUILD_JDK_JTREG_NATIVE_SRC += $(TOPDIR)/test/jdk/java/nio/channels/FileChannel/directio
+    BUILD_JDK_JTREG_NATIVE_SRC += $(TOPDIR)/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel
 endif
 
 BUILD_JDK_JTREG_OUTPUT_DIR := $(OUTPUTDIR)/support/test/jdk/jtreg/native
@@ -59,9 +60,14 @@
 ifeq ($(OPENJDK_TARGET_OS), windows)
     WIN_LIB_JAVA := $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib
     BUILD_JDK_JTREG_LIBRARIES_LIBS_libstringPlatformChars := $(WIN_LIB_JAVA)
+else ifeq ($(OPENJDK_TARGET_OS), linux)
+    BUILD_JDK_JTREG_LIBRARIES_LIBS_libstringPlatformChars := -ljava
+    BUILD_JDK_JTREG_LIBRARIES_LIBS_libDirectIO := -ljava
+    BUILD_JDK_JTREG_LIBRARIES_LIBS_libInheritedChannel := -ljava
 else ifeq ($(OPENJDK_TARGET_OS), solaris)
     BUILD_JDK_JTREG_LIBRARIES_LIBS_libstringPlatformChars := -ljava -lc
     BUILD_JDK_JTREG_LIBRARIES_LIBS_libDirectIO := -ljava -lc
+    BUILD_JDK_JTREG_LIBRARIES_LIBS_libInheritedChannel := -ljava -lc
 else
     BUILD_JDK_JTREG_LIBRARIES_LIBS_libstringPlatformChars := -ljava
     BUILD_JDK_JTREG_LIBRARIES_LIBS_libDirectIO := -ljava
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java	Sun Mar 04 18:46:07 2018 -0800
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java	Mon Mar 05 08:27:42 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
  *        jdk.test.lib.Platform
  *        jdk.test.lib.process.*
  *        StateTest StateTestService EchoTest EchoService CloseTest Launcher Util
- * @run testng/othervm InheritedChannelTest
+ * @run testng/othervm/native InheritedChannelTest
  * @key intermittent
  */
 
@@ -68,9 +68,7 @@
     private static final String OS_ARCH = ARCH.equals("i386") ? "i586" : ARCH;
 
     private static final Path LD_LIBRARY_PATH
-            = Paths.get(TEST_SRC, "lib", OS_NAME + "-" + OS_ARCH);
-
-    private static final Path LAUNCHERLIB = LD_LIBRARY_PATH.resolve("libLauncher.so");
+            = Paths.get(System.getProperty("java.library.path"));
 
     @DataProvider
     public Object[][] testCases() {
@@ -99,11 +97,6 @@
 
     @Test(dataProvider = "testCases")
     public void test(String desc, List<String> opts) throws Throwable {
-        if (!Files.exists(LAUNCHERLIB)) {
-            System.out.println("Cannot find " + LAUNCHERLIB
-                    + " - library not available for this system");
-            return;
-        }
         System.out.println("LD_LIBRARY_PATH=" + LD_LIBRARY_PATH);
 
         List<String> args = new ArrayList<>();
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.c	Sun Mar 04 18:46:07 2018 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +0,0 @@
-/*
- *
- *
- * A simple launcher to launch a program as if it was launched by inetd.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <ctype.h>
-
-#include "jni.h"
-
-#include "Launcher.h"
-
-/*
- * Throws the exception of the given class name and detail message
- */
-static void ThrowException(JNIEnv *env, const char *name, const char *msg) {
-    jclass cls = (*env)->FindClass(env, name);
-    if (cls != NULL) {
-        (*env)->ThrowNew(env, cls, msg);
-    }
-}
-
-/*
- * Convert a jstring to an ISO 8859_1 encoded C string
- */
-static char* getString8859_1Chars(JNIEnv *env, jstring jstr) {
-    int i;
-    char *result;
-    jint len = (*env)->GetStringLength(env, jstr);
-    const jchar *str = (*env)->GetStringCritical(env, jstr, 0);
-    if (str == 0) {
-        return NULL;
-    }
-
-    result = (char*)malloc(len+1);
-    if (result == 0) {
-        (*env)->ReleaseStringCritical(env, jstr, str);
-        ThrowException(env, "java/lang/OutOfMemoryError", NULL);
-        return NULL;
-    }
-
-    for (i=0; i<len; i++) {
-        jchar unicode = str[i];
-        if (unicode <= 0x00ff)
-            result[i] = unicode;
-        else
-            result[i] = '?';
-    }
-
-    result[len] = 0;
-    (*env)->ReleaseStringCritical(env, jstr, str);
-    return result;
-}
-
-
-/*
- * Class:     Launcher
- * Method:    launch0
- * Signature: ([Ljava/lang/String;I)V
- */
-JNIEXPORT void JNICALL Java_Launcher_launch0
-  (JNIEnv *env, jclass cls, jobjectArray cmdarray, jint serviceFd)
-{
-    pid_t pid;
-    DIR* dp;
-    struct dirent* dirp;
-    int thisFd;
-    char** cmdv;
-    int i, cmdlen;
-
-    /*
-     * Argument 0 of the command array is the program name.
-     * Here we just extract the program name and any arguments into
-     * a command array suitable for use with execvp.
-     */
-    cmdlen = (*env)->GetArrayLength(env, cmdarray);
-    if (cmdlen == 0) {
-        ThrowException(env, "java/lang/IllegalArgumentException",
-            "command array must at least include the program name");
-        return;
-    }
-    cmdv = (char **)malloc((cmdlen + 1) * sizeof(char *));
-    if (cmdv == NULL) {
-        ThrowException(env, "java/lang/OutOfMemoryError", NULL);
-        return;
-    }
-
-    for (i=0; i<cmdlen; i++) {
-        jstring str = (*env)->GetObjectArrayElement(env, cmdarray, i);
-        cmdv[i] = (char *) getString8859_1Chars(env, str);
-        if (cmdv[i] == NULL) {
-            return;
-        }
-    }
-
-    /*
-     * Command array must have NULL as the last entry
-     */
-    cmdv[cmdlen] = NULL;
-
-    /*
-     * Launch the program. As this isn't a complete inetd or Runtime.exec
-     * implementation we don't have a reaper to pick up child exit status.
-     */
-#ifdef __solaris__
-    pid = fork1();
-#else
-    pid = fork();
-#endif
-    if (pid != 0) {
-        if (pid < 0) {
-            ThrowException(env, "java/io/IOException", "fork failed");
-        }
-        return;
-    }
-
-    /*
-     * We need to close all file descriptors except for serviceFd. To
-     * get the list of open file descriptos we read through /proc/self/fd
-     * but to open this requires a file descriptor. We could use a specific
-     * file descriptor and fdopendir but Linux doesn't seem to support
-     * fdopendir. Instead we use opendir and make an assumption on the
-     * file descriptor that is used (by opening & closing a file).
-     */
-    thisFd = open("/dev/null", O_RDONLY);
-    if (thisFd < 0) {
-        _exit(-1);
-    }
-    close(thisFd);
-
-    if ((dp = opendir("/proc/self/fd")) == NULL) {
-        _exit(-1);
-    }
-
-    while ((dirp = readdir(dp)) != NULL) {
-        if (isdigit(dirp->d_name[0])) {
-            int fd = strtol(dirp->d_name, NULL, 10);
-            if (fd != serviceFd && fd != thisFd) {
-                close(fd);
-            }
-        }
-    }
-    closedir(dp);
-
-    /*
-     * At this point all file descriptors are closed except for
-     * serviceFd. We not dup 0,1,2 to this file descriptor and
-     * close serviceFd. This should leave us with only 0,1,2
-     * open and all connected to the same socket.
-     */
-    dup2(serviceFd, STDIN_FILENO);
-    dup2(serviceFd, STDOUT_FILENO);
-    dup2(serviceFd, STDERR_FILENO);
-    close(serviceFd);
-
-    execvp(cmdv[0], cmdv);
-    _exit(-1);
-}
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java	Sun Mar 04 18:46:07 2018 -0800
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java	Mon Mar 05 08:27:42 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@
 public class Launcher {
 
     static {
-        System.loadLibrary("Launcher");
+        System.loadLibrary("InheritedChannel");
     }
 
     private static native void launch0(String cmdarray[], int fd) throws IOException;
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Makefile	Sun Mar 04 18:46:07 2018 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-#
-#
-# Makefile for building libLauncher.so
-#
-# To build libLauncher.so requires :-
-#     JAVA_HOME environment variable 
-#     cc (Solaris) or gcc (Linux) on PATH
-#
-# The library is created in a architecture specific directory :-
-#
-#     lib/solaris-sparc/libLauncher.so	(Solaris/SPARC)
-#     lib/solaris-i586/libLauncher.so	(Solaris/x86)
-#     lib/linux-i586/libLauncher.so	(Linux/x86)
-
-ECHO  = echo
-MKDIR = mkdir
-UNAME = uname
-
-uname := $(shell uname)
-
-ifeq ($(uname), SunOS)
-  PLATFORM = solaris
-  ISAINFO = isainfo
-  ARCH_DATA_MODEL=64
-  ARCH := $(shell $(ISAINFO) -n)
-  CC = cc
-  LD = ld
-  CFLAGS = -D_REENTRANT -D__solaris__
-  LDFLAGS_COMMON = -G
-  EXTRA_LIBS = -lc
-  CC += -m64 -Kpic
-endif
-
-ifeq ($(uname), Linux)
-  PLATFORM = linux
-  archExpr = case "`$(UNAME) -m`" in  \
-		i[3-6]86) \
-                    $(ECHO) i586 \
-                    ;; \
-		sparc*)	 \
-                    $(ECHO) sparc \
-                    ;; \
-		*) \
-                    $(UNAME) -m	 \
-                    ;; \
-	   esac
-  ARCH	    := $(shell $(archExpr) )
-  CC = gcc
-  CFLAGS = -fno-strict-aliasing -fPIC -W -Wall
-  LD = ld
-  LDFLAGS_COMMON = -shared
-  EXTRA_LIBS = -lc
-endif
-
-LIBDIR=lib/$(PLATFORM)-$(ARCH)
-LAUNCHERLIB=$(LIBDIR)/libLauncher.so
-
-all: java_home $(LAUNCHERLIB)
-
-$(LAUNCHERLIB) : $(LIBDIR) $(LIBDIR)/Launcher.o
-	$(LD) $(LDFLAGS_COMMON) -o $(LAUNCHERLIB) $(LIBDIR)/Launcher.o $(EXTRA_LIBS)
-
-$(LIBDIR):
-	@$(MKDIR) -p $(LIBDIR)
-
-$(LIBDIR)/Launcher.o : Launcher.c \
-		       Launcher.h
-	$(CC) -c $(CFLAGS) -o $(LIBDIR)/Launcher.o \
-	    -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM) Launcher.c
-	
-Launcher.class Launcher.h : Launcher.java
-	$(JAVA_HOME)/bin/javac -h . Launcher.java
-
-java_home:
-ifndef JAVA_HOME
-	@$(ECHO) "ERROR: Your JAVA_HOME environment variable is not set."
-	exit 1	
-endif
-
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/README	Sun Mar 04 18:46:07 2018 -0800
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/README	Mon Mar 05 08:27:42 2018 -0800
@@ -1,33 +1,16 @@
-
 The unit tests in this directory depend on a native launcher library
-(libLauncher.so). This native library is built off-line and the
-resulting libLauncher.so for each processor/OS combination is checked
-into the workspace. The reason for this is because the test environment
-may not have the required compilers/build environment.
+(libInheritedChannel.so). This library is built by executing
 
-In order to rebuild libLauncher.so the following is required :-
-
-1. Check-out each of the shared libraries (sccs edit)
+$ make test-image-jdk-jtreg-native
 
-2. Edit Launcher.c with the appropriate changes
-
-3. Execute the make script (gnumake all) on each processor/OS so
-that the appropriate lib/<platform>/libLauncher.so is built.
+in the root directory of the OpenJDK clone. It will generate
+libInheritedChannel.so in two locations:
 
-4. Test the changes
-
-5. Check-in each of the shared library (sccs delget)
-
-
-For step 4 (re-building libLauncher.so) the following environment is required:
+$ $JDK_ROOT/build/$PLATFORM/support/test/jdk/jtreg/native/lib/libInheritedChannel.so
+$ $JDK_ROOT/build/$PLATFORM/images/test/jdk/jtreg/native/libInheritedChannel.so
 
-(a) JAVA_HOME needs to be set to J2SE directory, eg:-
-	export JAVA_HOME=/usr/local/java/jdk1.5/solaris-sparc
+The test may then be run using jtreg for example as follows:
 
-(b) For Solaris the SOS8 'cc' needs to be on the PATH, check using:
-	# cc -V
-	cc: Sun C 5.5 2003/03/12
-
-(c) Execute the make script :-
-	Solaris:	gnumake all
-	Linux:		gmake all
+$ jtreg -s -w:/tmp -r:/tmp -va -dir:$JDK_ROOT/test/jdk \
+-nativepath:$JDK_ROOT/build/$PLATFORM/support/test/jdk/jtreg/native/lib \
+java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java
Binary file test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/linux-i586/libLauncher.so has changed
Binary file test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/solaris-amd64/libLauncher.so has changed
Binary file test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/lib/solaris-sparcv9/libLauncher.so has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/libInheritedChannel.c	Mon Mar 05 08:27:42 2018 -0800
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * A simple launcher to launch a program as if it was launched by inetd.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
+
+#include "jni.h"
+
+/*
+ * Throws the exception of the given class name and detail message
+ */
+static void ThrowException(JNIEnv *env, const char *name, const char *msg) {
+    jclass cls = (*env)->FindClass(env, name);
+    if (cls != NULL) {
+        (*env)->ThrowNew(env, cls, msg);
+    }
+}
+
+/*
+ * Convert a jstring to an ISO 8859_1 encoded C string
+ */
+static char* getString8859_1Chars(JNIEnv *env, jstring jstr) {
+    int i;
+    char *result;
+    jint len = (*env)->GetStringLength(env, jstr);
+    const jchar *str = (*env)->GetStringCritical(env, jstr, 0);
+    if (str == 0) {
+        return NULL;
+    }
+
+    result = (char*)malloc(len+1);
+    if (result == 0) {
+        (*env)->ReleaseStringCritical(env, jstr, str);
+        ThrowException(env, "java/lang/OutOfMemoryError", NULL);
+        return NULL;
+    }
+
+    for (i=0; i<len; i++) {
+        jchar unicode = str[i];
+        if (unicode <= 0x00ff)
+            result[i] = unicode;
+        else
+            result[i] = '?';
+    }
+
+    result[len] = 0;
+    (*env)->ReleaseStringCritical(env, jstr, str);
+    return result;
+}
+
+
+/*
+ * Class:     Launcher
+ * Method:    launch0
+ * Signature: ([Ljava/lang/String;I)V
+ */
+JNIEXPORT void JNICALL Java_Launcher_launch0
+  (JNIEnv *env, jclass cls, jobjectArray cmdarray, jint serviceFd)
+{
+    pid_t pid;
+    DIR* dp;
+    struct dirent* dirp;
+    int thisFd;
+    char** cmdv;
+    int i, cmdlen;
+
+    /*
+     * Argument 0 of the command array is the program name.
+     * Here we just extract the program name and any arguments into
+     * a command array suitable for use with execvp.
+     */
+    cmdlen = (*env)->GetArrayLength(env, cmdarray);
+    if (cmdlen == 0) {
+        ThrowException(env, "java/lang/IllegalArgumentException",
+            "command array must at least include the program name");
+        return;
+    }
+    cmdv = (char **)malloc((cmdlen + 1) * sizeof(char *));
+    if (cmdv == NULL) {
+        ThrowException(env, "java/lang/OutOfMemoryError", NULL);
+        return;
+    }
+
+    for (i=0; i<cmdlen; i++) {
+        jstring str = (*env)->GetObjectArrayElement(env, cmdarray, i);
+        cmdv[i] = (char *) getString8859_1Chars(env, str);
+        if (cmdv[i] == NULL) {
+            return;
+        }
+    }
+
+    /*
+     * Command array must have NULL as the last entry
+     */
+    cmdv[cmdlen] = NULL;
+
+    /*
+     * Launch the program. As this isn't a complete inetd or Runtime.exec
+     * implementation we don't have a reaper to pick up child exit status.
+     */
+#ifdef __solaris__
+    pid = fork1();
+#else
+    pid = fork();
+#endif
+    if (pid != 0) {
+        if (pid < 0) {
+            ThrowException(env, "java/io/IOException", "fork failed");
+        }
+        return;
+    }
+
+    /*
+     * We need to close all file descriptors except for serviceFd. To
+     * get the list of open file descriptos we read through /proc/self/fd
+     * but to open this requires a file descriptor. We could use a specific
+     * file descriptor and fdopendir but Linux doesn't seem to support
+     * fdopendir. Instead we use opendir and make an assumption on the
+     * file descriptor that is used (by opening & closing a file).
+     */
+    thisFd = open("/dev/null", O_RDONLY);
+    if (thisFd < 0) {
+        _exit(-1);
+    }
+    close(thisFd);
+
+    if ((dp = opendir("/proc/self/fd")) == NULL) {
+        _exit(-1);
+    }
+
+    while ((dirp = readdir(dp)) != NULL) {
+        if (isdigit(dirp->d_name[0])) {
+            int fd = strtol(dirp->d_name, NULL, 10);
+            if (fd != serviceFd && fd != thisFd) {
+                close(fd);
+            }
+        }
+    }
+    closedir(dp);
+
+    /*
+     * At this point all file descriptors are closed except for
+     * serviceFd. We not dup 0,1,2 to this file descriptor and
+     * close serviceFd. This should leave us with only 0,1,2
+     * open and all connected to the same socket.
+     */
+    dup2(serviceFd, STDIN_FILENO);
+    dup2(serviceFd, STDOUT_FILENO);
+    dup2(serviceFd, STDERR_FILENO);
+    close(serviceFd);
+
+    execvp(cmdv[0], cmdv);
+    _exit(-1);
+}