The
ProcessTools.startProcess(...)
drains output streams and it might cause problems for tests trying to read output for this process.
The possible solution would be either to try to duplicate streams for ProcessImpl created with ProcessTools.startProcess(...) or to explicitly throw exception.
Also, it might be required to fix all tests with the pattern:
Process p = ProcessTools.startProcess("..");
p.waitFor();
OutputAnalyzer out = new OutputAnalyzer(p);
Here is the example of the problem:
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class Main {
public static void main(String[] args) throws Exception {
if (args.length > 0) {
System.out.print(args[0]);
return;
}
// Needed to set property if run without using jtreg.
System.setProperty("test.jdk", "/Users/lmesnik/tools/jdk-19/macosx-x64");
{
Process p = ProcessTools.createJavaProcessBuilder(Main.class.getName(), "ARG1\n").start();
p.waitFor();
OutputAnalyzer out = new OutputAnalyzer(p);
out.reportDiagnosticSummary();
}
{
Process p = ProcessTools.startProcess("process",ProcessTools.createJavaProcessBuilder(Main.class.getName(), "ARG2\n"));
p.waitFor();
OutputAnalyzer out = new OutputAnalyzer(p);
out.reportDiagnosticSummary();
}
}
}
The ouput:
Command line: [/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG1
]
[2023-03-06T22:57:45.968145Z] Gathering output for process 28704
[2023-03-06T22:57:46.004649Z] Waiting for completion for process 28704
[2023-03-06T22:57:46.004776Z] Waiting for completion finished for process 28704
Command line: [/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG2
]
[process]:/Users/lmesnik/tools/jdk-19/macosx-x64/bin/java -cp /Users/lmesnik/IdeaProjects/tests/out/production/tests Main ARG2
[2023-03-06T22:57:46.019328Z] Gathering output for process 28705
stdout: [ARG1
];
stderr: []
exitValue = 0
[process] ARG2
[2023-03-06T22:57:46.108352Z] Waiting for completion for process 28705
[2023-03-06T22:57:46.108643Z] Waiting for completion finished for process 28705
stdout: [];
stderr: []
exitValue = 0