From: Ivan Maidanski Date: Fri, 3 Feb 2017 16:19:32 +0000 (+0300) Subject: Test store/CAS emulation explicitly X-Git-Tag: v7.6.0~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0add78973e4d92adbc0c53c7084210d518fbe530;p=libatomic_ops Test store/CAS emulation explicitly * 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(). --- diff --git a/tests/Makefile.am b/tests/Makefile.am index a846292..35a89e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/test_atomic.c b/tests/test_atomic.c index 80818a4..5a25dac 100644 --- a/tests/test_atomic.c +++ b/tests/test_atomic.c @@ -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; }