Skip to content

Commit 0abbfb2

Browse files
author
Roger Riggs
committedMar 22, 2021
8263729: [test] divert spurious output away from stream under test in ProcessBuilder Basic test
Reviewed-by: stuefe, iklam
1 parent 6c2220e commit 0abbfb2

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed
 

‎test/jdk/java/lang/ProcessBuilder/Basic.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
2727
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
2828
* 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
2929
* 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
30-
* 8067796 8224905
30+
* 8067796 8224905 8263729
3131
* @key intermittent
3232
* @summary Basic tests for Process and Environment Variable code
3333
* @modules java.base/java.lang:open
@@ -2135,10 +2135,34 @@ public void doIt(Map<String,String> environ) {
21352135
final int cases = 4;
21362136
for (int i = 0; i < cases; i++) {
21372137
final int action = i;
2138-
List<String> childArgs = new ArrayList<String>(javaChildArgs);
2138+
List<String> childArgs = new ArrayList<>(javaChildArgs);
2139+
final ProcessBuilder pb = new ProcessBuilder(childArgs);
2140+
{
2141+
// Redirect any child VM error output away from the stream being tested
2142+
// and to the log file. For background see:
2143+
// 8231297: java/lang/ProcessBuilder/Basic.java test fails intermittently
2144+
// Destroying the process may, depending on the timing, cause some output
2145+
// from the child VM.
2146+
// This test requires the thread reading from the subprocess be blocked
2147+
// in the read from the subprocess; there should be no bytes to read.
2148+
// Modify the argument list shared with ProcessBuilder to redirect VM output.
2149+
assert (childArgs.get(1).equals("-XX:+DisplayVMOutputToStderr")) : "Expected arg 1 to be \"-XX:+DisplayVMOutputToStderr\"";
2150+
switch (action & 0x1) {
2151+
case 0:
2152+
childArgs.set(1, "-XX:+DisplayVMOutputToStderr");
2153+
pb.redirectError(INHERIT);
2154+
break;
2155+
case 1:
2156+
childArgs.set(1, "-XX:+DisplayVMOutputToStdout");
2157+
pb.redirectOutput(INHERIT);
2158+
break;
2159+
default:
2160+
throw new Error();
2161+
}
2162+
}
21392163
childArgs.add("sleep");
21402164
final byte[] bytes = new byte[10];
2141-
final Process p = new ProcessBuilder(childArgs).start();
2165+
final Process p = pb.start();
21422166
final CountDownLatch latch = new CountDownLatch(1);
21432167
final InputStream s;
21442168
switch (action & 0x1) {

0 commit comments

Comments
 (0)
Please sign in to comment.