4 * Userspace RCU library - test atomic operations
6 * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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.
24 #include <urcu/uatomic.h>
31 #ifdef UATOMIC_HAS_ATOMIC_BYTE
34 #ifdef UATOMIC_HAS_ATOMIC_SHORT
41 static struct testvals vals
;
43 #define do_test(ptr) \
45 __typeof__(*(ptr)) v; \
47 uatomic_add(ptr, 10); \
48 ok1(uatomic_read(ptr) == 10); \
50 uatomic_add(ptr, -11UL); \
51 ok1(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
53 v = uatomic_cmpxchg(ptr, -1UL, 22); \
54 ok1(uatomic_read(ptr) == 22); \
55 ok1(v == (__typeof__(*(ptr)))-1UL); \
57 v = uatomic_cmpxchg(ptr, 33, 44); \
58 ok1(uatomic_read(ptr) == 22); \
61 v = uatomic_xchg(ptr, 55); \
62 ok1(uatomic_read(ptr) == 55); \
65 uatomic_set(ptr, 22); \
67 ok1(uatomic_read(ptr) == 23); \
70 ok1(uatomic_read(ptr) == 22); \
72 v = uatomic_add_return(ptr, 74); \
74 ok1(uatomic_read(ptr) == 96); \
76 uatomic_or(ptr, 58); \
77 ok1(uatomic_read(ptr) == 122); \
79 v = uatomic_sub_return(ptr, 1); \
82 uatomic_sub(ptr, (unsigned int) 2); \
83 ok1(uatomic_read(ptr) == 119); \
87 ok1(uatomic_read(ptr) == 121); \
89 uatomic_and(ptr, 129); \
90 ok1(uatomic_read(ptr) == 1); \
97 #ifdef UATOMIC_HAS_ATOMIC_BYTE
100 #ifdef UATOMIC_HAS_ATOMIC_SHORT
104 plan_tests(nr_run
* NR_TESTS
);
105 #ifdef UATOMIC_HAS_ATOMIC_BYTE
106 diag("Test atomic ops on byte");
109 #ifdef UATOMIC_HAS_ATOMIC_SHORT
110 diag("Test atomic ops on short");
113 diag("Test atomic ops on int");
115 diag("Test atomic ops on long");
118 return exit_status();
This page took 0.032014 seconds and 5 git commands to generate.