Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libatomic / testsuite / libatomic.c / atomic-generic.c
1 /* Test generic __atomic routines for proper function calling.
2    memory model.  */
3 /* { dg-options "-w" } */
4 /* { dg-do run } */
5
6 /* Test that the generioc atomic builtins execute as expected..
7    sync-mem-generic-aux.c supplies a functional external entry point for 
8    the 4 generic functions.  */
9
10 #include <stdlib.h>
11 #include <stdbool.h>
12
13 extern void abort();
14
15 typedef struct test {
16   int array[10];
17 } test_struct;
18
19 test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
20 test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
21 test_struct a,b;
22
23 int size = sizeof (test_struct);
24 /* Test for consistency on sizes 1, 2, 4, 8, 16 and 32.  */
25 main ()
26 {
27   test_struct c;
28
29   __atomic_store (&a, &zero, __ATOMIC_RELAXED);
30   if (memcmp (&a, &zero, size))
31     abort ();
32
33   __atomic_exchange (&a, &ones, &c, __ATOMIC_SEQ_CST);
34   if (memcmp (&c, &zero, size))
35     abort ();
36   if (memcmp (&a, &ones, size))
37     abort ();
38
39   __atomic_load (&a, &b, __ATOMIC_RELAXED);
40   if (memcmp (&b, &ones, size))
41     abort ();
42
43   if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
44     abort();
45   if (memcmp (&a, &zero, size))
46     abort ();
47
48   if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
49     abort();
50   if (memcmp (&b, &zero, size))
51     abort ();
52
53   return 0;
54 }
55