提交 9a66f45d 编写于 作者: A avorobye

8071909: Port testlibrary improvments in jdk/test to hotspot/test as required for DCMD test port

Reviewed-by: jbachorik, egahlin, ykantser, mtobiass
上级 ba01cd97
......@@ -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)"));
}
}
......@@ -187,23 +187,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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册