update x86 and ppc atomic ops
[urcu.git] / tests / test_atomic.c
1 #include <stdio.h>
2 #include <arch_atomic.h>
3 #include <assert.h>
4
5 struct testvals {
6 unsigned char c;
7 unsigned short s;
8 unsigned int i;
9 unsigned long l;
10 };
11
12 static struct testvals vals;
13
14 #define do_test(ptr) \
15 do { \
16 __typeof__(*(ptr)) v; \
17 \
18 atomic_add(ptr, 10); \
19 assert(atomic_read(ptr) == 10); \
20 atomic_add(ptr, -11UL); \
21 assert(atomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
22 v = cmpxchg(ptr, -1UL, 22); \
23 assert(atomic_read(ptr) == 22); \
24 assert(v == (__typeof__(*(ptr)))-1UL); \
25 v = cmpxchg(ptr, 33, 44); \
26 assert(atomic_read(ptr) == 22); \
27 assert(v == 22); \
28 v = xchg(ptr, 55); \
29 assert(atomic_read(ptr) == 55); \
30 assert(v == 22); \
31 atomic_set(ptr, 22); \
32 atomic_inc(ptr); \
33 assert(atomic_read(ptr) == 23); \
34 atomic_dec(ptr); \
35 assert(atomic_read(ptr) == 22); \
36 v = atomic_add_return(ptr, 100); \
37 assert(v == 122); \
38 assert(atomic_read(ptr) == 122); \
39 v = atomic_sub_return(ptr, 1); \
40 assert(v == 121); \
41 assert(atomic_read(ptr) == 121); \
42 } while (0)
43
44 int main(int argc, char **argv)
45 {
46 do_test(&vals.c);
47 do_test(&vals.s);
48 do_test(&vals.i);
49 do_test(&vals.l);
50 printf("Atomic ops test OK\n");
51
52 return 0;
53 }
This page took 0.038946 seconds and 4 git commands to generate.