Commit | Line | Data |
---|---|---|
6eee141f ILT |
1 | // tls_test.cc -- test TLS variables for gold |
2 | ||
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. | |
4 | // Written by Ian Lance Taylor <iant@google.com>. | |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
23 | // This provides a set of test functions for TLS variables. The | |
24 | // functions are called by a main function in tls_test_main.cc. This | |
25 | // lets us test TLS access from a shared library. We currently don't | |
26 | // bother to test TLS access between two different files, on the | |
27 | // theory that that is no more complicated than ordinary variable | |
28 | // access between files. | |
29 | ||
30 | // We start two threads, and stop the second one. Then we run the | |
31 | // first thread through the following cases. Then we let the second | |
32 | // thread continue, and run it through the same set of cases. All the | |
33 | // actual thread manipulation is in tls_test_main.cc. | |
34 | ||
35 | // 1 Access to an uninitialized global thread variable. | |
36 | // 2 Access to an uninitialized static thread variable. | |
37 | // 3 Access to an initialized global thread variable. | |
38 | // 4 Access to an initialized static thread variable. | |
39 | // 5 Taking the address of a global thread variable. | |
40 | // 6 Taking the address of a static thread variable. | |
e0374858 ILT |
41 | // 8 Like test 1, but with the thread variable defined in another file. |
42 | // 9 Like test 3, but with the thread variable defined in another file. | |
43 | // 10 Like test 5, but with the thread variable defined in another file. | |
44 | // last Verify that the above tests left the variables set correctly. | |
45 | ||
6eee141f ILT |
46 | |
47 | #include "tls_test.h" | |
48 | ||
49 | __thread int v1; | |
50 | static __thread int v2; | |
51 | __thread int v3 = 3; | |
52 | static __thread int v4 = 4; | |
53 | __thread int v5; | |
54 | static __thread int v6; | |
55 | ||
e0374858 ILT |
56 | // These variables are defined in tls_test_file2.cc |
57 | extern __thread int o1; | |
58 | extern __thread int o2; | |
59 | extern __thread int o3; | |
60 | ||
6eee141f ILT |
61 | bool |
62 | t1() | |
63 | { | |
64 | if (v1 != 0) | |
65 | return false; | |
66 | v1 = 10; | |
67 | return true; | |
68 | } | |
69 | ||
70 | bool | |
71 | t2() | |
72 | { | |
73 | if (v2 != 0) | |
74 | return false; | |
75 | v2 = 20; | |
76 | return true; | |
77 | } | |
78 | ||
79 | bool | |
80 | t3() | |
81 | { | |
82 | if (v3 != 3) | |
83 | return false; | |
84 | v3 = 30; | |
85 | return true; | |
86 | } | |
87 | ||
88 | bool | |
89 | t4() | |
90 | { | |
91 | if (v4 != 4) | |
92 | return false; | |
93 | v4 = 40; | |
94 | return true; | |
95 | } | |
96 | ||
97 | // For test 5 the main function calls f5b(f5a()), then calls t5(). | |
98 | ||
99 | int* | |
100 | f5a() | |
101 | { | |
102 | return &v5; | |
103 | } | |
104 | ||
105 | void | |
106 | f5b(int* p) | |
107 | { | |
108 | *p = 50; | |
109 | } | |
110 | ||
111 | bool | |
112 | t5() | |
113 | { | |
114 | return v5 == 50; | |
115 | } | |
116 | ||
e0374858 | 117 | // For test 6 the main function calls f6b(f6a()), then calls t6(). |
6eee141f ILT |
118 | |
119 | int* | |
120 | f6a() | |
121 | { | |
122 | return &v6; | |
123 | } | |
124 | ||
125 | void | |
126 | f6b(int* p) | |
127 | { | |
128 | *p = 60; | |
129 | } | |
130 | ||
131 | bool | |
132 | t6() | |
133 | { | |
134 | return v6 == 60; | |
135 | } | |
136 | ||
e0374858 ILT |
137 | // The slot for t7() is unused. |
138 | ||
139 | bool | |
140 | t8() | |
141 | { | |
142 | if (o1 != 0) | |
143 | return false; | |
144 | o1 = 10; | |
145 | return true; | |
146 | } | |
147 | ||
148 | bool | |
149 | t9() | |
150 | { | |
151 | if (o2 != 2) | |
152 | return false; | |
153 | o2 = 20; | |
154 | return true; | |
155 | } | |
156 | ||
157 | // For test 10 the main function calls f10b(f10a()), then calls t10(). | |
158 | ||
159 | int* | |
160 | f10a() | |
161 | { | |
162 | return &o3; | |
163 | } | |
164 | ||
165 | void | |
166 | f10b(int* p) | |
167 | { | |
168 | *p = 30; | |
169 | } | |
170 | ||
171 | bool | |
172 | t10() | |
173 | { | |
174 | return o3 == 30; | |
175 | } | |
176 | ||
6eee141f | 177 | bool |
e0374858 | 178 | t_last() |
6eee141f ILT |
179 | { |
180 | return (v1 == 10 | |
181 | && v2 == 20 | |
182 | && v3 == 30 | |
183 | && v4 == 40 | |
184 | && v5 == 50 | |
e0374858 ILT |
185 | && v6 == 60 |
186 | && o1 == 10 | |
187 | && o2 == 20 | |
188 | && o3 == 30); | |
6eee141f | 189 | } |