提交 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 @@ ...@@ -24,6 +24,8 @@
package com.oracle.java.testlibrary; package com.oracle.java.testlibrary;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -69,6 +71,58 @@ public final class OutputAnalyzer { ...@@ -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 * Verify that the stdout and stderr contents of output buffer contains the string
* *
* @param expectedString String that buffer should contain * @param expectedString String that buffer should contain
...@@ -365,4 +419,18 @@ public final class OutputAnalyzer { ...@@ -365,4 +419,18 @@ public final class OutputAnalyzer {
public int getExitValue() { public int getExitValue() {
return exitValue; 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 { ...@@ -187,23 +187,36 @@ public final class ProcessTools {
return executeProcess(pb); return executeProcess(pb);
} }
/** /**
* Executes a process, waits for it to finish and returns the process output. * Executes a process, waits for it to finish and returns the process output.
* @param pb The ProcessBuilder to execute. * The process will have exited before this method returns.
* @return The output from the process. * @param pb The ProcessBuilder to execute.
*/ * @return The {@linkplain OutputAnalyzer} instance wrapping the process.
public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable { */
OutputAnalyzer output = null; public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception {
try { OutputAnalyzer output = null;
output = new OutputAnalyzer(pb.start()); Process p = null;
return output; boolean failed = false;
} catch (Throwable t) { try {
System.out.println("executeProcess() failed: " + t); p = pb.start();
throw t; output = new OutputAnalyzer(p);
} finally { p.waitFor();
System.out.println(getProcessLog(pb, output));
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. * 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.
先完成此消息的编辑!
想要评论请 注册