diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2016-11-01 12:18:33 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2016-11-01 12:18:33 +0300 |
commit | 020bdf20b8f972a32e93064b2d836aab1ed23d83 (patch) | |
tree | 1b08404bdcc02db7e12d69fcdc7251623dd0ae21 | |
parent | 9b5c548da220b8ffb07661c5c8fe0bbbee894725 (diff) | |
download | libatomic_ops-020bdf20b8f972a32e93064b2d836aab1ed23d83.tar.gz |
Add *_and/or/xor* and *_[fetch_]compare_and_swap* tests to test_atomic
Previously, only AO_and/or/xor and AO_[fetch]_CAS tests (for AO_t)
existed in test_atomic.
* tests/test_atomic_include.template (test_atomicXX): Add minimal
testing of AO_short_compare_and_swapXX, AO_short_orXX, AO_short_xorXX,
AO_short_andXX, AO_short_fetch_compare_and_swapXX,
AO_char_compare_and_swapXX, AO_char_orXX, AO_char_xorXX, AO_char_andXX,
AO_char_fetch_compare_and_swapXX, AO_int_compare_and_swapXX,
AO_int_orXX, AO_int_xorXX, AO_int_andXX,
AO_int_fetch_compare_and_swapXX.
-rw-r--r-- | tests/test_atomic_include.template | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/tests/test_atomic_include.template b/tests/test_atomic_include.template index fe88e19..f665aac 100644 --- a/tests/test_atomic_include.template +++ b/tests/test_atomic_include.template @@ -275,6 +275,188 @@ void test_atomicXX(void) if (x == 25) x = 117; # endif TA_assert(x == 117); +# if defined(AO_HAVE_short_compare_and_swapXX) + TA_assert(!AO_short_compare_and_swapXX(&s, 14, 42)); + TA_assert(s == 13); + TA_assert(AO_short_compare_and_swapXX(&s, 13, 42)); + TA_assert(s == 42); +# else + MISSING(AO_short_compare_and_swap); + if (*(volatile short *)&s == 13) s = 42; +# endif +# if defined(AO_HAVE_short_orXX) + AO_short_orXX(&s, 66); + TA_assert(s == 106); +# else +# if !defined(AO_HAVE_short_or) || !defined(AO_HAVE_short_or_acquire) \ + || !defined(AO_HAVE_short_or_acquire_read) \ + || !defined(AO_HAVE_short_or_full) || !defined(AO_HAVE_short_or_read) \ + || !defined(AO_HAVE_short_or_release) \ + || !defined(AO_HAVE_short_or_release_write) \ + || !defined(AO_HAVE_short_or_write) + MISSING(AO_short_or); +# endif + s |= 66; +# endif +# if defined(AO_HAVE_short_xorXX) + AO_short_xorXX(&s, 181); + TA_assert(s == 223); +# else +# if !defined(AO_HAVE_short_xor) || !defined(AO_HAVE_short_xor_acquire) \ + || !defined(AO_HAVE_short_xor_acquire_read) \ + || !defined(AO_HAVE_short_xor_full) \ + || !defined(AO_HAVE_short_xor_read) \ + || !defined(AO_HAVE_short_xor_release) \ + || !defined(AO_HAVE_short_xor_release_write) \ + || !defined(AO_HAVE_short_xor_write) + MISSING(AO_short_xor); +# endif + s ^= 181; +# endif +# if defined(AO_HAVE_short_andXX) + AO_short_andXX(&s, 57); + TA_assert(s == 25); +# else +# if !defined(AO_HAVE_short_and) || !defined(AO_HAVE_short_and_acquire) \ + || !defined(AO_HAVE_short_and_acquire_read) \ + || !defined(AO_HAVE_short_and_full) \ + || !defined(AO_HAVE_short_and_read) \ + || !defined(AO_HAVE_short_and_release) \ + || !defined(AO_HAVE_short_and_release_write) \ + || !defined(AO_HAVE_short_and_write) + MISSING(AO_short_and); +# endif + s &= 57; +# endif +# if defined(AO_HAVE_short_fetch_compare_and_swapXX) + TA_assert(AO_short_fetch_compare_and_swapXX(&s, 14, 117) == 25); + TA_assert(s == 25); + TA_assert(AO_short_fetch_compare_and_swapXX(&s, 25, 117) == 25); +# else + MISSING(AO_short_fetch_compare_and_swap); + if (s == 25) s = 117; +# endif + TA_assert(s == 117); +# if defined(AO_HAVE_char_compare_and_swapXX) + TA_assert(!AO_char_compare_and_swapXX(&b, 14, 42)); + TA_assert(b == 13); + TA_assert(AO_char_compare_and_swapXX(&b, 13, 42)); + TA_assert(b == 42); +# else + MISSING(AO_char_compare_and_swap); + if (*(volatile char *)&b == 13) b = 42; +# endif +# if defined(AO_HAVE_char_orXX) + AO_char_orXX(&b, 66); + TA_assert(b == 106); +# else +# if !defined(AO_HAVE_char_or) || !defined(AO_HAVE_char_or_acquire) \ + || !defined(AO_HAVE_char_or_acquire_read) \ + || !defined(AO_HAVE_char_or_full) || !defined(AO_HAVE_char_or_read) \ + || !defined(AO_HAVE_char_or_release) \ + || !defined(AO_HAVE_char_or_release_write) \ + || !defined(AO_HAVE_char_or_write) + MISSING(AO_char_or); +# endif + b |= 66; +# endif +# if defined(AO_HAVE_char_xorXX) + AO_char_xorXX(&b, 181); + TA_assert(b == 223); +# else +# if !defined(AO_HAVE_char_xor) || !defined(AO_HAVE_char_xor_acquire) \ + || !defined(AO_HAVE_char_xor_acquire_read) \ + || !defined(AO_HAVE_char_xor_full) || !defined(AO_HAVE_char_xor_read) \ + || !defined(AO_HAVE_char_xor_release) \ + || !defined(AO_HAVE_char_xor_release_write) \ + || !defined(AO_HAVE_char_xor_write) + MISSING(AO_char_xor); +# endif + b ^= 181; +# endif +# if defined(AO_HAVE_char_andXX) + AO_char_andXX(&b, 57); + TA_assert(b == 25); +# else +# if !defined(AO_HAVE_char_and) || !defined(AO_HAVE_char_and_acquire) \ + || !defined(AO_HAVE_char_and_acquire_read) \ + || !defined(AO_HAVE_char_and_full) || !defined(AO_HAVE_char_and_read) \ + || !defined(AO_HAVE_char_and_release) \ + || !defined(AO_HAVE_char_and_release_write) \ + || !defined(AO_HAVE_char_and_write) + MISSING(AO_char_and); +# endif + b &= 57; +# endif +# if defined(AO_HAVE_char_fetch_compare_and_swapXX) + TA_assert(AO_char_fetch_compare_and_swapXX(&b, 14, 117) == 25); + TA_assert(b == 25); + TA_assert(AO_char_fetch_compare_and_swapXX(&b, 25, 117) == 25); +# else + MISSING(AO_char_fetch_compare_and_swap); + if (b == 25) b = 117; +# endif + TA_assert(b == 117); +# if defined(AO_HAVE_int_compare_and_swapXX) + TA_assert(!AO_int_compare_and_swapXX(&zz, 14, 42)); + TA_assert(zz == 13); + TA_assert(AO_int_compare_and_swapXX(&zz, 13, 42)); + TA_assert(zz == 42); +# else + MISSING(AO_int_compare_and_swap); + if (*(volatile int *)&zz == 13) zz = 42; +# endif +# if defined(AO_HAVE_int_orXX) + AO_int_orXX(&zz, 66); + TA_assert(zz == 106); +# else +# if !defined(AO_HAVE_int_or) || !defined(AO_HAVE_int_or_acquire) \ + || !defined(AO_HAVE_int_or_acquire_read) \ + || !defined(AO_HAVE_int_or_full) || !defined(AO_HAVE_int_or_read) \ + || !defined(AO_HAVE_int_or_release) \ + || !defined(AO_HAVE_int_or_release_write) \ + || !defined(AO_HAVE_int_or_write) + MISSING(AO_int_or); +# endif + zz |= 66; +# endif +# if defined(AO_HAVE_int_xorXX) + AO_int_xorXX(&zz, 181); + TA_assert(zz == 223); +# else +# if !defined(AO_HAVE_int_xor) || !defined(AO_HAVE_int_xor_acquire) \ + || !defined(AO_HAVE_int_xor_acquire_read) \ + || !defined(AO_HAVE_int_xor_full) || !defined(AO_HAVE_int_xor_read) \ + || !defined(AO_HAVE_int_xor_release) \ + || !defined(AO_HAVE_int_xor_release_write) \ + || !defined(AO_HAVE_int_xor_write) + MISSING(AO_int_xor); +# endif + zz ^= 181; +# endif +# if defined(AO_HAVE_int_andXX) + AO_int_andXX(&zz, 57); + TA_assert(zz == 25); +# else +# if !defined(AO_HAVE_int_and) || !defined(AO_HAVE_int_and_acquire) \ + || !defined(AO_HAVE_int_and_acquire_read) \ + || !defined(AO_HAVE_int_and_full) || !defined(AO_HAVE_int_and_read) \ + || !defined(AO_HAVE_int_and_release) \ + || !defined(AO_HAVE_int_and_release_write) \ + || !defined(AO_HAVE_int_and_write) + MISSING(AO_int_and); +# endif + zz &= 57; +# endif +# if defined(AO_HAVE_int_fetch_compare_and_swapXX) + TA_assert(AO_int_fetch_compare_and_swapXX(&zz, 14, 117) == 25); + TA_assert(zz == 25); + TA_assert(AO_int_fetch_compare_and_swapXX(&zz, 25, 117) == 25); +# else + MISSING(AO_int_fetch_compare_and_swap); + if (zz == 25) zz = 117; +# endif + TA_assert(zz == 117); # if defined(AO_HAVE_double_loadXX) old_w.AO_val1 = 3316; old_w.AO_val2 = 2921; |