|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
27 | 27 | * 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
|
28 | 28 | * 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
|
29 | 29 | * 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
|
30 |
| - * 8067796 8224905 |
| 30 | + * 8067796 8224905 8263729 |
31 | 31 | * @key intermittent
|
32 | 32 | * @summary Basic tests for Process and Environment Variable code
|
33 | 33 | * @modules java.base/java.lang:open
|
@@ -2135,10 +2135,34 @@ public void doIt(Map<String,String> environ) {
|
2135 | 2135 | final int cases = 4;
|
2136 | 2136 | for (int i = 0; i < cases; i++) {
|
2137 | 2137 | 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 | + } |
2139 | 2163 | childArgs.add("sleep");
|
2140 | 2164 | final byte[] bytes = new byte[10];
|
2141 |
| - final Process p = new ProcessBuilder(childArgs).start(); |
| 2165 | + final Process p = pb.start(); |
2142 | 2166 | final CountDownLatch latch = new CountDownLatch(1);
|
2143 | 2167 | final InputStream s;
|
2144 | 2168 | switch (action & 0x1) {
|
|
0 commit comments