1 /* Tests for atomic.h macros.
2 Copyright (C) 2003-2013 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, see
18 <http://www.gnu.org/licenses/>. */
27 /* Test various atomic.h macros. */
34 #ifdef atomic_compare_and_exchange_val_acq
36 if (atomic_compare_and_exchange_val_acq (&mem
, 35, 24) != 24
39 puts ("atomic_compare_and_exchange_val_acq test 1 failed");
44 if (atomic_compare_and_exchange_val_acq (&mem
, 10, 15) != 12
47 puts ("atomic_compare_and_exchange_val_acq test 2 failed");
52 if (atomic_compare_and_exchange_val_acq (&mem
, -56, -15) != -15
55 puts ("atomic_compare_and_exchange_val_acq test 3 failed");
60 if (atomic_compare_and_exchange_val_acq (&mem
, 17, 0) != -1
63 puts ("atomic_compare_and_exchange_val_acq test 4 failed");
69 if (atomic_compare_and_exchange_bool_acq (&mem
, 35, 24)
72 puts ("atomic_compare_and_exchange_bool_acq test 1 failed");
77 if (! atomic_compare_and_exchange_bool_acq (&mem
, 10, 15)
80 puts ("atomic_compare_and_exchange_bool_acq test 2 failed");
85 if (atomic_compare_and_exchange_bool_acq (&mem
, -56, -15)
88 puts ("atomic_compare_and_exchange_bool_acq test 3 failed");
93 if (! atomic_compare_and_exchange_bool_acq (&mem
, 17, 0)
96 puts ("atomic_compare_and_exchange_bool_acq test 4 failed");
101 if (atomic_exchange_acq (&mem
, 31) != 64
104 puts ("atomic_exchange_acq test failed");
109 if (atomic_exchange_and_add (&mem
, 11) != 2
112 puts ("atomic_exchange_and_add test failed");
117 atomic_add (&mem
, 22);
120 puts ("atomic_add test failed");
125 atomic_increment (&mem
);
128 puts ("atomic_increment test failed");
133 if (atomic_increment_val (&mem
) != 3)
135 puts ("atomic_increment_val test failed");
140 if (atomic_increment_and_test (&mem
)
143 puts ("atomic_increment_and_test test 1 failed");
148 if (atomic_increment_and_test (&mem
)
151 puts ("atomic_increment_and_test test 2 failed");
156 if (! atomic_increment_and_test (&mem
)
159 puts ("atomic_increment_and_test test 3 failed");
164 atomic_decrement (&mem
);
167 puts ("atomic_decrement test failed");
171 if (atomic_decrement_val (&mem
) != 15)
173 puts ("atomic_decrement_val test failed");
178 if (atomic_decrement_and_test (&mem
)
181 puts ("atomic_decrement_and_test test 1 failed");
186 if (atomic_decrement_and_test (&mem
)
189 puts ("atomic_decrement_and_test test 2 failed");
194 if (! atomic_decrement_and_test (&mem
)
197 puts ("atomic_decrement_and_test test 3 failed");
202 if (atomic_decrement_if_positive (&mem
) != 1
205 puts ("atomic_decrement_if_positive test 1 failed");
210 if (atomic_decrement_if_positive (&mem
) != 0
213 puts ("atomic_decrement_if_positive test 2 failed");
218 if (atomic_decrement_if_positive (&mem
) != -1
221 puts ("atomic_decrement_if_positive test 3 failed");
226 if (! atomic_add_negative (&mem
, 10)
229 puts ("atomic_add_negative test 1 failed");
234 if (atomic_add_negative (&mem
, 100)
237 puts ("atomic_add_negative test 2 failed");
242 if (atomic_add_negative (&mem
, -10)
245 puts ("atomic_add_negative test 3 failed");
250 if (atomic_add_negative (&mem
, 14)
253 puts ("atomic_add_negative test 4 failed");
258 if (! atomic_add_negative (&mem
, -1)
261 puts ("atomic_add_negative test 5 failed");
266 if (atomic_add_negative (&mem
, 31)
269 puts ("atomic_add_negative test 6 failed");
274 if (atomic_add_zero (&mem
, 31)
277 puts ("atomic_add_zero test 1 failed");
282 if (! atomic_add_zero (&mem
, 36)
285 puts ("atomic_add_zero test 2 failed");
290 if (atomic_add_zero (&mem
, -13)
293 puts ("atomic_add_zero test 3 failed");
298 if (atomic_add_zero (&mem
, 20)
301 puts ("atomic_add_zero test 4 failed");
306 if (atomic_add_zero (&mem
, -20)
309 puts ("atomic_add_zero test 5 failed");
314 if (! atomic_add_zero (&mem
, -10)
317 puts ("atomic_add_zero test 6 failed");
322 atomic_bit_set (&mem
, 1);
325 puts ("atomic_bit_set test 1 failed");
330 atomic_bit_set (&mem
, 3);
333 puts ("atomic_bit_set test 2 failed");
339 atomic_bit_set (&mem
, 35);
340 if (mem
!= 0x800000010LL
)
342 puts ("atomic_bit_set test 3 failed");
348 if (atomic_bit_test_set (&mem
, 1)
351 puts ("atomic_bit_test_set test 1 failed");
356 if (! atomic_bit_test_set (&mem
, 3)
359 puts ("atomic_bit_test_set test 2 failed");
365 if (atomic_bit_test_set (&mem
, 35)
366 || mem
!= 0x800000010LL
)
368 puts ("atomic_bit_test_set test 3 failed");
373 if (! atomic_bit_test_set (&mem
, 32)
374 || mem
!= 0x100000000LL
)
376 puts ("atomic_bit_test_set test 4 failed");
381 #ifdef catomic_compare_and_exchange_val_acq
383 if (catomic_compare_and_exchange_val_acq (&mem
, 35, 24) != 24
386 puts ("catomic_compare_and_exchange_val_acq test 1 failed");
391 if (catomic_compare_and_exchange_val_acq (&mem
, 10, 15) != 12
394 puts ("catomic_compare_and_exchange_val_acq test 2 failed");
399 if (catomic_compare_and_exchange_val_acq (&mem
, -56, -15) != -15
402 puts ("catomic_compare_and_exchange_val_acq test 3 failed");
407 if (catomic_compare_and_exchange_val_acq (&mem
, 17, 0) != -1
410 puts ("catomic_compare_and_exchange_val_acq test 4 failed");
416 if (catomic_compare_and_exchange_bool_acq (&mem
, 35, 24)
419 puts ("catomic_compare_and_exchange_bool_acq test 1 failed");
424 if (! catomic_compare_and_exchange_bool_acq (&mem
, 10, 15)
427 puts ("catomic_compare_and_exchange_bool_acq test 2 failed");
432 if (catomic_compare_and_exchange_bool_acq (&mem
, -56, -15)
435 puts ("catomic_compare_and_exchange_bool_acq test 3 failed");
440 if (! catomic_compare_and_exchange_bool_acq (&mem
, 17, 0)
443 puts ("catomic_compare_and_exchange_bool_acq test 4 failed");
448 if (catomic_exchange_and_add (&mem
, 11) != 2
451 puts ("catomic_exchange_and_add test failed");
456 catomic_add (&mem
, 22);
459 puts ("catomic_add test failed");
464 catomic_increment (&mem
);
467 puts ("catomic_increment test failed");
472 if (catomic_increment_val (&mem
) != 3)
474 puts ("catomic_increment_val test failed");
479 catomic_decrement (&mem
);
482 puts ("catomic_decrement test failed");
486 if (catomic_decrement_val (&mem
) != 15)
488 puts ("catomic_decrement_val test failed");
495 #define TEST_FUNCTION do_test ()
496 #include "../test-skeleton.c"