mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
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:
parent
b440bfb8eb
commit
afb73945a3
1 changed files with 15 additions and 33 deletions
|
@ -36,6 +36,7 @@
|
|||
*/
|
||||
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.lang.ProcessHandle;
|
||||
import static java.lang.ProcessBuilder.Redirect.*;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -47,7 +48,6 @@ import java.util.*;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.security.*;
|
||||
import sun.misc.Unsafe;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
import static java.lang.System.getenv;
|
||||
|
@ -309,6 +309,8 @@ public class Basic {
|
|||
String action = args[0];
|
||||
if (action.equals("sleep")) {
|
||||
Thread.sleep(10 * 60 * 1000L);
|
||||
} else if (action.equals("pid")) {
|
||||
System.out.println(ProcessHandle.current().getPid());
|
||||
} else if (action.equals("testIO")) {
|
||||
String expected = "standard input";
|
||||
char[] buf = new char[expected.length()+1];
|
||||
|
@ -1139,40 +1141,20 @@ public class Basic {
|
|||
}
|
||||
|
||||
static void checkProcessPid() {
|
||||
long actualPid = 0;
|
||||
long expectedPid = -1;
|
||||
if (Windows.is()) {
|
||||
String[] argsTasklist = {"tasklist.exe", "/NH", "/FI", "\"IMAGENAME eq tasklist.exe\""};
|
||||
ProcessBuilder pb = new ProcessBuilder(argsTasklist);
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
List<String> list = new ArrayList<String>(javaChildArgs);
|
||||
list.add("pid");
|
||||
pb.command(list);
|
||||
try {
|
||||
Process proc = pb.start();
|
||||
expectedPid = proc.getPid();
|
||||
|
||||
String output = commandOutput(proc);
|
||||
String[] splits = output.split("\\s+");
|
||||
actualPid = Integer.valueOf(splits[2]);
|
||||
} 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;
|
||||
}
|
||||
|
||||
Process p = pb.start();
|
||||
String s = commandOutput(p);
|
||||
long actualPid = Long.valueOf(s.trim());
|
||||
long expectedPid = p.getPid();
|
||||
equal(actualPid, expectedPid);
|
||||
} catch (Throwable t) {
|
||||
unexpected(t);
|
||||
}
|
||||
|
||||
|
||||
// Test the default implementation of Process.getPid
|
||||
DelegatingProcess p = new DelegatingProcess(null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue