comparison gcc/testsuite/gcc.dg/atomic-lockfree.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Test __atomic routines for existence and execution with each valid
2 memory model. */
3 /* { dg-options "-w" } */
4 /* { dg-do run } */
5 /* { dg-additional-sources "atomic-lockfree-aux.c" } */
6
7 /* Test that __atomic_{is,always}_lock_free builtins execute.
8 sync-mem-lockfree-aux.c supplies and external entry point for
9 __atomic_is_lock_free which always returns a 2. We can detect the
10 external routine was called if 2 is returned since that is not a valid
11 result normally. */
12
13 #include <stdlib.h>
14
15 extern void abort();
16
17 int r1, r2;
18
19 /* Test for consistency on sizes 1, 2, 4, 8, 16 and 32. */
20 int
21 main ()
22 {
23
24 r1 = __atomic_always_lock_free (sizeof(char), 0);
25 r2 = __atomic_is_lock_free (sizeof(char), 0);
26 /* If always lock free, then is_lock_free must also be true. */
27 if (r1)
28 {
29 if (r2 != 1)
30 abort ();
31 }
32 else
33 {
34 /* If it is not lock free, then the external routine must be called. */
35 if (r2 != 2)
36 abort ();
37 }
38
39 r1 = __atomic_always_lock_free (2, 0);
40 r2 = __atomic_is_lock_free (2, 0);
41 /* If always lock free, then is_lock_free must also be true. */
42 if (r1)
43 {
44 if (r2 != 1)
45 abort ();
46 }
47 else
48 {
49 /* If it is not lock free, then the external routine must be called. */
50 if (r2 != 2)
51 abort ();
52 }
53
54
55 r1 = __atomic_always_lock_free (4, 0);
56 r2 = __atomic_is_lock_free (4, 0); /* Try passing in a variable. */
57 /* If always lock free, then is_lock_free must also be true. */
58 if (r1)
59 {
60 if (r2 != 1)
61 abort ();
62 }
63 else
64 {
65 /* If it is not lock free, then the external routine must be called. */
66 if (r2 != 2)
67 abort ();
68 }
69
70
71 r1 = __atomic_always_lock_free (8, 0);
72 r2 = __atomic_is_lock_free (8, 0);
73 /* If always lock free, then is_lock_free must also be true. */
74 if (r1)
75 {
76 if (r2 != 1)
77 abort ();
78 }
79 else
80 {
81 /* If it is not lock free, then the external routine must be called. */
82 if (r2 != 2)
83 abort ();
84 }
85
86
87 r1 = __atomic_always_lock_free (16, 0);
88 r2 = __atomic_is_lock_free (16, 0);
89 /* If always lock free, then is_lock_free must also be true. */
90 if (r1)
91 {
92 if (r2 != 1)
93 abort ();
94 }
95 else
96 {
97 /* If it is not lock free, then the external routine must be called. */
98 if (r2 != 2)
99 abort ();
100 }
101
102
103 r1 = __atomic_always_lock_free (32, 0);
104 r2 = __atomic_is_lock_free (32, 0);
105 /* If always lock free, then is_lock_free must also be true. */
106 if (r1)
107 {
108 if (r2 != 1)
109 abort ();
110 }
111 else
112 {
113 /* If it is not lock free, then the external routine must be called. */
114 if (r2 != 2)
115 abort ();
116 }
117
118
119 return 0;
120 }
121