Test cleanup: replace "l" parameter by "loops"
[urcu.git] / tests / test_uatomic.c
1 /*
2 * test_uatomic.c
3 *
4 * Userspace RCU library - test atomic operations
5 *
6 * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include <stdio.h>
24 #include <assert.h>
25 #include <urcu/uatomic.h>
26
27 struct testvals {
28 unsigned char c;
29 unsigned short s;
30 unsigned int i;
31 unsigned long l;
32 };
33
34 static struct testvals vals;
35
36 #define do_test(ptr) \
37 do { \
38 __typeof__(*(ptr)) v; \
39 \
40 uatomic_add(ptr, 10); \
41 assert(uatomic_read(ptr) == 10); \
42 uatomic_add(ptr, -11UL); \
43 assert(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
44 v = uatomic_cmpxchg(ptr, -1UL, 22); \
45 assert(uatomic_read(ptr) == 22); \
46 assert(v == (__typeof__(*(ptr)))-1UL); \
47 v = uatomic_cmpxchg(ptr, 33, 44); \
48 assert(uatomic_read(ptr) == 22); \
49 assert(v == 22); \
50 v = uatomic_xchg(ptr, 55); \
51 assert(uatomic_read(ptr) == 55); \
52 assert(v == 22); \
53 uatomic_set(ptr, 22); \
54 uatomic_inc(ptr); \
55 assert(uatomic_read(ptr) == 23); \
56 uatomic_dec(ptr); \
57 assert(uatomic_read(ptr) == 22); \
58 v = uatomic_add_return(ptr, 74); \
59 assert(v == 96); \
60 assert(uatomic_read(ptr) == 96); \
61 uatomic_or(ptr, 58); \
62 assert(uatomic_read(ptr) == 122); \
63 v = uatomic_sub_return(ptr, 1); \
64 assert(v == 121); \
65 uatomic_sub(ptr, (unsigned int) 2); \
66 assert(uatomic_read(ptr) == 119); \
67 uatomic_inc(ptr); \
68 uatomic_inc(ptr); \
69 assert(uatomic_read(ptr) == 121); \
70 uatomic_and(ptr, 129); \
71 assert(uatomic_read(ptr) == 1); \
72 } while (0)
73
74 int main(int argc, char **argv)
75 {
76 #ifdef UATOMIC_HAS_ATOMIC_BYTE
77 do_test(&vals.c);
78 #endif
79 #ifdef UATOMIC_HAS_ATOMIC_SHORT
80 do_test(&vals.s);
81 #endif
82 do_test(&vals.i);
83 do_test(&vals.l);
84 printf("Atomic ops test OK\n");
85
86 return 0;
87 }
This page took 0.030593 seconds and 4 git commands to generate.