convert to autotools
[urcu.git] / tests / test_uatomic.c
1 #include <stdio.h>
2 #include <assert.h>
3 #include <urcu/uatomic_arch.h>
4
5 #if (defined(__i386__) || defined(__x86_64__))
6 #define HAS_ATOMIC_BYTE
7 #define HAS_ATOMIC_SHORT
8 #endif
9
10 struct testvals {
11 #ifdef HAS_ATOMIC_BYTE
12 unsigned char c;
13 #endif
14 #ifdef HAS_ATOMIC_SHORT
15 unsigned short s;
16 #endif
17 unsigned int i;
18 unsigned long l;
19 };
20
21 static struct testvals vals;
22
23 #define do_test(ptr) \
24 do { \
25 __typeof__(*(ptr)) v; \
26 \
27 uatomic_add(ptr, 10); \
28 assert(uatomic_read(ptr) == 10); \
29 uatomic_add(ptr, -11UL); \
30 assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
31 v = uatomic_cmpxchg(ptr, -1UL, 22); \
32 assert(uatomic_read(ptr) == 22); \
33 assert(v == (__typeof__(*(ptr)))-1UL); \
34 v = uatomic_cmpxchg(ptr, 33, 44); \
35 assert(uatomic_read(ptr) == 22); \
36 assert(v == 22); \
37 v = uatomic_xchg(ptr, 55); \
38 assert(uatomic_read(ptr) == 55); \
39 assert(v == 22); \
40 uatomic_set(ptr, 22); \
41 uatomic_inc(ptr); \
42 assert(uatomic_read(ptr) == 23); \
43 uatomic_dec(ptr); \
44 assert(uatomic_read(ptr) == 22); \
45 v = uatomic_add_return(ptr, 100); \
46 assert(v == 122); \
47 assert(uatomic_read(ptr) == 122); \
48 v = uatomic_sub_return(ptr, 1); \
49 assert(v == 121); \
50 assert(uatomic_read(ptr) == 121); \
51 } while (0)
52
53 int main(int argc, char **argv)
54 {
55 #ifdef HAS_ATOMIC_BYTE
56 do_test(&vals.c);
57 #endif
58 #ifdef HAS_ATOMIC_SHORT
59 do_test(&vals.s);
60 #endif
61 do_test(&vals.i);
62 do_test(&vals.l);
63 printf("Atomic ops test OK\n");
64
65 return 0;
66 }
This page took 0.040515 seconds and 4 git commands to generate.