changeset 30:39879befac76

tests-custom: Sample stale read test.
author shade
date Wed, 24 Jul 2013 13:24:46 +0400
parents 31111172517a
children 7f139400685e
files tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/StaleReadTest.java tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml
diffstat 2 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/scratch/StaleReadTest.java	Wed Jul 24 13:24:46 2013 +0400
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005, 2013, 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.scratch;
+
+import org.openjdk.jcstress.tests.TerminationTest;
+
+public class StaleReadTest implements TerminationTest<StaleReadTest.State> {
+
+    @Override
+    public void actor1(State state) throws Exception {
+        int la = 0;
+        int lg = 0;
+        while (la == 0) {
+            lg = state.g; // "force re-read"
+            la = state.a;
+        }
+    }
+
+    @Override
+    public void signal(State state, Thread actor1) throws Exception {
+        state.a = 1;
+    }
+
+    @Override
+    public State newState() {
+        return new State();
+    }
+
+    public static class State {
+        volatile int g;
+        int a;
+    }
+
+}
--- a/tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml	Wed Jul 24 12:37:39 2013 +0400
+++ b/tests-custom/src/main/resources/org/openjdk/jcstress/desc/scratch.xml	Wed Jul 24 13:24:46 2013 +0400
@@ -72,5 +72,18 @@
         </unmatched>
     </test>
 
+    <test name="org.openjdk.jcstress.tests.scratch.StaleReadTest">
+        <contributed-by>Aleksey Shipilev (aleksey.shipilev@oracle.com)</contributed-by>
+        <description>Generated test</description>
+        <case>
+            <match>TERMINATED</match>
+            <expect>REQUIRED</expect>
+            <description>Default value</description>
+        </case>
+        <unmatched>
+            <expect>FORBIDDEN</expect>
+            <description>Other cases are not expected.</description>
+        </unmatched>
+    </test>
 
 </testsuite>
\ No newline at end of file