mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +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.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 proc = pb.start();
|
Process p = pb.start();
|
||||||
expectedPid = proc.getPid();
|
String s = commandOutput(p);
|
||||||
|
long actualPid = Long.valueOf(s.trim());
|
||||||
String output = commandOutput(proc);
|
long expectedPid = p.getPid();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
equal(actualPid, expectedPid);
|
equal(actualPid, expectedPid);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
unexpected(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Test the default implementation of Process.getPid
|
// Test the default implementation of Process.getPid
|
||||||
DelegatingProcess p = new DelegatingProcess(null);
|
DelegatingProcess p = new DelegatingProcess(null);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue