1 /* Tests for atomic.h macros.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 /* Test various atomic.h macros. */
35 #ifdef atomic_compare_and_exchange_val_acq
37 if (atomic_compare_and_exchange_val_acq (&mem, 35, 24) != 24
40 puts ("atomic_compare_and_exchange_val_acq test 1 failed");
45 if (atomic_compare_and_exchange_val_acq (&mem, 10, 15) != 12
48 puts ("atomic_compare_and_exchange_val_acq test 2 failed");
53 if (atomic_compare_and_exchange_val_acq (&mem, -56, -15) != -15
56 puts ("atomic_compare_and_exchange_val_acq test 3 failed");
61 if (atomic_compare_and_exchange_val_acq (&mem, 17, 0) != -1
64 puts ("atomic_compare_and_exchange_val_acq test 4 failed");
70 if (atomic_compare_and_exchange_bool_acq (&mem, 35, 24)
73 puts ("atomic_compare_and_exchange_bool_acq test 1 failed");
78 if (! atomic_compare_and_exchange_bool_acq (&mem, 10, 15)
81 puts ("atomic_compare_and_exchange_bool_acq test 2 failed");
86 if (atomic_compare_and_exchange_bool_acq (&mem, -56, -15)
89 puts ("atomic_compare_and_exchange_bool_acq test 3 failed");
94 if (! atomic_compare_and_exchange_bool_acq (&mem, 17, 0)
97 puts ("atomic_compare_and_exchange_bool_acq test 4 failed");
102 if (atomic_exchange_acq (&mem, 31) != 64
105 puts ("atomic_exchange_acq test failed");
110 if (atomic_exchange_and_add (&mem, 11) != 2
113 puts ("atomic_exchange_and_add test failed");
118 atomic_add (&mem, 22);
121 puts ("atomic_add test failed");
126 atomic_increment (&mem);
129 puts ("atomic_increment test failed");
134 if (atomic_increment_and_test (&mem)
137 puts ("atomic_increment_and_test test 1 failed");
142 if (atomic_increment_and_test (&mem)
145 puts ("atomic_increment_and_test test 2 failed");
150 if (! atomic_increment_and_test (&mem)
153 puts ("atomic_increment_and_test test 3 failed");
158 atomic_decrement (&mem);
161 puts ("atomic_decrement test failed");
166 if (atomic_decrement_and_test (&mem)
169 puts ("atomic_decrement_and_test test 1 failed");
174 if (atomic_decrement_and_test (&mem)
177 puts ("atomic_decrement_and_test test 2 failed");
182 if (! atomic_decrement_and_test (&mem)
185 puts ("atomic_decrement_and_test test 3 failed");
190 if (atomic_decrement_if_positive (&mem) != 1
193 puts ("atomic_decrement_if_positive test 1 failed");
198 if (atomic_decrement_if_positive (&mem) != 0
201 puts ("atomic_decrement_if_positive test 2 failed");
206 if (atomic_decrement_if_positive (&mem) != -1
209 puts ("atomic_decrement_if_positive test 3 failed");
214 if (! atomic_add_negative (&mem, 10)
217 puts ("atomic_add_negative test 1 failed");
222 if (atomic_add_negative (&mem, 100)
225 puts ("atomic_add_negative test 2 failed");
230 if (atomic_add_negative (&mem, -10)
233 puts ("atomic_add_negative test 3 failed");
238 if (atomic_add_negative (&mem, 14)
241 puts ("atomic_add_negative test 4 failed");
246 if (! atomic_add_negative (&mem, -1)
249 puts ("atomic_add_negative test 5 failed");
254 if (atomic_add_negative (&mem, 31)
257 puts ("atomic_add_negative test 6 failed");
262 if (atomic_add_zero (&mem, 31)
265 puts ("atomic_add_zero test 1 failed");
270 if (! atomic_add_zero (&mem, 36)
273 puts ("atomic_add_zero test 2 failed");
278 if (atomic_add_zero (&mem, -13)
281 puts ("atomic_add_zero test 3 failed");
286 if (atomic_add_zero (&mem, 20)
289 puts ("atomic_add_zero test 4 failed");
294 if (atomic_add_zero (&mem, -20)
297 puts ("atomic_add_zero test 5 failed");
302 if (! atomic_add_zero (&mem, -10)
305 puts ("atomic_add_zero test 6 failed");
310 atomic_bit_set (&mem, 1);
313 puts ("atomic_bit_set test 1 failed");
318 atomic_bit_set (&mem, 3);
321 puts ("atomic_bit_set test 2 failed");
327 atomic_bit_set (&mem, 35);
328 if (mem != 0x800000010LL)
330 puts ("atomic_bit_set test 3 failed");
336 if (atomic_bit_test_set (&mem, 1)
339 puts ("atomic_bit_test_set test 1 failed");
344 if (! atomic_bit_test_set (&mem, 3)
347 puts ("atomic_bit_test_set test 2 failed");
353 if (atomic_bit_test_set (&mem, 35)
354 || mem != 0x800000010LL)
356 puts ("atomic_bit_test_set test 3 failed");
361 if (! atomic_bit_test_set (&mem, 32)
362 || mem != 0x100000000LL)
364 puts ("atomic_bit_test_set test 4 failed");
372 #define TEST_FUNCTION do_test ()
373 #include "../test-skeleton.c"