1 /* Tests for atomic.h macros.
2 Copyright (C) 2003, 2004 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_val (&mem
) != 3)
136 puts ("atomic_increment_val test failed");
141 if (atomic_increment_and_test (&mem
)
144 puts ("atomic_increment_and_test test 1 failed");
149 if (atomic_increment_and_test (&mem
)
152 puts ("atomic_increment_and_test test 2 failed");
157 if (! atomic_increment_and_test (&mem
)
160 puts ("atomic_increment_and_test test 3 failed");
165 atomic_decrement (&mem
);
168 puts ("atomic_decrement test failed");
172 if (atomic_decrement_val (&mem
) != 15)
174 puts ("atomic_decrement_val test failed");
179 if (atomic_decrement_and_test (&mem
)
182 puts ("atomic_decrement_and_test test 1 failed");
187 if (atomic_decrement_and_test (&mem
)
190 puts ("atomic_decrement_and_test test 2 failed");
195 if (! atomic_decrement_and_test (&mem
)
198 puts ("atomic_decrement_and_test test 3 failed");
203 if (atomic_decrement_if_positive (&mem
) != 1
206 puts ("atomic_decrement_if_positive test 1 failed");
211 if (atomic_decrement_if_positive (&mem
) != 0
214 puts ("atomic_decrement_if_positive test 2 failed");
219 if (atomic_decrement_if_positive (&mem
) != -1
222 puts ("atomic_decrement_if_positive test 3 failed");
227 if (! atomic_add_negative (&mem
, 10)
230 puts ("atomic_add_negative test 1 failed");
235 if (atomic_add_negative (&mem
, 100)
238 puts ("atomic_add_negative test 2 failed");
243 if (atomic_add_negative (&mem
, -10)
246 puts ("atomic_add_negative test 3 failed");
251 if (atomic_add_negative (&mem
, 14)
254 puts ("atomic_add_negative test 4 failed");
259 if (! atomic_add_negative (&mem
, -1)
262 puts ("atomic_add_negative test 5 failed");
267 if (atomic_add_negative (&mem
, 31)
270 puts ("atomic_add_negative test 6 failed");
275 if (atomic_add_zero (&mem
, 31)
278 puts ("atomic_add_zero test 1 failed");
283 if (! atomic_add_zero (&mem
, 36)
286 puts ("atomic_add_zero test 2 failed");
291 if (atomic_add_zero (&mem
, -13)
294 puts ("atomic_add_zero test 3 failed");
299 if (atomic_add_zero (&mem
, 20)
302 puts ("atomic_add_zero test 4 failed");
307 if (atomic_add_zero (&mem
, -20)
310 puts ("atomic_add_zero test 5 failed");
315 if (! atomic_add_zero (&mem
, -10)
318 puts ("atomic_add_zero test 6 failed");
323 atomic_bit_set (&mem
, 1);
326 puts ("atomic_bit_set test 1 failed");
331 atomic_bit_set (&mem
, 3);
334 puts ("atomic_bit_set test 2 failed");
340 atomic_bit_set (&mem
, 35);
341 if (mem
!= 0x800000010LL
)
343 puts ("atomic_bit_set test 3 failed");
349 if (atomic_bit_test_set (&mem
, 1)
352 puts ("atomic_bit_test_set test 1 failed");
357 if (! atomic_bit_test_set (&mem
, 3)
360 puts ("atomic_bit_test_set test 2 failed");
366 if (atomic_bit_test_set (&mem
, 35)
367 || mem
!= 0x800000010LL
)
369 puts ("atomic_bit_test_set test 3 failed");
374 if (! atomic_bit_test_set (&mem
, 32)
375 || mem
!= 0x100000000LL
)
377 puts ("atomic_bit_test_set test 4 failed");
385 #define TEST_FUNCTION do_test ()
386 #include "../test-skeleton.c"