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");
54 if (atomic_compare_and_exchange_bool_acq (&mem, 35, 24)
57 puts ("atomic_compare_and_exchange_bool_acq test 1 failed");
62 if (! atomic_compare_and_exchange_bool_acq (&mem, 10, 15)
65 puts ("atomic_compare_and_exchange_bool_acq test 2 failed");
70 if (atomic_exchange (&mem, 31) != 64
73 puts ("atomic_exchange test failed");
78 if (atomic_exchange_and_add (&mem, 11) != 2
81 puts ("atomic_exchange_and_add test failed");
86 atomic_add (&mem, 22);
89 puts ("atomic_add test failed");
94 atomic_increment (&mem);
97 puts ("atomic_increment test failed");
102 if (atomic_increment_and_test (&mem)
105 puts ("atomic_increment_and_test test 1 failed");
110 if (atomic_increment_and_test (&mem)
113 puts ("atomic_increment_and_test test 2 failed");
118 if (! atomic_increment_and_test (&mem)
121 puts ("atomic_increment_and_test test 3 failed");
126 atomic_decrement (&mem);
129 puts ("atomic_decrement test failed");
134 if (atomic_decrement_and_test (&mem)
137 puts ("atomic_decrement_and_test test 1 failed");
142 if (atomic_decrement_and_test (&mem)
145 puts ("atomic_decrement_and_test test 2 failed");
150 if (! atomic_decrement_and_test (&mem)
153 puts ("atomic_decrement_and_test test 1 failed");
158 if (atomic_decrement_if_positive (&mem) != 1
161 puts ("atomic_decrement_if_positive test 1 failed");
166 if (atomic_decrement_if_positive (&mem) != 0
169 puts ("atomic_decrement_if_positive test 2 failed");
174 if (atomic_decrement_if_positive (&mem) != -1
177 puts ("atomic_decrement_if_positive test 3 failed");
182 if (! atomic_add_negative (&mem, 10)
185 puts ("atomic_add_negative test 1 failed");
190 if (atomic_add_negative (&mem, 100)
193 puts ("atomic_add_negative test 2 failed");
198 if (atomic_add_negative (&mem, -10)
201 puts ("atomic_add_negative test 3 failed");
206 if (atomic_add_zero (&mem, 31)
209 puts ("atomic_add_zero test 1 failed");
214 if (! atomic_add_zero (&mem, 36)
217 puts ("atomic_add_zero test 2 failed");
222 if (atomic_add_zero (&mem, -13)
225 puts ("atomic_add_zero test 3 failed");
230 atomic_bit_set (&mem, 1);
233 puts ("atomic_bit_set test 1 failed");
238 atomic_bit_set (&mem, 3);
241 puts ("atomic_bit_set test 2 failed");
247 atomic_bit_set (&mem, 35);
248 if (mem != 0x800000010LL)
250 puts ("atomic_bit_set test 3 failed");
256 if (atomic_bit_test_set (&mem, 1)
259 puts ("atomic_bit_test_set test 1 failed");
264 if (! atomic_bit_test_set (&mem, 3)
267 puts ("atomic_bit_test_set test 2 failed");
273 if (atomic_bit_test_set (&mem, 35)
274 || mem != 0x800000010LL)
276 puts ("atomic_bit_test_set test 3 failed");
281 if (! atomic_bit_test_set (&mem, 32)
282 || mem != 0x100000000LL)
284 puts ("atomic_bit_test_set test 4 failed");
292 #define TEST_FUNCTION do_test ()
293 #include "../test-skeleton.c"