8182465: Refactor shell test java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh to java
Reviewed-by: alanb
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/CloseTest.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/CloseTest.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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,9 @@
* peer has closed the connection) in less than 15 seconds.
*/
import java.nio.ByteBuffer;
-import java.nio.channels.*;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
public class CloseTest {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoService.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoService.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -55,10 +55,15 @@
* facilate testing that the channel is closed the "tcp nowait" service
* can close the connection after a given number of bytes.
*/
-import java.nio.*;
-import java.nio.channels.*;
import java.io.IOException;
-import java.net.*;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
public class EchoService {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoTest.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/EchoTest.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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,10 +35,13 @@
* the packet is correctly echoed.
*
*/
-import java.net.*;
-import java.io.*;
+import java.io.IOException;
+import java.net.DatagramPacket;
import java.nio.ByteBuffer;
-import java.nio.channels.*;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
import java.util.Random;
public class EchoTest {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java Wed Jun 21 14:40:38 2017 +0800
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+
+/*
+ * @test
+ * @bug 4673940 4930794
+ * @summary Unit tests for inetd feature
+ * @requires (os.family == "linux" | os.family == "solaris")
+ * @library /test/lib
+ * @build jdk.test.lib.Utils
+ * jdk.test.lib.Asserts
+ * jdk.test.lib.JDKToolFinder
+ * jdk.test.lib.JDKToolLauncher
+ * jdk.test.lib.Platform
+ * jdk.test.lib.process.*
+ * StateTest StateTestService EchoTest EchoService CloseTest Launcher Util
+ * @run testng/othervm InheritedChannelTest
+ * @key intermittent
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.Utils;
+import jdk.test.lib.process.ProcessTools;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static java.util.Arrays.asList;
+
+public class InheritedChannelTest {
+
+ private static final String TEST_SRC = System.getProperty("test.src");
+ private static final String TEST_CLASSES = System.getProperty("test.classes");
+ private static final Path POLICY_PASS = Paths.get(TEST_SRC, "java.policy.pass");
+ private static final Path POLICY_FAIL = Paths.get(TEST_SRC, "java.policy.fail");
+
+ private static final String OS = System.getProperty("os.name").toLowerCase();
+ private static final String OS_NAME = OS.startsWith("sunos") ? "solaris" : OS;
+
+ private static final String ARCH = System.getProperty("os.arch");
+ 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");
+
+ @DataProvider
+ public Object[][] testCases() {
+ return new Object[][]{
+ { "StateTest", List.of(StateTest.class.getName()) },
+ { "EchoTest", List.of(EchoTest.class.getName()) },
+ { "CloseTest", List.of(CloseTest.class.getName()) },
+
+ // run StateTest with a SecurityManager set
+ // Note that the system properties are arguments to StateTest and not options.
+ // These system properties are passed to the launched service as options:
+ // java [-options] class [args...]
+ { "StateTest run with " + POLICY_PASS, List.of(StateTest.class.getName(),
+ "-Djava.security.manager",
+ "-Djava.security.policy="
+ + POLICY_PASS)
+ },
+ { "StateTest run with " + POLICY_FAIL, List.of(StateTest.class.getName(),
+ "-expectFail",
+ "-Djava.security.manager",
+ "-Djava.security.policy="
+ + POLICY_FAIL)
+ }
+ };
+ }
+
+ @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<>();
+ args.add(JDKToolFinder.getJDKTool("java"));
+ args.addAll(asList(Utils.getTestJavaOpts()));
+ args.addAll(List.of("--add-opens", "java.base/java.io=ALL-UNNAMED",
+ "--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED"));
+ args.addAll(opts);
+
+ ProcessBuilder pb = new ProcessBuilder(args);
+
+ Map<String, String> env = pb.environment();
+ env.put("CLASSPATH", TEST_CLASSES);
+ env.put("LD_LIBRARY_PATH", LD_LIBRARY_PATH.toString());
+
+ ProcessTools.executeCommand(pb)
+ .shouldHaveExitValue(0);
+ }
+}
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -25,9 +25,12 @@
* A Launcher to launch a java process with its standard input, output,
* and error streams connected to a socket.
*/
-import java.net.*;
-import java.nio.channels.*;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
public class Launcher {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTest.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTest.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -33,10 +33,14 @@
* socket state and replies back to this class via an out-of-band
* channel.
*/
-import java.io.*;
-import java.net.*;
+import java.io.IOException;
+import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
-import java.nio.channels.*;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
public class StateTest {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTestService.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTestService.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -37,11 +37,14 @@
* establishes a TCP connection to the port and sends a PASSED/FAILED
* message to indicate the test result.
*/
-import java.nio.*;
-import java.nio.channels.*;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
public class StateTestService {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/Util.java Wed Jun 21 12:09:25 2017 +0800
+++ b/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/Util.java Wed Jun 21 14:40:38 2017 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -25,10 +25,12 @@
* A collection of utility methods used by the SelectorProvider.inheritedChannel
* unit tests.
*/
-import java.net.*;
-import java.io.*;
-import java.nio.channels.*;
-import java.lang.reflect.*;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.lang.reflect.Field;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
public class Util {
--- a/jdk/test/java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh Wed Jun 21 12:09:25 2017 +0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2003, 2013, 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.
-#
-
-# @test
-# @bug 4673940 4930794
-# @summary Unit tests for inetd feature
-#
-# @build StateTest StateTestService EchoTest EchoService CloseTest Launcher Util
-# @run shell run_tests.sh
-# @key intermittent
-
-os=`uname -s`
-
-if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
- echo "Test not designed to run on this operating system, skipping..."
- exit 0
-fi
-
-# if TESTJAVA isn't set then we assume an interactive run. So that it's
-# clear which version of 'java' is running we do a 'which java' and
-# a 'java -version'.
-
-if [ -z "$TESTJAVA" ]; then
- TESTSRC=`pwd`
- TESTCLASSES=`pwd`
- JAVA=java
- which $JAVA
- ${JAVA} -version
-else
- JAVA="${TESTJAVA}/bin/java"
-fi
-
-CLASSPATH=${TESTCLASSES}
-export CLASSPATH
-
-
-# Check that we have libLauncher.so for the right platform.
-# On Solaris we assume 64-bit
-
-DFLAG=
-if [ "$os" = "SunOS" ]; then
- PLATFORM=solaris
- case "`uname -p`" in
- i[3-9]86)
- ARCH=amd64
- ;;
- sparc)
- ARCH=sparcv9
- ;;
- esac
-fi
-
-if [ "$os" = "Linux" ]; then
- PLATFORM=linux
- ARCH=unknown
- case "`uname -m`" in
- i[3-6]86)
- ARCH=i586
- ;;
- ia64)
- ARCH=ia64
- ;;
- x86_64)
- ARCH=amd64
- ;;
- esac
-fi
-
-LIBDIR=lib/${PLATFORM}-${ARCH}
-LAUNCHERLIB=${LIBDIR}/libLauncher.so
-echo $LIBDIR
-
-if [ ! -f "${TESTSRC}/${LAUNCHERLIB}" ]; then
- echo "Cannot find ${LAUNCHERLIB} - library not available for this system"
- exit 0
-fi
-
-LD_LIBRARY_PATH=${TESTSRC}/${LIBDIR}
-export LD_LIBRARY_PATH
-
-failures=0
-
-go() {
- echo ''
- sh -xc "$JAVA ${TESTVMOPTS} --add-opens java.base/java.io=ALL-UNNAMED \
- --add-opens java.base/sun.nio.ch=ALL-UNNAMED $DFLAG \
- $1 $2 $3 $4 $5 $6 $7 $8" 2>&1
- if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
-}
-
-# Run the tests
-
-go StateTest
-go EchoTest
-go CloseTest
-
-# Re-run StateTest with a SecurityManager set
-# Note that the system properties are arguments to StateTest and not options.
-# These system properties are passed to the launched service as options:
-# java [-options] class [args...]
-
-go StateTest -Djava.security.manager -Djava.security.policy=${TESTSRC}/java.policy.pass
-go StateTest -expectFail -Djava.security.manager -Djava.security.policy=${TESTSRC}/java.policy.fail
-
-
-#
-# Results
-#
-echo ''
-if [ $failures -gt 0 ];
- then echo "$failures test(s) failed";
- else echo "All test(s) passed"; fi
-exit $failures