changeset 222:e7361050c369

Basic StringBu* tests.
author shade
date Tue, 20 Oct 2015 22:23:40 +0300
parents 07af6b67cd23
children bda9fbee58c8
files jcstress-core/src/main/java/org/openjdk/jcstress/annotations/Result.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBufferTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBuilderTest.java
diffstat 4 files changed, 117 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/annotations/Result.java	Tue Apr 21 16:33:24 2015 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/annotations/Result.java	Tue Oct 20 22:23:40 2015 +0300
@@ -36,7 +36,7 @@
  *   - Result classes usually mimic value types: they do not have identity, and harness
  *     may reuse the objects, and also auto-magically clear the fields;
  *   - All fields in Result classes should be public;
- *   - All fields in Result classes should be primitive;
+ *   - All fields in Result classes should be primitive, or String;
  *   - Result classes should be serializable;
  */
 @Target(ElementType.TYPE)
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Tue Apr 21 16:33:24 2015 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Tue Oct 20 22:23:40 2015 +0300
@@ -25,17 +25,7 @@
 package org.openjdk.jcstress.infra.processors;
 
 import org.openjdk.jcstress.Options;
-import org.openjdk.jcstress.annotations.Actor;
-import org.openjdk.jcstress.annotations.Arbiter;
-import org.openjdk.jcstress.annotations.Description;
-import org.openjdk.jcstress.annotations.JCStressMeta;
-import org.openjdk.jcstress.annotations.JCStressTest;
-import org.openjdk.jcstress.annotations.Mode;
-import org.openjdk.jcstress.annotations.Outcome;
-import org.openjdk.jcstress.annotations.Ref;
-import org.openjdk.jcstress.annotations.Result;
-import org.openjdk.jcstress.annotations.Signal;
-import org.openjdk.jcstress.annotations.State;
+import org.openjdk.jcstress.annotations.*;
 import org.openjdk.jcstress.infra.collectors.TestResultCollector;
 import org.openjdk.jcstress.infra.runners.Control;
 import org.openjdk.jcstress.infra.runners.Runner;
@@ -50,14 +40,7 @@
 import javax.annotation.processing.RoundEnvironment;
 import javax.annotation.processing.SupportedSourceVersion;
 import javax.lang.model.SourceVersion;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.AnnotationValue;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.VariableElement;
+import javax.lang.model.element.*;
 import javax.lang.model.util.ElementFilter;
 import javax.tools.Diagnostic;
 import javax.tools.FileObject;
@@ -65,18 +48,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
+import java.util.*;
+import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -446,6 +419,9 @@
                 case "boolean":
                     pw.print("false");
                     break;
+                case "java.lang.String":
+                    pw.print("\"\"");
+                    break;
                 default:
                     throw new GenerationException("Unable to handle @" + Result.class.getSimpleName() + " field of type " + type, var);
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBufferTest.java	Tue Oct 20 22:23:40 2015 +0300
@@ -0,0 +1,54 @@
+/*
+ * 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.tests.strings;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.StringResult1;
+
+@JCStressTest
+@Description("Tests the StringBuffers are working good under concurrent updates.")
+@Outcome(id = "[fb]", expect = Expect.ACCEPTABLE, desc = "T1 -> T2 execution.")
+@Outcome(id = "[bf]", expect = Expect.ACCEPTABLE, desc = "T2 -> T1 execution.")
+@State
+public class StringBufferTest {
+
+    StringBuffer sb = new StringBuffer();
+
+    @Actor
+    public void actor1() {
+        sb.append('f');
+    }
+
+    @Actor
+    public void actor2() {
+        sb.append('b');
+    }
+
+    @Arbiter
+    public void tester(StringResult1 r) {
+        r.r1 = sb.toString();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBuilderTest.java	Tue Oct 20 22:23:40 2015 +0300
@@ -0,0 +1,55 @@
+/*
+ * 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.tests.strings;
+
+import org.openjdk.jcstress.annotations.*;
+import org.openjdk.jcstress.infra.results.StringResult1;
+
+@JCStressTest
+@Description("Tests the StringBuilders are working good under concurrent updates.")
+@Outcome(id = "[fb]", expect = Expect.ACCEPTABLE, desc = "T1 -> T2 execution.")
+@Outcome(id = "[bf]", expect = Expect.ACCEPTABLE, desc = "T2 -> T1 execution.")
+@Outcome(expect = Expect.ACCEPTABLE_INTERESTING, desc = "Other values are expected, threads are messing with each other.")
+@State
+public class StringBuilderTest {
+
+    StringBuilder sb = new StringBuilder();
+
+    @Actor
+    public void actor1() {
+        sb.append('f');
+    }
+
+    @Actor
+    public void actor2() {
+        sb.append('b');
+    }
+
+    @Arbiter
+    public void tester(StringResult1 r) {
+        r.r1 = sb.toString();
+    }
+
+}