Wed, 06 Jul 2016 17:06:08 +0300
8071909: Port testlibrary improvments in jdk/test to hotspot/test as required for DCMD test port
Reviewed-by: jbachorik, egahlin, ykantser, mtobiass
1.1 --- a/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java Fri Jul 08 13:59:32 2016 +0100 1.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java Wed Jul 06 17:06:08 2016 +0300 1.3 @@ -24,6 +24,8 @@ 1.4 package com.oracle.java.testlibrary; 1.5 1.6 import java.io.IOException; 1.7 +import java.util.Arrays; 1.8 +import java.util.List; 1.9 import java.util.regex.Matcher; 1.10 import java.util.regex.Pattern; 1.11 1.12 @@ -69,6 +71,58 @@ 1.13 } 1.14 1.15 /** 1.16 + * Verify that the stdout contents of output buffer is empty 1.17 + * 1.18 + * @throws RuntimeException 1.19 + * If stdout was not empty 1.20 + */ 1.21 + public void stdoutShouldBeEmpty() { 1.22 + if (!getStdout().isEmpty()) { 1.23 + reportDiagnosticSummary(); 1.24 + throw new RuntimeException("stdout was not empty"); 1.25 + } 1.26 + } 1.27 + 1.28 + /** 1.29 + * Verify that the stderr contents of output buffer is empty 1.30 + * 1.31 + * @throws RuntimeException 1.32 + * If stderr was not empty 1.33 + */ 1.34 + public void stderrShouldBeEmpty() { 1.35 + if (!getStderr().isEmpty()) { 1.36 + reportDiagnosticSummary(); 1.37 + throw new RuntimeException("stderr was not empty"); 1.38 + } 1.39 + } 1.40 + 1.41 + /** 1.42 + * Verify that the stdout contents of output buffer is not empty 1.43 + * 1.44 + * @throws RuntimeException 1.45 + * If stdout was empty 1.46 + */ 1.47 + public void stdoutShouldNotBeEmpty() { 1.48 + if (getStdout().isEmpty()) { 1.49 + reportDiagnosticSummary(); 1.50 + throw new RuntimeException("stdout was empty"); 1.51 + } 1.52 + } 1.53 + 1.54 + /** 1.55 + * Verify that the stderr contents of output buffer is not empty 1.56 + * 1.57 + * @throws RuntimeException 1.58 + * If stderr was empty 1.59 + */ 1.60 + public void stderrShouldNotBeEmpty() { 1.61 + if (getStderr().isEmpty()) { 1.62 + reportDiagnosticSummary(); 1.63 + throw new RuntimeException("stderr was empty"); 1.64 + } 1.65 + } 1.66 + 1.67 + /** 1.68 * Verify that the stdout and stderr contents of output buffer contains the string 1.69 * 1.70 * @param expectedString String that buffer should contain 1.71 @@ -365,4 +419,18 @@ 1.72 public int getExitValue() { 1.73 return exitValue; 1.74 } 1.75 + 1.76 + /** 1.77 + * Get the contents of the output buffer (stdout and stderr) as list of strings. 1.78 + * Output will be split by newlines. 1.79 + * 1.80 + * @return Contents of the output buffer as list of strings 1.81 + */ 1.82 + public List<String> asLines() { 1.83 + return asLines(getOutput()); 1.84 + } 1.85 + 1.86 + private List<String> asLines(String buffer) { 1.87 + return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)")); 1.88 + } 1.89 }
2.1 --- a/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Fri Jul 08 13:59:32 2016 +0100 2.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java Wed Jul 06 17:06:08 2016 +0300 2.3 @@ -187,23 +187,36 @@ 2.4 return executeProcess(pb); 2.5 } 2.6 2.7 - /** 2.8 - * Executes a process, waits for it to finish and returns the process output. 2.9 - * @param pb The ProcessBuilder to execute. 2.10 - * @return The output from the process. 2.11 - */ 2.12 - public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Throwable { 2.13 - OutputAnalyzer output = null; 2.14 - try { 2.15 - output = new OutputAnalyzer(pb.start()); 2.16 - return output; 2.17 - } catch (Throwable t) { 2.18 - System.out.println("executeProcess() failed: " + t); 2.19 - throw t; 2.20 - } finally { 2.21 - System.out.println(getProcessLog(pb, output)); 2.22 + /** 2.23 + * Executes a process, waits for it to finish and returns the process output. 2.24 + * The process will have exited before this method returns. 2.25 + * @param pb The ProcessBuilder to execute. 2.26 + * @return The {@linkplain OutputAnalyzer} instance wrapping the process. 2.27 + */ 2.28 + public static OutputAnalyzer executeProcess(ProcessBuilder pb) throws Exception { 2.29 + OutputAnalyzer output = null; 2.30 + Process p = null; 2.31 + boolean failed = false; 2.32 + try { 2.33 + p = pb.start(); 2.34 + output = new OutputAnalyzer(p); 2.35 + p.waitFor(); 2.36 + 2.37 + return output; 2.38 + } catch (Throwable t) { 2.39 + if (p != null) { 2.40 + p.destroyForcibly().waitFor(); 2.41 + } 2.42 + 2.43 + failed = true; 2.44 + System.out.println("executeProcess() failed: " + t); 2.45 + throw t; 2.46 + } finally { 2.47 + if (failed) { 2.48 + System.err.println(getProcessLog(pb, output)); 2.49 + } 2.50 + } 2.51 } 2.52 - } 2.53 2.54 /** 2.55 * Executes a process, waits for it to finish and returns the process output.