Add inc/dec x86 atomics
[urcu.git] / tests / test_atomic.c
CommitLineData
a81b8e5e
MD
1#include <stdio.h>
2#include <arch_atomic.h>
3#include <assert.h>
4
5struct testvals {
6 unsigned char c;
7 unsigned short s;
8 unsigned int i;
9 unsigned long l;
10};
11
12static struct testvals vals;
13
87322fe8
MD
14#define do_test(ptr) \
15do { \
16 __typeof__(*ptr) v; \
17 \
18 atomic_add(ptr, 10); \
19 assert(*ptr == 10); \
20 atomic_add(ptr, -11); \
21 assert(*ptr == (__typeof__(*ptr))-1U); \
22 v = cmpxchg(ptr, -1, 22); \
23 assert(*ptr == 22); \
24 assert(v == (__typeof__(*ptr))-1U); \
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
33int main(int argc, char **argv)
a81b8e5e 34{
87322fe8
MD
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;
a81b8e5e 42}
This page took 0.031356 seconds and 4 git commands to generate.