8265227: Move Proc.java from security/testlibrary to test/lib

Reviewed-by: rriggs, xuelei, rhalade, ssahoo
This commit is contained in:
Weijun Wang 2021-04-15 15:07:47 +00:00
parent 7b61a426e0
commit c70589c68c
9 changed files with 110 additions and 23 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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.*;

View File

@ -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;
}
}
}
}
}

View File

@ -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"));