changeset 325:bfe8579a17fb

Runners: print the runner messages in the results.
author shade
date Wed, 28 Sep 2016 15:02:15 +0200
parents 11b5f55dcddc
children d48af41e33bf
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/ConsoleReportPrinter.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java
diffstat 3 files changed, 35 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/ConsoleReportPrinter.java	Wed Sep 28 13:12:06 2016 +0200
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/ConsoleReportPrinter.java	Wed Sep 28 15:02:15 2016 +0200
@@ -101,21 +101,11 @@
                 return;
             case CHECK_TEST_ERROR:
             case TEST_ERROR:
-                output.println();
                 printLine("ERROR", r);
-                for (String data : r.getAuxData()) {
-                    output.println(data);
-                }
-                output.println();
                 hardErrors++;
                 return;
             case VM_ERROR:
-                output.println();
                 printLine("VM ERROR", r);
-                for (String data : r.getAuxData()) {
-                    output.println(data);
-                }
-                output.println();
                 hardErrors++;
                 return;
             case API_MISMATCH:
@@ -178,6 +168,14 @@
             output.println();
         }
 
+        if (!r.getAuxData().isEmpty()) {
+            output.println("    Messages: ");
+            for (String data : r.getAuxData()) {
+                output.println("        " + data);
+            }
+            output.println();
+        }
+
         printProgress();
     }
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Wed Sep 28 13:12:06 2016 +0200
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Wed Sep 28 15:02:15 2016 +0200
@@ -711,11 +711,8 @@
 
         pw.println("    @Override");
         pw.println("    public void run() {");
-        pw.println("        testLog.println(\"Running \" + testName);");
-        pw.println();
         pw.println("        Counter<Outcome> results = new OpenAddressHashCounter<>();");
         pw.println();
-        pw.println("        testLog.print(\"Iterations \");");
         pw.println("        for (int c = 0; c < config.iters; c++) {");
         pw.println("            try {");
         pw.println("                WhiteBoxSupport.tryDeopt(config.deoptRatio);");
@@ -723,20 +720,16 @@
         pw.println("                // gracefully \"handle\"");
         pw.println("            }");
         pw.println();
-        pw.println("            testLog.print(\".\");");
-        pw.println("            testLog.flush();");
         pw.println("            run(results);");
         pw.println();
-        pw.println("            dump(c, results);");
-        pw.println();
         pw.println("            if (results.count(Outcome.STALE) > 0) {");
-        pw.println("                testLog.println(\"Have stale threads, forcing VM to exit\");");
-        pw.println("                testLog.flush();");
-        pw.println("                testLog.close();");
+        pw.println("                messages.add(\"Have stale threads, forcing VM to exit for proper cleanup.\");");
+        pw.println("                dump(c, results);");
         pw.println("                System.exit(0);");
+        pw.println("            } else {");
+        pw.println("                dump(c, results);");
         pw.println("            }");
         pw.println("        }");
-        pw.println("        testLog.println();");
         pw.println("    }");
         pw.println();
         pw.println("    @Override");
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Wed Sep 28 13:12:06 2016 +0200
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Wed Sep 28 15:02:15 2016 +0200
@@ -28,12 +28,13 @@
 import org.openjdk.jcstress.infra.collectors.TestResult;
 import org.openjdk.jcstress.infra.collectors.TestResultCollector;
 import org.openjdk.jcstress.util.Counter;
-import org.openjdk.jcstress.util.NullOutputStream;
 import org.openjdk.jcstress.vm.WhiteBoxSupport;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
@@ -49,9 +50,9 @@
     protected final Control control;
     protected final TestResultCollector collector;
     protected final ExecutorService pool;
-    protected final PrintWriter testLog;
     protected final String testName;
     protected final TestConfig config;
+    protected final List<String> messages;
 
     public Runner(TestConfig config, TestResultCollector collector, ExecutorService pool, String testName) {
         this.collector = collector;
@@ -59,12 +60,7 @@
         this.testName = testName;
         this.control = new Control();
         this.config = config;
-
-        if (config.verbose) {
-            testLog = new PrintWriter(System.out, true);
-        } else {
-            testLog = new PrintWriter(new NullOutputStream(), true);
-        }
+        this.messages = new ArrayList<>();
     }
 
     /**
@@ -72,23 +68,16 @@
      * This method blocks until test is complete
      */
     public void run() {
-        testLog.println("Running " + testName);
-
         try {
             sanityCheck();
         } catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
-            testLog.println("Test sanity check failed, skipping");
-            testLog.println();
-            dumpFailure(-1, Status.API_MISMATCH, e);
+            dumpFailure(-1, Status.API_MISMATCH, "Test sanity check failed, skipping", e);
             return;
         } catch (Throwable e) {
-            testLog.println("Check test failed");
-            testLog.println();
-            dumpFailure(-1, Status.CHECK_TEST_ERROR, e);
+            dumpFailure(-1, Status.CHECK_TEST_ERROR, "Check test failed", e);
             return;
         }
 
-        testLog.print("Iterations ");
         for (int c = 0; c < config.iters; c++) {
             try {
                 WhiteBoxSupport.tryDeopt(config.deoptRatio);
@@ -96,20 +85,28 @@
                 // gracefully "handle"
             }
 
-            testLog.print(".");
-            testLog.flush();
             dump(c, internalRun());
         }
-        testLog.println();
     }
 
-    protected void dumpFailure(int iteration, Status status) {
+    private TestResult prepareResult(int iteration, Status status) {
         TestResult result = new TestResult(config, status, iteration);
+        for (String msg : messages) {
+            result.addAuxData(msg);
+        }
+        messages.clear();
+        return result;
+    }
+
+    protected void dumpFailure(int iteration, Status status, String message) {
+        messages.add(message);
+        TestResult result = prepareResult(iteration, status);
         collector.add(result);
     }
 
-    protected void dumpFailure(int iteration, Status status, Throwable aux) {
-        TestResult result = new TestResult(config, status, iteration);
+    protected void dumpFailure(int iteration, Status status, String message, Throwable aux) {
+        messages.add(message);
+        TestResult result = prepareResult(iteration, status);
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         aux.printStackTrace(pw);
@@ -119,12 +116,10 @@
     }
 
     protected void dump(int iteration, Counter<R> results) {
-        TestResult result = new TestResult(config, Status.NORMAL, iteration);
-
+        TestResult result = prepareResult(iteration, Status.NORMAL);
         for (R e : results.elementSet()) {
             result.addState(String.valueOf(e), results.count(e));
         }
-
         collector.add(result);
     }
 
@@ -143,7 +138,7 @@
                 } catch (TimeoutException e) {
                     allStopped = false;
                 } catch (ExecutionException e) {
-                    dumpFailure(-1, Status.TEST_ERROR, e.getCause());
+                    dumpFailure(-1, Status.TEST_ERROR, "Unrecoverable error while running", e.getCause());
                     return;
                 } catch (InterruptedException e) {
                     return;
@@ -151,7 +146,7 @@
             }
 
             if (TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) > Math.max(config.time, 60*1000)) {
-                dumpFailure(-1, Status.TIMEOUT_ERROR);
+                dumpFailure(-1, Status.TIMEOUT_ERROR, "Timeout out waiting for tasks to complete");
                 return;
             }
         }