changeset 202:0cba78bc2e06

Migrate generated test cases to new Annotation API.
author shade
date Wed, 13 Aug 2014 02:59:35 +0400
parents 3b872b32f4f0
children cf6034e845dd
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/tracer/TraceGen.java
diffstat 2 files changed, 22 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java	Wed Aug 13 02:37:50 2014 +0400
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java	Wed Aug 13 02:59:35 2014 +0400
@@ -41,7 +41,6 @@
     private final String resRoot;
 
     private final ResultGenerator resultGenerator;
-    private PrintWriter resourceWriter;
 
     public TestGenerator(String srcRoot, String resRoot) {
         this.srcRoot = srcRoot;
@@ -54,9 +53,6 @@
     }
 
     public void generateMemoryEffects() throws FileNotFoundException {
-        resourceWriter = new PrintWriter(Utils.ensureDir(resRoot + "/org/openjdk/jcstress/desc/") + "/memeffects.xml");
-        resourceWriter.println("<testsuite>");
-
         for (Class<?> varType : Types.SUPPORTED_PRIMITIVES) {
             for (Class<?> guardType : Types.SUPPORTED_PRIMITIVES) {
                 generate(new Types(guardType, varType), new VolatileReadWrite(guardType), "volatile_" + guardType + "_" + varType, "org.openjdk.jcstress.tests.memeffects.basic.volatiles");
@@ -98,38 +94,9 @@
             }
 
         }
-
-        resourceWriter.println("</testsuite>");
-        resourceWriter.close();
     }
 
    public void generate(Types types, Primitive prim, String klass, String pkg) throws FileNotFoundException {
-
-        resourceWriter.println("    <test name=\"" + pkg + "." + klass + "\">\n" +
-                "        <contributed-by>Aleksey Shipilev (aleksey.shipilev@oracle.com)</contributed-by>\n" +
-                "        <description>Generated test</description>\n" +
-                "        <case>\n" +
-                "            <match>[" + getDefaultValue(types.type(0)) +", " + getDefaultValue(types.type(1))+ "]</match>\n" +
-                "            <match>[" + getDefaultValue(types.type(0)) +", " + getSetValue(types.type(1))+ "]</match>\n" +
-                "            <expect>ACCEPTABLE</expect>\n" +
-                "            <description>Seeing default guard, can see any value</description>\n" +
-                "        </case>\n" +
-                "        <case>\n" +
-                "            <match>[" + getSetValue(types.type(0)) +", " + getSetValue(types.type(1))+ "]</match>\n" +
-                "            <expect>ACCEPTABLE</expect>\n" +
-                "            <description>Seeing set guard, seeing the updated value</description>\n" +
-                "        </case>\n" +
-                "        <case>\n" +
-                "            <match>[" + getSetValue(types.type(0)) +", " + getDefaultValue(types.type(1))+ "]</match>\n" +
-                "            <expect>FORBIDDEN</expect>\n" +
-                "            <description>Seeing set guard, not seeing the updated value</description>\n" +
-                "        </case>\n" +
-                "        <unmatched>\n" +
-                "            <expect>FORBIDDEN</expect>\n" +
-                "            <description>Other cases are not expected.</description>\n" +
-                "        </unmatched>\n" +
-                "    </test>");
-
         String resultName = resultGenerator.generateResult(types);
 
         String pathname = Utils.ensureDir(srcRoot + "/" + pkg.replaceAll("\\.", "/"));
@@ -145,8 +112,14 @@
         pw.println("import org.openjdk.jcstress.annotations.Actor;");
         pw.println("import org.openjdk.jcstress.annotations.JCStressTest;");
         pw.println("import org.openjdk.jcstress.annotations.State;");
+        pw.println("import org.openjdk.jcstress.annotations.Outcome;");
+        pw.println("import org.openjdk.jcstress.annotations.Expect;");
         pw.println();
         pw.println("@JCStressTest");
+        pw.println("@Outcome(id = \"[" + getDefaultValue(types.type(0)) +", " + getDefaultValue(types.type(1)) + "]\", expect = Expect.ACCEPTABLE, desc = \"Seeing default guard, can see any value\")");
+        pw.println("@Outcome(id = \"[" + getDefaultValue(types.type(0)) +", " + getSetValue(types.type(1)) + "]\", expect = Expect.ACCEPTABLE, desc = \"Seeing default guard, can see any value\")");
+        pw.println("@Outcome(id = \"[" + getSetValue(types.type(0)) +", " + getSetValue(types.type(1)) + "]\", expect = Expect.ACCEPTABLE, desc = \"Seeing set guard, seeing the updated value\")");
+        pw.println("@Outcome(id = \"[" + getSetValue(types.type(0)) +", " + getDefaultValue(types.type(1)) + "]\", expect = Expect.FORBIDDEN, desc = \"Seeing set guard, not seeing the updated value\")");
         pw.println("@State");
         pw.println("public class " + klass + " {");
         pw.println();
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/tracer/TraceGen.java	Wed Aug 13 02:37:50 2014 +0400
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/tracer/TraceGen.java	Wed Aug 13 02:59:35 2014 +0400
@@ -30,7 +30,16 @@
 
 import java.io.FileNotFoundException;
 import java.io.PrintWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
 
 public class TraceGen {
 
@@ -38,7 +47,6 @@
     private final String srcDir;
     private final String resDir;
     private final ResultGenerator resultGenerator;
-    private PrintWriter resourceWriter;
 
     public TraceGen(int vars, String srcDir, String resDir) {
         this.vars = vars;
@@ -48,13 +56,6 @@
     }
 
     public void generate() {
-        try {
-            resourceWriter = new PrintWriter(Utils.ensureDir(resDir + "/org/openjdk/jcstress/desc/") + "/seqcst-volatiles.xml");
-        } catch (FileNotFoundException e) {
-            throw new IllegalStateException(e);
-        }
-        resourceWriter.println("<testsuite>");
-
         List<Op> possibleOps = new ArrayList<>();
         for (int v = 0; v < vars; v++) {
             for (Op.Type t : Op.Type.values()) {
@@ -151,9 +152,6 @@
         }
         System.out.println();
         System.out.println(testCount + " interesting multi-traces");
-
-        resourceWriter.println("</testsuite>");
-        resourceWriter.close();
     }
 
     private void emit(MultiTrace mt, List<String> results) {
@@ -164,28 +162,6 @@
 
         String klass = mt.id() + "Test";
 
-        resourceWriter.println("    <test name=\"" + pkg + "." + klass + "\">\n" +
-                "        <contributed-by>Aleksey Shipilev (aleksey.shipilev@oracle.com)</contributed-by>\n" +
-                "        <description>Generated test</description>\n");
-
-        for (String r : results) {
-                resourceWriter.println(
-                "        <case>\n" +
-                "            <match>" + r + "</match>\n" +
-                "            <expect>ACCEPTABLE</expect>\n" +
-                "            <description>Sequential consistency.</description>\n" +
-                "        </case>\n"
-            );
-        }
-
-        resourceWriter.println(
-                "        <unmatched>\n" +
-                "            <expect>FORBIDDEN</expect>\n" +
-                "            <description>Non sequentially-consistent result</description>\n" +
-                "        </unmatched>\n" +
-                "    </test>");
-
-
         Class[] klasses = new Class[mt.original.getLoadCount()];
         for (int c = 0; c < klasses.length; c++) {
             klasses[c] = int.class;
@@ -208,8 +184,14 @@
         pw.println("import org.openjdk.jcstress.annotations.Actor;");
         pw.println("import org.openjdk.jcstress.annotations.JCStressTest;");
         pw.println("import org.openjdk.jcstress.annotations.State;");
+        pw.println("import org.openjdk.jcstress.annotations.Outcome;");
+        pw.println("import org.openjdk.jcstress.annotations.Expect;");
         pw.println();
         pw.println("@JCStressTest");
+        for (String r : results) {
+            pw.println("@Outcome(id = \"" + r + "\", expect = Expect.ACCEPTABLE, desc = \"Sequential consistency.\")");
+        }
+
         pw.println("@State");
         pw.println("public class " + klass + " {");
         pw.println();