changeset 384:020a3bf820bc

Report: rebuild test result page.
author shade
date Mon, 06 Mar 2017 17:13:41 +0100
parents 475d2625493e
children 6d05ba34c4e9
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java
diffstat 2 files changed, 119 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java	Mon Mar 06 14:18:42 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/HTMLReportPrinter.java	Mon Mar 06 17:13:41 2017 +0100
@@ -122,29 +122,7 @@
         output.println("<td width=100>");
 
         {
-            SortedMap<String, String> env = new TreeMap<>();
-            for (TestResult result : byName) {
-                if (result != null) {
-                    for (Map.Entry<String, String> kv : result.getEnv().entries().entrySet()) {
-                        String key = kv.getKey();
-                        String value = kv.getValue();
-                        String lastV = env.get(key);
-                        if (lastV == null) {
-                            env.put(key, value);
-                        } else {
-                            // Some VMs have these keys pre-populated with the command line,
-                            // which can have port definitions, PIDs, etc, and naturally
-                            // clash from launch to launch.
-                            if (key.equals("cmdLine")) continue;
-                            if (key.equals("launcher")) continue;
-
-                            if (!lastV.equalsIgnoreCase(value)) {
-                                System.err.println("Mismatched environment for key = " + key + ", was = " + lastV + ", now = " + value);
-                            }
-                        }
-                    }
-                }
-            }
+            SortedMap<String, String> env = getEnv(byName);
 
             output.println("<table>");
             for (Map.Entry<String, String> entry : env.entrySet()) {
@@ -192,6 +170,33 @@
         emitTestReports(ReportUtils.byName(collector.getTestResults()));
     }
 
+    private SortedMap<String, String> getEnv(List<TestResult> ts) {
+        SortedMap<String, String> env = new TreeMap<>();
+        for (TestResult result : ts) {
+            if (result != null) {
+                for (Map.Entry<String, String> kv : result.getEnv().entries().entrySet()) {
+                    String key = kv.getKey();
+                    String value = kv.getValue();
+                    String lastV = env.get(key);
+                    if (lastV == null) {
+                        env.put(key, value);
+                    } else {
+                        // Some VMs have these keys pre-populated with the command line,
+                        // which can have port definitions, PIDs, etc, and naturally
+                        // clash from launch to launch.
+                        if (key.equals("cmdLine")) continue;
+                        if (key.equals("launcher")) continue;
+
+                        if (!lastV.equalsIgnoreCase(value)) {
+                            System.err.println("Mismatched environment for key = " + key + ", was = " + lastV + ", now = " + value);
+                        }
+                    }
+                }
+            }
+        }
+        return env;
+    }
+
     private void printFooter(PrintWriter output) {
         output.println("</body>");
         output.println("</html>");
@@ -339,53 +344,100 @@
         });
     }
 
-    public void emitTestReport(PrintWriter output, Collection<TestResult> results, TestInfo test) {
-        printHeader(output);
+    public void emitTestReport(PrintWriter o, Collection<TestResult> results, TestInfo test) {
+        printHeader(o);
 
-        output.println("<h1>" + test.name() + "</h1>");
+        o.println("<h1>" + test.name() + "</h1>");
 
-        output.println("<p>" + test.description() + "</p>");
+        o.println("<h3>Description and references</h3>");
+        o.println("<p>" + test.description() + "</p>");
 
-        int rIdx = 1;
         for (String ref : test.refs()) {
-            output.println("<a href=\"" + ref + "\">[" + rIdx + "]</a>");
-            rIdx++;
+            o.println("<p><a href=\"" + ref + "\">" + ref + "</a></p>");
         }
 
-        for (TestResult r : results) {
-            output.println("<p>" + r.getConfig() + "</p>");
+        List<TestResult> sorted = new ArrayList<>(results);
+        sorted.sort(Comparator.comparing((TestResult t) -> StringUtils.join(t.getConfig().jvmArgs, ",")));
 
-            output.println("<table width=100%>");
-            output.println("<tr>");
-            output.println("<th width=250>Observed state</th>");
-            output.println("<th width=50>Occurrence</th>");
-            output.println("<th width=50>Expectation</th>");
-            output.println("<th>Interpretation</th>");
-            output.println("</tr>");
+        o.println("<h3>Environment</h3>");
+        o.println("<table>");
+        for (Map.Entry<String, String> entry : getEnv(sorted).entrySet()) {
+            o.println("<tr>");
+            o.println("<td nowrap>" + entry.getKey() + "</td>");
+            o.println("<td nowrap>" + entry.getValue() + "</td>");
+            o.println("</tr>");
+        }
+        o.println("</table>");
 
-            for (GradingResult c : r.grading().gradingResults) {
-                output.println("<tr bgColor=" + selectHTMLColor(c.expect, c.count == 0) + ">");
-                output.println("<td>" + c.id + "</td>");
-                output.println("<td align=center>" + c.count + "</td>");
-                output.println("<td align=center>" + c.expect + "</td>");
-                output.println("<td>" + c.description + "</td>");
-                output.println("</tr>");
+        o.println("<h3>Test configurations</h3>");
+
+        o.println("<table>");
+        int configs = 0;
+        for (TestResult r : sorted) {
+            o.println("<tr>");
+            o.println("<td nowrap><b>TC " + (configs + 1) + "</b></td>");
+            o.println("<td nowrap>" + r.getConfig() + "</td>");
+            o.println("</tr>");
+            configs++;
+        }
+        o.println("</table>");
+
+        o.println("<h3>Observed states</h3>");
+
+        Set<String> keys = new TreeSet<>();
+        for (TestResult r : sorted) {
+            keys.addAll(r.getStateKeys());
+        }
+
+        o.println("<table width=100% cellpadding=5>");
+        o.println("<tr>");
+        o.println("<th>Observed state</th>");
+        for (int c = 0; c < configs; c++) {
+            o.println("<th nowrap>TC " + (c+1) + "</th>");
+        }
+        o.println("<th>Expectation</th>");
+        o.println("<th>Interpretation</th>");
+        o.println("</tr>");
+
+        for (String key : keys) {
+            o.println("<tr>");
+            o.println("<td align='center'>" + key + "</td>");
+
+            String description = "";
+            Expect expect = null;
+
+            for (TestResult r : sorted) {
+                for (GradingResult c : r.grading().gradingResults) {
+                    if (c.id.equals(key)) {
+                        o.println("<td align='right' width='" + 30D/configs + "%' bgColor=" + selectHTMLColor(c.expect, c.count == 0) + ">" + c.count + "</td>");
+                        description = c.description;
+                        expect = c.expect;
+                    }
+                }
             }
 
-            output.println("</table>");
+            o.println("<td>" + expect + "</td>");
+            o.println("<td>" + description + "</td>");
+            o.println("</tr>");
+        }
 
+        o.println("</table>");
+
+        o.println("<h3>Auxiliary data</h3>");
+
+        for (TestResult r : sorted) {
             if (!r.getAuxData().isEmpty()) {
-                output.println("<p><b>Auxiliary data</b></p>");
-                output.println("<pre>");
+                o.println("<p><b>" + r.getConfig() + "</b></p>");
+                o.println("<pre>");
                 for (String data : r.getAuxData()) {
-                    output.println(data);
+                    o.println(data);
                 }
-                output.println("</pre>");
-                output.println();
+                o.println("</pre>");
+                o.println();
             }
         }
 
-        printFooter(output);
+        printFooter(o);
     }
 
     public String selectHTMLColor(Expect type, boolean isZero) {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java	Mon Mar 06 14:18:42 2017 +0100
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java	Mon Mar 06 17:13:41 2017 +0100
@@ -87,4 +87,18 @@
     private static boolean hasText(String s) {
         return (s != null) && !s.isEmpty();
     }
+
+    public static String join(List<String> list, String delim) {
+        StringBuilder sb = new StringBuilder();
+        boolean first = true;
+        for (String s : list) {
+            if (first) {
+                first = false;
+            } else {
+                sb.append(delim);
+            }
+            sb.append(s);
+        }
+        return sb.toString();
+    }
 }