Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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"));