X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_atomic.c;h=bf847572815012be866ff9b921c85b97ace1aa0d;hp=47cc319f9164381a92c6bb1e0ee374d8378bcd48;hb=87322fe8f9e201f9018dba7dfcf786b932cd899c;hpb=a81b8e5e402188a088c28e27c5e718b691109cf2 diff --git a/tests/test_atomic.c b/tests/test_atomic.c index 47cc319..bf84757 100644 --- a/tests/test_atomic.c +++ b/tests/test_atomic.c @@ -11,10 +11,32 @@ struct testvals { static struct testvals vals; -int main(int argc, void **argv) +#define do_test(ptr) \ +do { \ + __typeof__(*ptr) v; \ + \ + atomic_add(ptr, 10); \ + assert(*ptr == 10); \ + atomic_add(ptr, -11); \ + assert(*ptr == (__typeof__(*ptr))-1U); \ + v = cmpxchg(ptr, -1, 22); \ + assert(*ptr == 22); \ + assert(v == (__typeof__(*ptr))-1U); \ + v = cmpxchg(ptr, 33, 44); \ + assert(*ptr == 22); \ + assert(v == 22); \ + v = xchg(ptr, 55); \ + assert(*ptr == 55); \ + assert(v == 22); \ +} while (0) + +int main(int argc, char **argv) { - atomic_add(&vals.c, 10); - assert(vals.c == 10); - atomic_add(&vals.c, -11); - assert((char)vals.c == -1); + do_test(&vals.c); + do_test(&vals.s); + do_test(&vals.i); + do_test(&vals.l); + printf("Atomic ops test OK\n"); + + return 0; }