X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Funit%2Ftest_uatomic.c;h=fe2a6c1b8751794190261539d9cb276958fcee48;hp=804ce7bd8a79b1945f9fcd9ea5098d3f34a7a971;hb=1b3874915095deab4aa9be0f33423e992e571bb7;hpb=f356e6f340eae0be1d5560c44a84cb0ed3839632 diff --git a/tests/unit/test_uatomic.c b/tests/unit/test_uatomic.c index 804ce7b..fe2a6c1 100644 --- a/tests/unit/test_uatomic.c +++ b/tests/unit/test_uatomic.c @@ -21,9 +21,12 @@ */ #include -#include #include +#include "tap.h" + +#define NR_TESTS 17 + struct testvals { #ifdef UATOMIC_HAS_ATOMIC_BYTE unsigned char c; @@ -42,50 +45,75 @@ do { \ __typeof__(*(ptr)) v; \ \ uatomic_add(ptr, 10); \ - assert(uatomic_read(ptr) == 10); \ - uatomic_add(ptr, -11UL); \ - assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \ - v = uatomic_cmpxchg(ptr, -1UL, 22); \ - assert(uatomic_read(ptr) == 22); \ - assert(v == (__typeof__(*(ptr)))-1UL); \ - v = uatomic_cmpxchg(ptr, 33, 44); \ - assert(uatomic_read(ptr) == 22); \ - assert(v == 22); \ - v = uatomic_xchg(ptr, 55); \ - assert(uatomic_read(ptr) == 55); \ - assert(v == 22); \ + ok1(uatomic_read(ptr) == 10); \ + \ + uatomic_add(ptr, -11UL); \ + ok1(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \ + \ + v = uatomic_cmpxchg(ptr, -1UL, 22); \ + ok1(uatomic_read(ptr) == 22); \ + ok1(v == (__typeof__(*(ptr)))-1UL); \ + \ + v = uatomic_cmpxchg(ptr, 33, 44); \ + ok1(uatomic_read(ptr) == 22); \ + ok1(v == 22); \ + \ + v = uatomic_xchg(ptr, 55); \ + ok1(uatomic_read(ptr) == 55); \ + ok1(v == 22); \ + \ uatomic_set(ptr, 22); \ uatomic_inc(ptr); \ - assert(uatomic_read(ptr) == 23); \ + ok1(uatomic_read(ptr) == 23); \ + \ uatomic_dec(ptr); \ - assert(uatomic_read(ptr) == 22); \ + ok1(uatomic_read(ptr) == 22); \ + \ v = uatomic_add_return(ptr, 74); \ - assert(v == 96); \ - assert(uatomic_read(ptr) == 96); \ + ok1(v == 96); \ + ok1(uatomic_read(ptr) == 96); \ + \ uatomic_or(ptr, 58); \ - assert(uatomic_read(ptr) == 122); \ + ok1(uatomic_read(ptr) == 122); \ + \ v = uatomic_sub_return(ptr, 1); \ - assert(v == 121); \ + ok1(v == 121); \ + \ uatomic_sub(ptr, (unsigned int) 2); \ - assert(uatomic_read(ptr) == 119); \ + ok1(uatomic_read(ptr) == 119); \ + \ uatomic_inc(ptr); \ uatomic_inc(ptr); \ - assert(uatomic_read(ptr) == 121); \ + ok1(uatomic_read(ptr) == 121); \ + \ uatomic_and(ptr, 129); \ - assert(uatomic_read(ptr) == 1); \ + ok1(uatomic_read(ptr) == 1); \ + \ } while (0) int main(int argc, char **argv) { + int nr_run = 2; +#ifdef UATOMIC_HAS_ATOMIC_BYTE + nr_run += 1; +#endif +#ifdef UATOMIC_HAS_ATOMIC_SHORT + nr_run += 1; +#endif + + plan_tests(nr_run * NR_TESTS); #ifdef UATOMIC_HAS_ATOMIC_BYTE + diag("Test atomic ops on byte"); do_test(&vals.c); #endif #ifdef UATOMIC_HAS_ATOMIC_SHORT + diag("Test atomic ops on short"); do_test(&vals.s); #endif + diag("Test atomic ops on int"); do_test(&vals.i); + diag("Test atomic ops on long"); do_test(&vals.l); - printf("Atomic ops test OK\n"); - return 0; + return exit_status(); }