2 * Copyright (c) 2003 by Hewlett-Packard Company. All rights reserved.
4 * This file is covered by the GNU general public license, version 2.
5 * see doc/COPYING for details.
8 /* Some basic sanity tests. These do not test the barrier semantics. */
11 #define TA_assert(e) \
12 if (!(e)) { fprintf(stderr, "Assertion failed %s:%d (barrier: XX)\n", \
13 __FILE__, __LINE__), exit(1); }
16 #define MISSING(name) \
17 fprintf(stderr, "Missing: %s\n", #name "XX")
19 void test_atomicXX(void)
25 # if defined(AO_HAVE_test_and_setXX)
26 AO_TS_t z = AO_TS_INITIALIZER;
28 # if defined(AO_HAVE_double_t)
34 # if defined(AO_HAVE_nopXX)
39 # if defined(AO_HAVE_storeXX)
46 # if defined(AO_HAVE_loadXX)
47 TA_assert(AO_loadXX(&x) == 13);
51 # if defined(AO_HAVE_test_and_setXX)
52 assert(AO_test_and_setXX(&z) == AO_TS_CLEAR);
53 assert(AO_test_and_setXX(&z) == AO_TS_SET);
54 assert(AO_test_and_setXX(&z) == AO_TS_SET);
57 MISSING(AO_test_and_set);
59 # if defined(AO_HAVE_fetch_and_addXX)
60 TA_assert(AO_fetch_and_addXX(&x, 42) == 13);
61 TA_assert(AO_fetch_and_addXX(&x, -42) == 55);
63 MISSING(AO_fetch_and_add);
65 # if defined(AO_HAVE_fetch_and_add1XX)
66 TA_assert(AO_fetch_and_add1XX(&x) == 13);
68 MISSING(AO_fetch_and_add1);
71 # if defined(AO_HAVE_fetch_and_sub1XX)
72 TA_assert(AO_fetch_and_sub1XX(&x) == 14);
74 MISSING(AO_fetch_and_sub1);
77 # if defined(AO_HAVE_short_storeXX)
78 AO_short_storeXX(&s, 13);
80 MISSING(AO_short_store);
83 # if defined(AO_HAVE_short_loadXX)
84 TA_assert(AO_short_load(&s) == 13);
86 MISSING(AO_short_load);
88 # if defined(AO_HAVE_short_fetch_and_addXX)
89 TA_assert(AO_short_fetch_and_addXX(&s, 42) == 13);
90 TA_assert(AO_short_fetch_and_addXX(&s, -42) == 55);
92 MISSING(AO_short_fetch_and_add);
94 # if defined(AO_HAVE_short_fetch_and_add1XX)
95 TA_assert(AO_short_fetch_and_add1XX(&s) == 13);
97 MISSING(AO_short_fetch_and_add1);
100 # if defined(AO_HAVE_short_fetch_and_sub1XX)
101 TA_assert(AO_short_fetch_and_sub1XX(&s) == 14);
103 MISSING(AO_short_fetch_and_sub1);
106 # if defined(AO_HAVE_char_storeXX)
107 AO_char_storeXX(&b, 13);
109 MISSING(AO_char_store);
112 # if defined(AO_HAVE_char_loadXX)
113 TA_assert(AO_char_load(&b) == 13);
115 MISSING(AO_char_load);
117 # if defined(AO_HAVE_char_fetch_and_addXX)
118 TA_assert(AO_char_fetch_and_addXX(&b, 42) == 13);
119 TA_assert(AO_char_fetch_and_addXX(&b, -42) == 55);
121 MISSING(AO_char_fetch_and_add);
123 # if defined(AO_HAVE_char_fetch_and_add1XX)
124 TA_assert(AO_char_fetch_and_add1XX(&b) == 13);
126 MISSING(AO_char_fetch_and_add1);
129 # if defined(AO_HAVE_char_fetch_and_sub1XX)
130 TA_assert(AO_char_fetch_and_sub1XX(&b) == 14);
132 MISSING(AO_char_fetch_and_sub1);
135 # if defined(AO_HAVE_int_storeXX)
136 AO_int_storeXX(&zz, 13);
138 MISSING(AO_int_store);
141 # if defined(AO_HAVE_int_loadXX)
142 TA_assert(AO_int_load(&zz) == 13);
144 MISSING(AO_int_load);
146 # if defined(AO_HAVE_int_fetch_and_addXX)
147 TA_assert(AO_int_fetch_and_addXX(&zz, 42) == 13);
148 TA_assert(AO_int_fetch_and_addXX(&zz, -42) == 55);
150 MISSING(AO_int_fetch_and_add);
152 # if defined(AO_HAVE_int_fetch_and_add1XX)
153 TA_assert(AO_int_fetch_and_add1XX(&zz) == 13);
155 MISSING(AO_int_fetch_and_add1);
158 # if defined(AO_HAVE_int_fetch_and_sub1XX)
159 TA_assert(AO_int_fetch_and_sub1XX(&zz) == 14);
161 MISSING(AO_int_fetch_and_sub1);
164 # if defined(AO_HAVE_compare_and_swapXX)
165 TA_assert(!AO_compare_and_swapXX(&x, 14, 42));
167 TA_assert(AO_compare_and_swapXX(&x, 13, 42));
170 MISSING(AO_compare_and_swap);
173 # if defined(AO_HAVE_orXX)
180 # if defined(AO_HAVE_compare_double_and_swap_doubleXX)
181 TA_assert(!AO_compare_double_and_swap_doubleXX(&w, 17, 42, 12, 13));
182 TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
183 TA_assert(AO_compare_double_and_swap_doubleXX(&w, 0, 0, 12, 13));
184 TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
185 TA_assert(AO_compare_double_and_swap_doubleXX(&w, 12, 13, 17, 42));
186 TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
187 w.AO_val1 = 0; w.AO_val2 = 0;
189 MISSING(AO_compare_double_and_swap_double);
191 # if defined(AO_HAVE_compare_and_swap_doubleXX)
192 TA_assert(!AO_compare_and_swap_doubleXX(&w, 17, 12, 13));
193 TA_assert(w.AO_val1 == 0 && w.AO_val2 == 0);
194 TA_assert(AO_compare_and_swap_doubleXX(&w, 0, 12, 13));
195 TA_assert(w.AO_val1 == 12 && w.AO_val2 == 13);
196 TA_assert(AO_compare_and_swap_doubleXX(&w, 12, 17, 42));
197 TA_assert(w.AO_val1 == 17 && w.AO_val2 == 42);
199 MISSING(AO_compare_and_swap_double);