changeset 92:982044a7f3bc

Annotations: support @State on test class.
author shade
date Thu, 13 Mar 2014 19:13:40 +0400
parents 7387387cff9a
children 104a1971c4d2
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/ConcurrencyStressTestProcessor.java tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java
diffstat 2 files changed, 27 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/ConcurrencyStressTestProcessor.java	Thu Mar 13 19:03:50 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/ConcurrencyStressTestProcessor.java	Thu Mar 13 19:13:40 2014 +0400
@@ -159,7 +159,7 @@
         }
 
         String packageName = getPackageName(info.getTest()) + ".generated";
-        String testName = info.getTest().getSimpleName().toString();
+        String testName = info.getTest().getSimpleName().toString() + "_jcstress";
 
         info.setGeneratedName(packageName + "." + testName);
 
@@ -170,14 +170,13 @@
         PrintWriter pw;
         Writer writer;
         try {
-            writer = processingEnv.getFiler().createSourceFile(info.getTest().getQualifiedName().toString()).openWriter();
+            writer = processingEnv.getFiler().createSourceFile(info.getTest().getQualifiedName().toString() + "_jcstress").openWriter();
             pw = new PrintWriter(writer, true);
         } catch (IOException e) {
             throw new GenerationException("IOException", info.getTest());
         }
 
-        String t = info.getTest().getQualifiedName().toString();
-        String tShort = info.getTest().getSimpleName().toString();
+        String t = info.getTest().getSimpleName().toString();
         String s = info.getState().getSimpleName().toString();
         String r = info.getResult().getSimpleName().toString();
 
@@ -185,11 +184,11 @@
 
         printImports(pw, info);
 
-        pw.println("public class " + tShort + " extends Runner<" + r + "> {");
+        pw.println("public class " + t + "_jcstress extends Runner<" + r + "> {");
         pw.println();
 
-        pw.println("    public " + tShort + "(Options opts, TestResultCollector collector, ExecutorService pool) {");
-        pw.println("        super(opts, collector, pool, \"" + t + "\");");
+        pw.println("    public " + t + "_jcstress(Options opts, TestResultCollector collector, ExecutorService pool) {");
+        pw.println("        super(opts, collector, pool, \"" + info.getTest().getQualifiedName() + "\");");
         pw.println("    }");
         pw.println();
 
@@ -317,7 +316,11 @@
             pw.println("            for (int l = 0; l < loops; l++) {");
             pw.println("                int index = indices[l];");
 
-            emitMethod(pw, a, "                lt." + a.getSimpleName(), "cur[index]", "res[index]");
+            if (info.getState().equals(info.getTest())) {
+                emitMethod(pw, a, "                cur[index]." + a.getSimpleName(), "cur[index]", "res[index]");
+            } else {
+                emitMethod(pw, a, "                lt." + a.getSimpleName(), "cur[index]", "res[index]");
+            }
 
             pw.println("            }");
             pw.println();
@@ -334,7 +337,11 @@
                 pw.println();
                 pw.println("                for (int l = 0; l < loops; l++) {");
                 pw.println("                    int index = indices[l];");
-                emitMethod(pw, info.getArbiter(), "                test." + info.getArbiter().getSimpleName(), "cur[index]", "res[index]");
+                if (info.getState().equals(info.getTest())) {
+                    emitMethod(pw, info.getArbiter(), "                cur[index]." + info.getArbiter().getSimpleName(), "cur[index]", "res[index]");
+                } else {
+                    emitMethod(pw, info.getArbiter(), "                lt." + info.getArbiter().getSimpleName(), "cur[index]", "res[index]");
+                }
                 pw.println("                }");
             }
             pw.println();
@@ -391,7 +398,7 @@
     }
 
     private void emitMethod(PrintWriter pw, ExecutableElement el, String lvalue, String stateAccessor, String resultAccessor) {
-        pw.print("                " + lvalue + "(");
+        pw.print(lvalue + "(");
 
         boolean isFirst = true;
         for (VariableElement var : el.getParameters()) {
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java	Thu Mar 13 19:03:50 2014 +0400
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/volatiles/DekkerTest.java	Thu Mar 13 19:13:40 2014 +0400
@@ -30,24 +30,22 @@
 import org.openjdk.jcstress.infra.results.IntResult2;
 
 @ConcurrencyStressTest
+@State
 public class DekkerTest  {
 
+    volatile int a;
+    volatile int b;
+
     @Actor
-    public void actor1(S s, IntResult2 r) {
-        s.a = 1;
-        r.r1 = s.b;
+    public void actor1(IntResult2 r) {
+        a = 1;
+        r.r1 = b;
     }
 
     @Actor
-    public void actor2(S s, IntResult2 r) {
-        s.b = 1;
-        r.r2 = s.a;
-    }
-
-    @State
-    public static class S {
-        volatile int a;
-        volatile int b;
+    public void actor2(IntResult2 r) {
+        b = 1;
+        r.r2 = a;
     }
 
 }