changeset 235:526f1373dcb1

Footprint: coalesce multiple IDs in @Outcomes, condense the test line format.
author shade
date Tue, 10 May 2016 23:53:35 +0300
parents 70831b9d15b2
children 49d7d2c14b2f
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/TestList.java jcstress-core/src/main/java/org/openjdk/jcstress/util/TestLineReader.java jcstress-core/src/main/java/org/openjdk/jcstress/util/TestLineWriter.java jcstress-core/src/test/java/org/openjdk/jcstress/util/TestLineTest.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java
diffstat 6 files changed, 226 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Tue May 10 22:20:46 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Tue May 10 23:53:35 2016 +0300
@@ -31,10 +31,7 @@
 import org.openjdk.jcstress.infra.runners.Runner;
 import org.openjdk.jcstress.infra.runners.StateHolder;
 import org.openjdk.jcstress.infra.runners.TestList;
-import org.openjdk.jcstress.util.ArrayUtils;
-import org.openjdk.jcstress.util.Counter;
-import org.openjdk.jcstress.util.OpenAddressHashCounter;
-import org.openjdk.jcstress.util.VMSupport;
+import org.openjdk.jcstress.util.*;
 
 import javax.annotation.processing.AbstractProcessor;
 import javax.annotation.processing.RoundEnvironment;
@@ -94,36 +91,31 @@
                 FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", TestList.LIST.substring(1));
                 PrintWriter writer = new PrintWriter(file.openWriter());
                 for (TestInfo test : tests) {
-                    writer.print(
-                            test.getTest().getQualifiedName()
-                            + "===,===" + test.getGeneratedName()
-                            + "===,===" + test.getDescription()
-                            + "===,===" + test.getActors().size()
-                            + "===,===" + test.isRequiresFork());
+                    TestLineWriter wl = new TestLineWriter();
 
-                    int size = 0;
+                    wl.put(test.getTest().getQualifiedName());
+                    wl.put(test.getGeneratedName());
+                    wl.put(test.getDescription());
+                    wl.put(test.getActors().size());
+                    wl.put(test.isRequiresFork());
+
+                    wl.put(test.cases().size());
+
                     for (Outcome c : test.cases()) {
+                        wl.put(c.expect());
+                        wl.put(c.desc());
+                        wl.put(c.id().length);
                         for (String id : c.id()) {
-                            size++;
+                            wl.put(id);
                         }
                     }
 
-                    writer.print("===,===" + size);
-
-                    for (Outcome c : test.cases()) {
-                        for (String id : c.id()) {
-                            writer.print("===,===" + id);
-                            writer.print("===,===" + c.expect());
-                            writer.print("===,===" + c.desc());
-                        }
+                    wl.put(test.refs().size());
+                    for (String ref : test.refs()) {
+                        wl.put(ref);
                     }
 
-                    writer.print("===,===" + test.refs().size());
-                    for (String ref : test.refs()) {
-                        writer.print("===,===" + ref);
-                    }
-
-                    writer.println();
+                    writer.println(wl.get());
                 }
                 writer.close();
             } catch (IOException ex) {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/TestList.java	Tue May 10 22:20:46 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/TestList.java	Tue May 10 23:53:35 2016 +0300
@@ -27,6 +27,7 @@
 import org.openjdk.jcstress.annotations.Expect;
 import org.openjdk.jcstress.infra.StateCase;
 import org.openjdk.jcstress.infra.TestInfo;
+import org.openjdk.jcstress.util.TestLineReader;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -52,28 +53,32 @@
 
                 String line;
                 while ((line = reader.readLine()) != null) {
-                    String[] ls = line.split("===,===");
-                    if (ls.length >= 6) {
-                        String name = ls[0];
-                        String runner = ls[1];
-                        String description = ls[2];
-                        int actorCount = Integer.valueOf(ls[3]);
-                        boolean requiresFork = Boolean.valueOf(ls[4]);
-                        int caseCount = Integer.valueOf(ls[5]);
+                    TestLineReader read = new TestLineReader(line);
+
+                    if (read.isCorrect()) {
+                        String name = read.nextString();
+                        String runner = read.nextString();
+                        String description = read.nextString();
+                        int actorCount = read.nextInt();
+                        boolean requiresFork = read.nextBoolean();
+                        int caseCount = read.nextInt();
 
                         TestInfo testInfo = new TestInfo(name, runner, description, actorCount, requiresFork);
                         m.put(name, testInfo);
+
                         for (int c = 0; c < caseCount; c++) {
-                            String state  = ls[6 + 3*c + 0];
-                            String expect = ls[6 + 3*c + 1];
-                            String desc  = ls[6 + 3*c + 2];
-                            testInfo.addCase(new StateCase(state, Expect.valueOf(expect), desc));
+                            Expect expect  = Expect.valueOf(read.nextString());
+                            String desc    = read.nextString();
+                            int stateCount = read.nextInt();
+                            for (int s = 0; s < stateCount; s++) {
+                                String state = read.nextString();
+                                testInfo.addCase(new StateCase(state, expect, desc));
+                            }
                         }
 
-                        int s = 6 + caseCount * 3;
-                        int refCount = Integer.valueOf(ls[s]);
+                        int refCount = read.nextInt();
                         for (int c = 0; c < refCount; c++) {
-                            testInfo.addRef(ls[s + c]);
+                            testInfo.addRef(read.nextString());
                         }
                     }
                 }
@@ -93,6 +98,7 @@
         return tests;
     }
 
+
     public static Collection<String> tests() {
         return getTests().keySet();
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/TestLineReader.java	Tue May 10 23:53:35 2016 +0300
@@ -0,0 +1,92 @@
+/*
+ * 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 TestLineReader {
+
+    private final String line;
+    private final boolean correct;
+
+    private int cursor;
+
+    public TestLineReader(String line) {
+        this.line = line;
+        this.correct = (line.length() > 6 && line.startsWith("JCTEST"));
+        this.cursor = 6;
+    }
+
+    private int readLen() {
+        StringBuilder sb = new StringBuilder();
+        char c = line.charAt(cursor);
+        while (Character.isDigit(c)) {
+            sb.append(c);
+            cursor++;
+            c = line.charAt(cursor);
+        }
+        return Integer.valueOf(sb.toString());
+    }
+
+    private String readString(int len) {
+        String s = line.substring(cursor, cursor + len);
+        cursor += len;
+        return s;
+    }
+
+    private char readChar() {
+        return line.charAt(cursor++);
+    }
+
+    public String nextString() {
+        int len = readLen();
+        char tag = readChar();
+        if (tag != 'S') {
+            throw new IllegalStateException("expected tag = S, got = " + tag);
+        }
+        return readString(len);
+    }
+
+    public int nextInt() {
+        int len = readLen();
+        char tag = readChar();
+        if (tag != 'I') {
+            throw new IllegalStateException("expected tag = I, got = " + tag);
+        }
+        return Integer.valueOf(readString(len));
+    }
+
+    public boolean nextBoolean() {
+        int len = readLen();
+        char tag = readChar();
+        if (tag != 'B') {
+            throw new IllegalStateException("expected tag = B, got = " + tag);
+        }
+        char v = readChar();
+        return v == 'T';
+    }
+
+    public boolean isCorrect() {
+        return correct;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/TestLineWriter.java	Tue May 10 23:53:35 2016 +0300
@@ -0,0 +1,60 @@
+/*
+ * 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 TestLineWriter {
+
+    private StringBuilder line;
+
+    public TestLineWriter() {
+        line = new StringBuilder();
+        line.append("JCTEST");
+    }
+
+    public void put(Object value) {
+        String s = String.valueOf(value);
+        line.append(s.length());
+        line.append("S");
+        line.append(s);
+    }
+
+    public void put(int value) {
+        String s = String.valueOf(value);
+        line.append(s.length());
+        line.append("I");
+        line.append(s);
+    }
+
+    public void put(boolean value) {
+        line.append(1);
+        line.append("B");
+        line.append(value ? 'T' : 'F');
+    }
+
+    public String get() {
+        return line.toString();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/test/java/org/openjdk/jcstress/util/TestLineTest.java	Tue May 10 23:53:35 2016 +0300
@@ -0,0 +1,32 @@
+package org.openjdk.jcstress.util;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+public class TestLineTest {
+
+    @Test
+    public void test() {
+        TestLineWriter writer = new TestLineWriter();
+        writer.put("jcstress");
+        writer.put("is cool in the year");
+        writer.put(2016);
+        writer.put(" = ");
+        writer.put(true);
+        writer.put("");
+        writer.put("Yeah.");
+
+        String s = writer.get();
+
+        TestLineReader reader = new TestLineReader(s);
+
+        Assert.assertEquals("jcstress", reader.nextString());
+        Assert.assertEquals("is cool in the year", reader.nextString());
+        Assert.assertEquals(2016, reader.nextInt());
+        Assert.assertEquals(" = ", reader.nextString());
+        Assert.assertEquals(true, reader.nextBoolean());
+        Assert.assertEquals("", reader.nextString());
+        Assert.assertEquals("Yeah.", reader.nextString());
+    }
+
+}
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Tue May 10 22:20:46 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Tue May 10 23:53:35 2016 +0300
@@ -242,9 +242,11 @@
         pw.println("import org.openjdk.jcstress.annotations.*;");
         pw.println();
         pw.println("@JCStressTest");
+        pw.println("@Outcome(id = {");
         for (String r : scResults) {
-            pw.println("@Outcome(id = \"" + r + "\", expect = Expect.ACCEPTABLE, desc = \"Sequential consistency.\")");
+            pw.println("            \"" + r + "\",");
         }
+        pw.println("}, expect = Expect.ACCEPTABLE, desc = \"Sequential consistency.\")");
 
         pw.println("@State");
         pw.println("public class " + klass + " {");