]> granicus.if.org Git - libatomic_ops/commitdiff
Test store/CAS emulation explicitly
authorIvan Maidanski <ivmai@mail.ru>
Fri, 3 Feb 2017 16:19:32 +0000 (19:19 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 3 Feb 2017 17:06:23 +0000 (20:06 +0300)
* tests/Makefile.am (test_atomic_generalized_CPPFLAGS): Add
-D AO_TEST_EMULATION.
* tests/test_atomic.c [(!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS || AO_USE_WIN32_PTHREADS) && AO_TEST_EMULATION]
(AO_store_full_emulation, AO_fetch_compare_and_swap_emulation): Declare
prototype.
* tests/test_atomic.c [(!_MSC_VER && !__MINGW32__ && !__BORLANDC__
|| AO_USE_NO_SIGNALS || AO_USE_WIN32_PTHREADS) && AO_TEST_EMULATION
&& AO_HAVE_double_t] (AO_compare_double_and_swap_double_emulation):
Likewise.
* tests/test_atomic.c (test_atomic_emulation): New function (or a macro
defined to empty if AO_*_emulation primitives are unavailable).
* tests/test_atomic.c (main): Call test_atomic_emulation().

tests/Makefile.am
tests/test_atomic.c

index a846292be64a6814872489cd2f3cee3812f0a9a1..35a89e90711c8808720de26885536bbb4483aaeb 100644 (file)
@@ -26,7 +26,8 @@ test_atomic_SOURCES=test_atomic.c
 test_atomic_LDADD = $(THREADDLLIBS) $(top_builddir)/src/libatomic_ops.la
 
 test_atomic_generalized_SOURCES=$(test_atomic_SOURCES)
-test_atomic_generalized_CPPFLAGS=-DAO_PREFER_GENERALIZED $(AM_CPPFLAGS)
+test_atomic_generalized_CPPFLAGS= \
+        -DAO_PREFER_GENERALIZED -DAO_TEST_EMULATION $(AM_CPPFLAGS)
 test_atomic_generalized_LDADD=$(test_atomic_LDADD)
 
 test_stack_SOURCES=test_stack.c
index 80818a414f2ce7d9b6e3a5711ddf359d718e39dc..5a25dacf99dde66119612d5b0c74ec160f8fdc59 100644 (file)
@@ -177,6 +177,46 @@ int test_and_set_test(void)
 
 #endif /* defined(AO_HAVE_test_and_set_acquire) */
 
+#if (!defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__BORLANDC__) \
+     || defined(AO_USE_NO_SIGNALS) || defined(AO_USE_WIN32_PTHREADS)) \
+    && defined(AO_TEST_EMULATION)
+
+  void AO_store_full_emulation(volatile AO_t *addr, AO_t val);
+  AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val,
+                                           AO_t new_val);
+# ifdef AO_HAVE_double_t
+    int AO_compare_double_and_swap_double_emulation(volatile AO_double_t *,
+                                                AO_t old_val1, AO_t old_val2,
+                                                AO_t new_val1, AO_t new_val2);
+# endif
+
+  void test_atomic_emulation(void)
+  {
+    AO_t x;
+#   ifdef AO_HAVE_double_t
+      AO_double_t w; /* double-word alignment not needed */
+
+      w.AO_val1 = 0;
+      w.AO_val2 = 0;
+      TA_assert(!AO_compare_double_and_swap_double_emulation(&w, 4116, 2121,
+                                                             8537, 6410));
+      TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
+      TA_assert(AO_compare_double_and_swap_double_emulation(&w, 0, 0,
+                                                            8537, 6410));
+      TA_assert(w.AO_val1 == 8537 && w.AO_val2 == 6410);
+#   endif
+    AO_store_full_emulation(&x, 1314);
+    TA_assert(x == 1314);
+    TA_assert(AO_fetch_compare_and_swap_emulation(&x, 14, 13117) == 1314);
+    TA_assert(x == 1314);
+    TA_assert(AO_fetch_compare_and_swap_emulation(&x, 1314, 14117) == 1314);
+    TA_assert(x == 14117);
+  }
+
+#else
+# define test_atomic_emulation() (void)0
+#endif /* _MSC_VER && !AO_USE_NO_SIGNALS || !AO_TEST_EMULATION */
+
 int main(void)
 {
   test_atomic();
@@ -199,6 +239,7 @@ int main(void)
     run_parallel(5, test_and_set_thr, test_and_set_test,
          "test_and_set");
 # endif
+  test_atomic_emulation();
   return 0;
 }