8067808: java/lang/ProcessBuilder/Basic.java failed on Assertion

Change to use javaChild reporting its pid not portable

Reviewed-by: igerasim
This commit is contained in:
Roger Riggs 2015-06-03 18:18:05 -04:00
parent b440bfb8eb
commit afb73945a3

View file

@ -36,6 +36,7 @@
*/ */
import java.lang.ProcessBuilder.Redirect; import java.lang.ProcessBuilder.Redirect;
import java.lang.ProcessHandle;
import static java.lang.ProcessBuilder.Redirect.*; import static java.lang.ProcessBuilder.Redirect.*;
import java.io.*; import java.io.*;
@ -47,7 +48,6 @@ import java.util.*;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.security.*; import java.security.*;
import sun.misc.Unsafe;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import static java.lang.System.getenv; import static java.lang.System.getenv;
@ -309,6 +309,8 @@ public class Basic {
String action = args[0]; String action = args[0];
if (action.equals("sleep")) { if (action.equals("sleep")) {
Thread.sleep(10 * 60 * 1000L); Thread.sleep(10 * 60 * 1000L);
} else if (action.equals("pid")) {
System.out.println(ProcessHandle.current().getPid());
} else if (action.equals("testIO")) { } else if (action.equals("testIO")) {
String expected = "standard input"; String expected = "standard input";
char[] buf = new char[expected.length()+1]; char[] buf = new char[expected.length()+1];
@ -1139,40 +1141,20 @@ public class Basic {
} }
static void checkProcessPid() { static void checkProcessPid() {
long actualPid = 0; ProcessBuilder pb = new ProcessBuilder();
long expectedPid = -1; List<String> list = new ArrayList<String>(javaChildArgs);
if (Windows.is()) { list.add("pid");
String[] argsTasklist = {"tasklist.exe", "/NH", "/FI", "\"IMAGENAME eq tasklist.exe\""}; pb.command(list);
ProcessBuilder pb = new ProcessBuilder(argsTasklist); try {
try { Process p = pb.start();
Process proc = pb.start(); String s = commandOutput(p);
expectedPid = proc.getPid(); long actualPid = Long.valueOf(s.trim());
long expectedPid = p.getPid();
String output = commandOutput(proc); equal(actualPid, expectedPid);
String[] splits = output.split("\\s+"); } catch (Throwable t) {
actualPid = Integer.valueOf(splits[2]); unexpected(t);
} catch (Throwable t) {
unexpected(t);
}
} else if (Unix.is() || MacOSX.is()) {
String[] shArgs = {"sh", "-c", "echo $$"};
ProcessBuilder pb = new ProcessBuilder(shArgs);
try {
Process proc = pb.start();
expectedPid = proc.getPid();
String output = commandOutput(proc);
String[] splits = output.split("\\s+");
actualPid = Integer.valueOf(splits[0]);
} catch (Throwable t) {
unexpected(t);
}
} else {
fail("No test for checkProcessPid on platform: " + System.getProperty("os.name"));
return;
} }
equal(actualPid, expectedPid);
// Test the default implementation of Process.getPid // Test the default implementation of Process.getPid
DelegatingProcess p = new DelegatingProcess(null); DelegatingProcess p = new DelegatingProcess(null);