aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Weijun Wang <weijun@openjdk.org> 2021-04-15 15:07:47 +0000
committerGravatar Weijun Wang <weijun@openjdk.org> 2021-04-15 15:07:47 +0000
commitc70589c68c09d3089b69b46a83c97fb9e86fff42 (patch)
tree21039fdd63cf2d31aab46e92cdbcffae33a435cd
parent7b61a426e0837bde4885bd53397bba6b0939382f (diff)
downloadjdk-c70589c68c09d3089b69b46a83c97fb9e86fff42.tar.gz
jdk-c70589c68c09d3089b69b46a83c97fb9e86fff42.zip
8265227: Move Proc.java from security/testlibrary to test/lib
Reviewed-by: rriggs, xuelei, rhalade, ssahoo
-rw-r--r--test/jdk/sun/security/krb5/auto/BasicProc.java3
-rw-r--r--test/jdk/sun/security/krb5/auto/Renewal.java4
-rw-r--r--test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java3
-rw-r--r--test/jdk/sun/security/krb5/auto/ReplayCacheTestProcWithMD5.java2
-rw-r--r--test/jdk/sun/security/krb5/ccache/EmptyCC.java7
-rw-r--r--test/jdk/sun/security/util/FilePermCompat/CompatImpact.java5
-rw-r--r--test/jdk/sun/security/util/FilePermCompat/Flag.java4
-rw-r--r--test/lib-test/jdk/test/lib/process/ProcTest.java81
-rw-r--r--test/lib/jdk/test/lib/process/Proc.java (renamed from test/jdk/java/security/testlibrary/Proc.java)24
9 files changed, 110 insertions, 23 deletions
diff --git a/test/jdk/sun/security/krb5/auto/BasicProc.java b/test/jdk/sun/security/krb5/auto/BasicProc.java
index 9e681af03de..0ba0b907b77 100644
--- a/test/jdk/sun/security/krb5/auto/BasicProc.java
+++ b/test/jdk/sun/security/krb5/auto/BasicProc.java
@@ -26,7 +26,7 @@
* @bug 8009977 8186884 8194486 8201627
* @summary A test to launch multiple Java processes using either Java GSS
* or native GSS
- * @library ../../../../java/security/testlibrary/ /test/lib
+ * @library /test/lib
* @compile -XDignore.symbol.file BasicProc.java
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
* @run main/othervm -Djdk.net.hosts.file=TestHosts BasicProc launcher
@@ -41,6 +41,7 @@ import java.util.Set;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
+import jdk.test.lib.process.Proc;
import org.ietf.jgss.Oid;
import sun.security.krb5.Config;
diff --git a/test/jdk/sun/security/krb5/auto/Renewal.java b/test/jdk/sun/security/krb5/auto/Renewal.java
index 1d0417f89e5..c90ff4acaeb 100644
--- a/test/jdk/sun/security/krb5/auto/Renewal.java
+++ b/test/jdk/sun/security/krb5/auto/Renewal.java
@@ -26,19 +26,19 @@
* @bug 8044500 8194486
* @summary Add kinit options and krb5.conf flags that allow users to
* obtain renewable tickets and specify ticket lifetimes
- * @library ../../../../java/security/testlibrary/ /test/lib
+ * @library /test/lib
* @compile -XDignore.symbol.file Renewal.java
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
* @run main/othervm -Djdk.net.hosts.file=TestHosts Renewal
*/
+import jdk.test.lib.process.Proc;
import sun.security.krb5.Config;
import sun.security.krb5.internal.ccache.Credentials;
import sun.security.krb5.internal.ccache.FileCredentialsCache;
import javax.security.auth.kerberos.KerberosTicket;
import java.util.Date;
-import java.util.Random;
import java.util.Set;
// The basic krb5 test skeleton you can copy from
diff --git a/test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java b/test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java
index ae71fc04b0f..e0dfaa541c4 100644
--- a/test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java
+++ b/test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java
@@ -25,7 +25,7 @@
* @test
* @bug 7152176 8168518 8172017 8014628 8194486
* @summary More krb5 tests
- * @library ../../../../java/security/testlibrary/ /test/lib
+ * @library /test/lib
* @build jdk.test.lib.Platform
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
* @run main/othervm/timeout=300 -Djdk.net.hosts.file=TestHosts
@@ -49,6 +49,7 @@ import java.util.regex.Pattern;
import jdk.test.lib.Asserts;
import jdk.test.lib.Platform;
+import jdk.test.lib.process.Proc;
import sun.security.jgss.GSSUtil;
import sun.security.krb5.internal.rcache.AuthTime;
diff --git a/test/jdk/sun/security/krb5/auto/ReplayCacheTestProcWithMD5.java b/test/jdk/sun/security/krb5/auto/ReplayCacheTestProcWithMD5.java
index 0ce649ef4d6..5f2f4bbeca3 100644
--- a/test/jdk/sun/security/krb5/auto/ReplayCacheTestProcWithMD5.java
+++ b/test/jdk/sun/security/krb5/auto/ReplayCacheTestProcWithMD5.java
@@ -27,7 +27,7 @@
* @summary testing jdk.krb5.rcache.useMD5. This action is put in a separate
* test so that ReplayCacheTestProc.java can be launched with special
* test.* system properties easily.
- * @library ../../../../java/security/testlibrary/ /test/lib
+ * @library /test/lib
* @build jdk.test.lib.Platform
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
* @run main/othervm/timeout=300 -Djdk.krb5.rcache.useMD5=true
diff --git a/test/jdk/sun/security/krb5/ccache/EmptyCC.java b/test/jdk/sun/security/krb5/ccache/EmptyCC.java
index d5cfc4d557f..1faceadb0d7 100644
--- a/test/jdk/sun/security/krb5/ccache/EmptyCC.java
+++ b/test/jdk/sun/security/krb5/ccache/EmptyCC.java
@@ -26,15 +26,16 @@
* @bug 7158329
* @bug 8001208
* @summary NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
- * @library ../../../../java/security/testlibrary/
- * @modules java.base/jdk.internal.misc
- * java.security.jgss/sun.security.krb5
+ * @library /test/lib
+ * @modules java.security.jgss/sun.security.krb5
* java.security.jgss/sun.security.krb5.internal.ccache
* @compile -XDignore.symbol.file EmptyCC.java
* @run main EmptyCC tmpcc
* @run main EmptyCC FILE:tmpcc
*/
import java.io.File;
+
+import jdk.test.lib.process.Proc;
import sun.security.krb5.Credentials;
import sun.security.krb5.PrincipalName;
import sun.security.krb5.internal.ccache.CredentialsCache;
diff --git a/test/jdk/sun/security/util/FilePermCompat/CompatImpact.java b/test/jdk/sun/security/util/FilePermCompat/CompatImpact.java
index eb46435b7e9..edf48e0d6b0 100644
--- a/test/jdk/sun/security/util/FilePermCompat/CompatImpact.java
+++ b/test/jdk/sun/security/util/FilePermCompat/CompatImpact.java
@@ -25,8 +25,7 @@
* @test
* @bug 8164705 8168410
* @summary check compatibility after FilePermission change
- * @library /java/security/testlibrary/
- * @modules java.base/jdk.internal.misc
+ * @library /test/lib
* @run main CompatImpact prepare
* @run main CompatImpact builtin
* @run main/othervm -Djdk.security.filePermCompat=true CompatImpact mine
@@ -34,6 +33,8 @@
* @run main CompatImpact dopriv
*/
+import jdk.test.lib.process.Proc;
+
import java.io.File;
import java.io.FilePermission;
import java.nio.file.Files;
diff --git a/test/jdk/sun/security/util/FilePermCompat/Flag.java b/test/jdk/sun/security/util/FilePermCompat/Flag.java
index 00c7fbc2677..eb52fc6f774 100644
--- a/test/jdk/sun/security/util/FilePermCompat/Flag.java
+++ b/test/jdk/sun/security/util/FilePermCompat/Flag.java
@@ -24,11 +24,11 @@
/*
* @test
* @bug 8164705 8209901
- * @library /test/jdk/java/security/testlibrary
- * @modules java.base/jdk.internal.misc
+ * @library /test/lib
* @summary check jdk.filepermission.canonicalize
*/
+import jdk.test.lib.process.Proc;
import java.io.File;
import java.io.FilePermission;
import java.lang.*;
diff --git a/test/lib-test/jdk/test/lib/process/ProcTest.java b/test/lib-test/jdk/test/lib/process/ProcTest.java
new file mode 100644
index 00000000000..e64567cdccb
--- /dev/null
+++ b/test/lib-test/jdk/test/lib/process/ProcTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021, 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 8265227
+ * @summary Test Proc
+ * @library /test/lib
+ */
+
+import jdk.test.lib.process.Proc;
+
+import java.util.Random;
+import java.util.List;
+
+public class ProcTest {
+ public static void main(String[] args) throws Exception {
+ if (args.length == 0) {
+ Proc p1 = Proc.create("ProcTest")
+ .args("p1")
+ .debug("p1")
+ .start();
+ Proc p2 = Proc.create("ProcTest")
+ .args("p2")
+ .debug("p2")
+ .start();
+ while (true) {
+ String s1 = p1.readData(); // p1 shows to p2
+ if (s1 != null) p2.println(s1);
+ String s2 = p2.readData(); // p2 shows to p1
+ if (s2 != null) p1.println(s2);
+ if (s1 == null && s2 == null) break;
+ }
+ p1.waitFor();
+ p2.waitFor();
+ } else {
+ List<String> gestures = List.of("Rock", "Paper", "Scissors");
+ int wins = 0;
+ Random r = new Random();
+ while (true) {
+ String my = gestures.get(r.nextInt(3));
+ Proc.textOut(my); // show first, next line might block
+ String peer = Proc.textIn();
+ if (!my.equals(peer)) {
+ if (my.equals("Paper") && peer.equals("Rock")
+ || my.equals("Rock") && peer.equals("Scissors")
+ || my.equals("Scissors") && peer.equals("Paper")) {
+ wins++;
+ } else {
+ wins--;
+ }
+ }
+ // Message not from textOut() will be ignored by readData().
+ System.out.println(my + " vs " + peer + ", I win " + wins + " times");
+ if (wins > 2 || wins < -2) {
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/test/jdk/java/security/testlibrary/Proc.java b/test/lib/jdk/test/lib/process/Proc.java
index cff7e790e7e..def8796fce8 100644
--- a/test/jdk/java/security/testlibrary/Proc.java
+++ b/test/lib/jdk/test/lib/process/Proc.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2021, 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
@@ -21,6 +21,8 @@
* questions.
*/
+package jdk.test.lib.process;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -42,7 +44,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
* This is a test library that makes writing a Java test that spawns multiple
@@ -260,23 +261,24 @@ public class Proc {
// Starts the proc
public Proc start() throws IOException {
List<String> cmd = new ArrayList<>();
- boolean hasModules;
if (launcher != null) {
cmd.add(launcher);
File base = new File(launcher).getParentFile().getParentFile();
- hasModules = new File(base, "modules").exists() ||
- new File(base, "jmods").exists();
} else {
cmd.add(new File(new File(System.getProperty("java.home"), "bin"),
"java").getPath());
- hasModules = true;
}
- if (hasModules) {
- Stream.of(jdk.internal.misc.VM.getRuntimeArguments())
- .filter(arg -> arg.startsWith("--add-exports=") ||
- arg.startsWith("--add-opens="))
- .forEach(cmd::add);
+ String testModules = System.getProperty("test.modules");
+ if (testModules != null) {
+ for (String module : testModules.split("\\s+")) {
+ if (module.endsWith(":+open")) {
+ String realModule = module.substring(0, module.length() - 6);
+ cmd.add("--add-opens=" + realModule + "=ALL-UNNAMED");
+ } else if (module.contains("/")) {
+ cmd.add("--add-exports=" + module + "=ALL-UNNAMED");
+ }
+ }
}
Collections.addAll(cmd, splitProperty("test.vm.opts"));