1 // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: GPL-2.0-or-later
6 #include <urcu/uatomic.h>
13 #ifdef UATOMIC_HAS_ATOMIC_BYTE
16 #ifdef UATOMIC_HAS_ATOMIC_SHORT
23 static struct testvals vals
;
25 #define do_test(ptr) \
27 __typeof__(*(ptr)) v; \
29 uatomic_add(ptr, 10); \
30 ok1(uatomic_read(ptr) == 10); \
32 uatomic_add(ptr, -11UL); \
33 ok1(uatomic_read(ptr) == (__typeof__(*(ptr)))-1UL); \
35 v = uatomic_cmpxchg(ptr, -1UL, 22); \
36 ok1(uatomic_read(ptr) == 22); \
37 ok1(v == (__typeof__(*(ptr)))-1UL); \
39 v = uatomic_cmpxchg(ptr, 33, 44); \
40 ok1(uatomic_read(ptr) == 22); \
43 v = uatomic_xchg(ptr, 55); \
44 ok1(uatomic_read(ptr) == 55); \
47 uatomic_set(ptr, 22); \
49 ok1(uatomic_read(ptr) == 23); \
52 ok1(uatomic_read(ptr) == 22); \
54 v = uatomic_add_return(ptr, 74); \
56 ok1(uatomic_read(ptr) == 96); \
58 uatomic_or(ptr, 58); \
59 ok1(uatomic_read(ptr) == 122); \
61 v = uatomic_sub_return(ptr, 1); \
64 uatomic_sub(ptr, (unsigned int) 2); \
65 ok1(uatomic_read(ptr) == 119); \
69 ok1(uatomic_read(ptr) == 121); \
71 uatomic_and(ptr, 129); \
72 ok1(uatomic_read(ptr) == 1); \
79 #ifdef UATOMIC_HAS_ATOMIC_BYTE
82 #ifdef UATOMIC_HAS_ATOMIC_SHORT
86 plan_tests(nr_run
* NR_TESTS
);
87 #ifdef UATOMIC_HAS_ATOMIC_BYTE
88 diag("Test atomic ops on byte");
91 #ifdef UATOMIC_HAS_ATOMIC_SHORT
92 diag("Test atomic ops on short");
95 diag("Test atomic ops on int");
97 diag("Test atomic ops on long");
100 return exit_status();
This page took 0.031395 seconds and 4 git commands to generate.