Fix: add missing sched.h include in rculfhash.c
[urcu.git] / tests / test_uatomic.c
CommitLineData
a81b8e5e 1#include <stdio.h>
a81b8e5e 2#include <assert.h>
a2e7bf9c 3#include <urcu/uatomic.h>
a81b8e5e
MD
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 { \
6edb297e 16 __typeof__(*(ptr)) v; \
87322fe8 17 \
ec4e58a3
MD
18 uatomic_add(ptr, 10); \
19 assert(uatomic_read(ptr) == 10); \
20 uatomic_add(ptr, -11UL); \
21 assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
22 v = uatomic_cmpxchg(ptr, -1UL, 22); \
23 assert(uatomic_read(ptr) == 22); \
6edb297e 24 assert(v == (__typeof__(*(ptr)))-1UL); \
ec4e58a3
MD
25 v = uatomic_cmpxchg(ptr, 33, 44); \
26 assert(uatomic_read(ptr) == 22); \
87322fe8 27 assert(v == 22); \
ec4e58a3
MD
28 v = uatomic_xchg(ptr, 55); \
29 assert(uatomic_read(ptr) == 55); \
87322fe8 30 assert(v == 22); \
ec4e58a3
MD
31 uatomic_set(ptr, 22); \
32 uatomic_inc(ptr); \
33 assert(uatomic_read(ptr) == 23); \
34 uatomic_dec(ptr); \
35 assert(uatomic_read(ptr) == 22); \
985b35b1
PB
36 v = uatomic_add_return(ptr, 74); \
37 assert(v == 96); \
38 assert(uatomic_read(ptr) == 96); \
39 uatomic_or(ptr, 58); \
ec4e58a3
MD
40 assert(uatomic_read(ptr) == 122); \
41 v = uatomic_sub_return(ptr, 1); \
0fad128b 42 assert(v == 121); \
ec4e58a3 43 assert(uatomic_read(ptr) == 121); \
bf33aaea
PB
44 uatomic_and(ptr, 129); \
45 assert(uatomic_read(ptr) == 1); \
87322fe8
MD
46} while (0)
47
48int main(int argc, char **argv)
a81b8e5e 49{
f469d839 50#ifdef UATOMIC_HAS_ATOMIC_BYTE
87322fe8 51 do_test(&vals.c);
4d78cb54 52#endif
f469d839 53#ifdef UATOMIC_HAS_ATOMIC_SHORT
87322fe8 54 do_test(&vals.s);
4d78cb54 55#endif
87322fe8
MD
56 do_test(&vals.i);
57 do_test(&vals.l);
58 printf("Atomic ops test OK\n");
59
60 return 0;
a81b8e5e 61}
This page took 0.027194 seconds and 4 git commands to generate.