Skip to content
Permalink
Browse files
8265227: Move Proc.java from security/testlibrary to test/lib
Reviewed-by: rriggs, xuelei, rhalade, ssahoo
  • Loading branch information
wangweij committed Apr 15, 2021
1 parent 7b61a42 commit c70589c68c09d3089b69b46a83c97fb9e86fff42
@@ -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 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;

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

@@ -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
@@ -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;
@@ -25,15 +25,16 @@
* @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
* @run main/fail CompatImpact mine
* @run main CompatImpact dopriv
*/

import jdk.test.lib.process.Proc;

import java.io.File;
import java.io.FilePermission;
import java.nio.file.Files;
@@ -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.*;
@@ -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;
}
}
}
}
}
@@ -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.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 Proc grant(String v) {
// 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"));

1 comment on commit c70589c

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on c70589c Apr 15, 2021

Please sign in to comment.