mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 04:24:49 +02:00
8071909: Port testlibrary improvments in jdk/test to hotspot/test as required for DCMD test port
Reviewed-by: jbachorik, egahlin, ykantser, mtobiass
This commit is contained in:
parent
8563f899e6
commit
353ca5002c
2 changed files with 97 additions and 16 deletions
|
@ -24,6 +24,8 @@
|
|||
package com.oracle.java.testlibrary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -69,6 +71,58 @@ public final class OutputAnalyzer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Verify that the stdout contents of output buffer is empty
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If stdout was not empty
|
||||
*/
|
||||
public void stdoutShouldBeEmpty() {
|
||||
if (!getStdout().isEmpty()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("stdout was not empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stderr contents of output buffer is empty
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If stderr was not empty
|
||||
*/
|
||||
public void stderrShouldBeEmpty() {
|
||||
if (!getStderr().isEmpty()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("stderr was not empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stdout contents of output buffer is not empty
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If stdout was empty
|
||||
*/
|
||||
public void stdoutShouldNotBeEmpty() {
|
||||
if (getStdout().isEmpty()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("stdout was empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stderr contents of output buffer is not empty
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* If stderr was empty
|
||||
*/
|
||||
public void stderrShouldNotBeEmpty() {
|
||||
if (getStderr().isEmpty()) {
|
||||
reportDiagnosticSummary();
|
||||
throw new RuntimeException("stderr was empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the stdout and stderr contents of output buffer contains the string
|
||||
*
|
||||
* @param expectedString String that buffer should contain
|
||||
|
@ -365,4 +419,18 @@ public final class OutputAnalyzer {
|
|||
public int getExitValue() {
|
||||
return exitValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of the output buffer (stdout and stderr) as list of strings.
|
||||
* Output will be split by newlines.
|
||||
*
|
||||
* @return Contents of the output buffer as list of strings
|
||||
*/
|
||||
public List<String> asLines() {
|
||||
return asLines(getOutput());
|
||||
}
|
||||
|
||||
private List<String> asLines(String buffer) {
|
||||
return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,23 +184,36 @@ public final class ProcessTools {
|
|||
return executeProcess(pb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a process, waits for it to finish and returns the process output.
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
* @return The output from the process.
|
||||
*/
|
||||
public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable {
|
||||
OutputAnalyzer output = null;
|
||||
try {
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
return output;
|
||||
} catch (Throwable t) {
|
||||
System.out.println("executeProcess() failed: " + t);
|
||||
throw t;
|
||||
} finally {
|
||||
System.out.println(getProcessLog(pb, output));
|
||||
/**
|
||||
* Executes a process, waits for it to finish and returns the process output.
|
||||
* The process will have exited before this method returns.
|
||||
* @param pb The ProcessBuilder to execute.
|
||||
* @return The {@linkplain OutputAnalyzer} instance wrapping the process.
|
||||
*/
|
||||
public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception {
|
||||
OutputAnalyzer output = null;
|
||||
Process p = null;
|
||||
boolean failed = false;
|
||||
try {
|
||||
p = pb.start();
|
||||
output = new OutputAnalyzer(p);
|
||||
p.waitFor();
|
||||
|
||||
return output;
|
||||
} catch (Throwable t) {
|
||||
if (p != null) {
|
||||
p.destroyForcibly().waitFor();
|
||||
}
|
||||
|
||||
failed = true;
|
||||
System.out.println("executeProcess() failed: " + t);
|
||||
throw t;
|
||||
} finally {
|
||||
if (failed) {
|
||||
System.err.println(getProcessLog(pb, output));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a process, waits for it to finish and returns the process output.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue