changeset 238:d81530020d67

Runner: state output trimming is overly excessive.
author shade
date Wed, 11 May 2016 01:27:50 +0300
parents 905643674ab9
children f1395382fbc4
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/util/StringUtils.java jcstress-core/src/test/java/org/openjdk/jcstress/util/StringUtilsTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/sample/SampleTest.java
diffstat 5 files changed, 81 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/ConsoleReportPrinter.java	Wed May 11 00:45:54 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/grading/ConsoleReportPrinter.java	Wed May 11 01:27:50 2016 +0300
@@ -32,6 +32,7 @@
 import org.openjdk.jcstress.infra.collectors.TestResult;
 import org.openjdk.jcstress.infra.collectors.TestResultCollector;
 import org.openjdk.jcstress.infra.runners.TestList;
+import org.openjdk.jcstress.util.StringUtils;
 
 import javax.xml.bind.JAXBException;
 import java.io.FileNotFoundException;
@@ -165,15 +166,12 @@
                 expectLen = Math.max(expectLen, Expect.UNKNOWN.toString().length());
             }
 
-            idLen += 2;
-            occLen += 2;
-
             TestInfo test = TestList.getInfo(r.getName());
             if (test == null) {
                 output.printf("%" + idLen + "s %" + occLen +"s %" + expectLen + "s  %-" + descLen + "s%n", "Observed state", "Occurrences", "Expectation", "Interpretation");
                 for (State s : r.getStates()) {
                     output.printf("%" + idLen + "s %," + occLen + "d %" + expectLen + "s  %-" + descLen + "s%n",
-                            cutoff(s.getId(), idLen),
+                            StringUtils.cutoff(s.getId(), idLen),
                             s.getCount(),
                             Expect.UNKNOWN,
                             "N/A");
@@ -182,9 +180,13 @@
             }
 
             for (StateCase c : test.cases()) {
+                idLen = Math.max(idLen, c.state().length());
                 expectLen = Math.max(expectLen, c.expect().toString().length());
             }
             expectLen = Math.max(expectLen, test.unmatched().expect().toString().length());
+
+            idLen += 2;
+            occLen += 2;
             expectLen += 2;
 
             output.printf("%" + idLen + "s %" + occLen +"s %" + expectLen + "s  %-" + descLen + "s%n", "Observed state", "Occurrences", "Expectation", "Interpretation");
@@ -199,10 +201,10 @@
                     if (c.state().equals(s.getId())) {
                         // match!
                         output.printf("%" + idLen + "s %," + occLen + "d %" + expectLen + "s  %-" + descLen + "s%n",
-                                cutoff(s.getId(), idLen),
+                                StringUtils.cutoff(s.getId(), idLen),
                                 s.getCount(),
                                 c.expect(),
-                                cutoff(c.description(), descLen));
+                                StringUtils.cutoff(c.description(), descLen));
                         matched = true;
                         unmatchedStates.remove(s);
                     }
@@ -210,38 +212,25 @@
 
                 if (!matched) {
                     output.printf("%" + idLen + "s %," + occLen + "d %" + expectLen + "s  %-" + descLen + "s%n",
-                                cutoff(c.state(), idLen),
+                                StringUtils.cutoff(c.state(), idLen),
                                 0,
                                 c.expect(),
-                                cutoff(c.description(), descLen));
+                                StringUtils.cutoff(c.description(), descLen));
                 }
             }
 
             for (State s : unmatchedStates) {
                 output.printf("%" + idLen + "s %," + occLen + "d %" + expectLen + "s  %-" + descLen + "s%n",
-                        cutoff(s.getId(), idLen),
+                        StringUtils.cutoff(s.getId(), idLen),
                         s.getCount(),
                         test.unmatched().expect(),
-                        cutoff(test.unmatched().description(), descLen));
+                        StringUtils.cutoff(test.unmatched().description(), descLen));
             }
 
             output.println();
         }
     }
 
-    private static String cutoff(String src, int len) {
-        while (src.contains("  ")) {
-            src = src.replaceAll("  ", " ");
-        }
-        String trim = src.replaceAll("\n", "").trim();
-        String substring = trim.substring(0, Math.min(len - 3, trim.length()));
-        if (!substring.equals(trim)) {
-            return substring + "...";
-        } else {
-            return substring;
-        }
-    }
-
     private PrintWriter printLine(PrintWriter output, String label, TestResult r) {
         return output.printf(" (ETA: %10s) (R: %s) (T:%4d/%d) (F:%2d/%d) (I:%2d/%d) %10s %s\n",
                 computeETA(),
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Wed May 11 00:45:54 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Wed May 11 01:27:50 2016 +0300
@@ -391,8 +391,7 @@
 
         for (VariableElement var : ElementFilter.fieldsIn(info.getResult().getEnclosedElements())) {
             pw.print("            r." + var.getSimpleName().toString() + " = ");
-            String type = var.asType().toString();
-            pw.print(getDefaultVal(var, type));
+            pw.print(getDefaultVal(var));
             pw.println(";");
         }
 
@@ -481,7 +480,8 @@
         pw.close();
     }
 
-    private String getDefaultVal(VariableElement var, String type) {
+    private String getDefaultVal(VariableElement var) {
+        String type = var.asType().toString();
         String val;
         switch (type) {
             case "int":
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/StringUtils.java	Wed May 11 01:27:50 2016 +0300
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.util;
+
+public class StringUtils {
+
+    public static String cutoff(String src, int len) {
+        while (src.contains("  ")) {
+            src = src.replaceAll("  ", " ");
+        }
+        String trim = src.replaceAll("\n", "").trim();
+        if (trim.length() <= len) {
+            return trim;
+        }
+        int min = Math.min(len - 3, trim.length());
+        String substring = trim.substring(0, min);
+        if (!substring.equals(trim)) {
+            return substring + "...";
+        } else {
+            return substring;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/test/java/org/openjdk/jcstress/util/StringUtilsTest.java	Wed May 11 01:27:50 2016 +0300
@@ -0,0 +1,18 @@
+package org.openjdk.jcstress.util;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+public class StringUtilsTest {
+
+    @Test
+    public void test() {
+        String s = "FooBar";
+
+        Assert.assertEquals("FooBar", StringUtils.cutoff(s, 7));
+        Assert.assertEquals("FooBar", StringUtils.cutoff(s, 6));
+        Assert.assertEquals("Fo...", StringUtils.cutoff(s, 5));
+        Assert.assertEquals("...", StringUtils.cutoff(s, 3));
+    }
+
+}
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/sample/SampleTest.java	Wed May 11 00:45:54 2016 +0300
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/sample/SampleTest.java	Wed May 11 01:27:50 2016 +0300
@@ -35,8 +35,8 @@
 @State
 public class SampleTest {
 
-    public int a;
-    public int b;
+    int a;
+    int b;
 
     @Actor
     public void actor1(IntResult4 r) {