3d2b64e434d3ef97eb0feec03a2c49968b96bc2e
[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(*(ptr) == 10); \
20 atomic_add(ptr, -11UL); \
21 assert(*(ptr) == (__typeof__(*(ptr)))-1UL); \
22 v = cmpxchg(ptr, -1UL, 22); \
23 assert(*(ptr) == 22); \
24 assert(v == (__typeof__(*(ptr)))-1UL); \
25 v = cmpxchg(ptr, 33, 44); \
26 assert(*(ptr) == 22); \
27 assert(v == 22); \
28 v = xchg(ptr, 55); \
29 assert(*(ptr) == 55); \
30 assert(v == 22); \
31 } while (0)
32
33 int main(int argc, char **argv)
34 {
35 do_test(&vals.c);
36 do_test(&vals.s);
37 do_test(&vals.i);
38 do_test(&vals.l);
39 printf("Atomic ops test OK\n");
40
41 return 0;
42 }
This page took 0.03911 seconds and 3 git commands to generate.