t_call_once2.sh revision 1.3 1 1.3 rin # $NetBSD: t_call_once2.sh,v 1.3 2021/09/04 05:47:31 rin Exp $
2 1.1 kamil #
3 1.1 kamil # Copyright (c) 2018 The NetBSD Foundation, Inc.
4 1.1 kamil # All rights reserved.
5 1.1 kamil #
6 1.1 kamil # Redistribution and use in source and binary forms, with or without
7 1.1 kamil # modification, are permitted provided that the following conditions
8 1.1 kamil # are met:
9 1.1 kamil # 1. Redistributions of source code must retain the above copyright
10 1.1 kamil # notice, this list of conditions and the following disclaimer.
11 1.1 kamil # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kamil # notice, this list of conditions and the following disclaimer in the
13 1.1 kamil # documentation and/or other materials provided with the distribution.
14 1.1 kamil #
15 1.1 kamil # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 kamil # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 kamil # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 kamil # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 kamil # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 kamil # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 kamil # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 kamil # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 kamil # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 kamil # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kamil # POSSIBILITY OF SUCH DAMAGE.
26 1.1 kamil #
27 1.1 kamil
28 1.1 kamil atf_test_case call_once2
29 1.1 kamil call_once2_head() {
30 1.1 kamil atf_set "descr" "compile and run std::call_once"
31 1.1 kamil atf_set "require.progs" "c++"
32 1.1 kamil }
33 1.1 kamil
34 1.1 kamil atf_test_case call_once2_profile
35 1.1 kamil call_once2_profile_head() {
36 1.1 kamil atf_set "descr" "compile and run std::call_once with profiling option"
37 1.1 kamil atf_set "require.progs" "c++"
38 1.1 kamil }
39 1.1 kamil
40 1.1 kamil atf_test_case call_once2_pic
41 1.1 kamil call_once2_pic_head() {
42 1.1 kamil atf_set "descr" "compile and run PIC std::call_once"
43 1.1 kamil atf_set "require.progs" "c++"
44 1.1 kamil }
45 1.1 kamil
46 1.1 kamil atf_test_case call_once2_pic_32
47 1.1 kamil call_once2_pic_32_head() {
48 1.1 kamil atf_set "descr" "compile and run 32-bit PIC std::call_once"
49 1.1 kamil atf_set "require.progs" "c++"
50 1.1 kamil }
51 1.1 kamil
52 1.1 kamil atf_test_case call_once2_pic_profile
53 1.3 rin call_once2_pic_profile_head() {
54 1.1 kamil atf_set "descr" "compile and run PIC std::call_once with profiling flag"
55 1.1 kamil atf_set "require.progs" "c++"
56 1.1 kamil }
57 1.1 kamil
58 1.1 kamil atf_test_case call_once2_pic_profile_32
59 1.1 kamil call_once2_pic_profile_32_head() {
60 1.1 kamil atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag"
61 1.1 kamil atf_set "require.progs" "c++"
62 1.1 kamil }
63 1.1 kamil
64 1.1 kamil atf_test_case call_once2_profile_32
65 1.1 kamil call_once2_profile_32_head() {
66 1.1 kamil atf_set "descr" "compile and run 32-bit std::call_once with profiling flag"
67 1.1 kamil atf_set "require.progs" "c++"
68 1.1 kamil }
69 1.1 kamil
70 1.1 kamil atf_test_case call_once2_pie
71 1.1 kamil call_once2_pie_head() {
72 1.1 kamil atf_set "descr" "compile and run position independent (PIE) std::call_once"
73 1.1 kamil atf_set "require.progs" "c++"
74 1.1 kamil }
75 1.1 kamil
76 1.1 kamil atf_test_case call_once2_32
77 1.1 kamil call_once2_32_head() {
78 1.1 kamil atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation"
79 1.1 kamil atf_set "require.progs" "c++ file diff cat"
80 1.1 kamil }
81 1.1 kamil
82 1.1 kamil atf_test_case call_once2_static
83 1.1 kamil call_once2_static_head() {
84 1.1 kamil atf_set "descr" "compile and run std::call_once with static flag"
85 1.1 kamil atf_set "require.progs" "c++"
86 1.1 kamil }
87 1.1 kamil
88 1.1 kamil call_once2_body() {
89 1.1 kamil cat > test.cpp << EOF
90 1.1 kamil #include <mutex>
91 1.1 kamil #include <thread>
92 1.1 kamil #include <iostream>
93 1.1 kamil std::once_flag flag, flag_throw;
94 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
95 1.1 kamil void throw_once(void) { throw std::exception(); }
96 1.1 kamil int main(void) {
97 1.1 kamil static const int nr_threads(4);
98 1.1 kamil std::thread threads[nr_threads];
99 1.1 kamil
100 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
101 1.1 kamil threads[i] = std::thread(print_once);
102 1.1 kamil }
103 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
104 1.1 kamil threads[i].join();
105 1.1 kamil }
106 1.1 kamil
107 1.1 kamil try {
108 1.1 kamil std::call_once(flag_throw, throw_once);
109 1.1 kamil } catch (...) {
110 1.1 kamil std::cout << "world!" << std::endl;
111 1.1 kamil }
112 1.1 kamil return 0;
113 1.1 kamil }
114 1.1 kamil EOF
115 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 test.cpp -pthread
116 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
117 1.1 kamil }
118 1.1 kamil
119 1.1 kamil call_once2_profile_body() {
120 1.2 christos atf_expect_fail "profiling option doesn't work with shared libraries"
121 1.1 kamil cat > test.cpp << EOF
122 1.1 kamil #include <mutex>
123 1.1 kamil #include <thread>
124 1.1 kamil #include <iostream>
125 1.1 kamil std::once_flag flag, flag_throw;
126 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
127 1.1 kamil void throw_once(void) { throw std::exception(); }
128 1.1 kamil int main(void) {
129 1.1 kamil static const int nr_threads(4);
130 1.1 kamil std::thread threads[nr_threads];
131 1.1 kamil
132 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
133 1.1 kamil threads[i] = std::thread(print_once);
134 1.1 kamil }
135 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
136 1.1 kamil threads[i].join();
137 1.1 kamil }
138 1.1 kamil
139 1.1 kamil try {
140 1.1 kamil std::call_once(flag_throw, throw_once);
141 1.1 kamil } catch (...) {
142 1.1 kamil std::cout << "world!" << std::endl;
143 1.1 kamil }
144 1.1 kamil return 0;
145 1.1 kamil }
146 1.1 kamil EOF
147 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once2 test.cpp -pthread
148 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
149 1.1 kamil }
150 1.1 kamil
151 1.1 kamil call_once2_profile_32_body() {
152 1.1 kamil atf_expect_fail "profiling option doesn't work now"
153 1.1 kamil # check whether this arch is 64bit
154 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
155 1.1 kamil atf_skip "this is not a 64 bit architecture"
156 1.1 kamil fi
157 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
158 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
159 1.1 kamil else
160 1.1 kamil if fgrep -q _LP64 ./def32; then
161 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
162 1.1 kamil fi
163 1.1 kamil fi
164 1.1 kamil
165 1.1 kamil cat > test.cpp << EOF
166 1.1 kamil #include <mutex>
167 1.1 kamil #include <thread>
168 1.1 kamil #include <iostream>
169 1.1 kamil std::once_flag flag, flag_throw;
170 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
171 1.1 kamil void throw_once(void) { throw std::exception(); }
172 1.1 kamil int main(void) {
173 1.1 kamil static const int nr_threads(4);
174 1.1 kamil std::thread threads[nr_threads];
175 1.1 kamil
176 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
177 1.1 kamil threads[i] = std::thread(print_once);
178 1.1 kamil }
179 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
180 1.1 kamil threads[i].join();
181 1.1 kamil }
182 1.1 kamil
183 1.1 kamil try {
184 1.1 kamil std::call_once(flag_throw, throw_once);
185 1.1 kamil } catch (...) {
186 1.1 kamil std::cout << "world!" << std::endl;
187 1.1 kamil }
188 1.1 kamil return 0;
189 1.1 kamil }
190 1.1 kamil EOF
191 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once2 test.cpp -pthread
192 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
193 1.1 kamil atf_expect_fail "The combination of 32-bit and profiling should be fail"
194 1.1 kamil }
195 1.1 kamil
196 1.1 kamil call_once2_pic_body() {
197 1.1 kamil cat > test.cpp << EOF
198 1.1 kamil #include <stdlib.h>
199 1.1 kamil int callpic(void);
200 1.1 kamil int main(void) {callpic();exit(0);}
201 1.1 kamil EOF
202 1.1 kamil cat > pic.cpp << EOF
203 1.1 kamil #include <mutex>
204 1.1 kamil #include <thread>
205 1.1 kamil #include <iostream>
206 1.1 kamil std::once_flag flag, flag_throw;
207 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
208 1.1 kamil void throw_once(void) { throw std::exception(); }
209 1.1 kamil int callpic(void) {
210 1.1 kamil static const int nr_threads(4);
211 1.1 kamil std::thread threads[nr_threads];
212 1.1 kamil
213 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
214 1.1 kamil threads[i] = std::thread(print_once);
215 1.1 kamil }
216 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
217 1.1 kamil threads[i].join();
218 1.1 kamil }
219 1.1 kamil
220 1.1 kamil try {
221 1.1 kamil std::call_once(flag_throw, throw_once);
222 1.1 kamil } catch (...) {
223 1.1 kamil std::cout << "world!" << std::endl;
224 1.1 kamil }
225 1.1 kamil return 0;
226 1.1 kamil }
227 1.1 kamil EOF
228 1.1 kamil
229 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
230 1.1 kamil c++ -fPIC -shared -o libtest.so pic.cpp
231 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
232 1.1 kamil c++ -o call_once2 test.cpp -L. -ltest -pthread
233 1.1 kamil
234 1.1 kamil export LD_LIBRARY_PATH=.
235 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
236 1.1 kamil }
237 1.1 kamil
238 1.1 kamil call_once2_pic_32_body() {
239 1.1 kamil # check whether this arch is 64bit
240 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
241 1.1 kamil atf_skip "this is not a 64 bit architecture"
242 1.1 kamil fi
243 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
244 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
245 1.1 kamil else
246 1.1 kamil if fgrep -q _LP64 ./def32; then
247 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
248 1.1 kamil fi
249 1.1 kamil fi
250 1.1 kamil
251 1.1 kamil cat > test.cpp << EOF
252 1.1 kamil #include <stdlib.h>
253 1.1 kamil int callpic(void);
254 1.1 kamil int main(void) {callpic();exit(0);}
255 1.1 kamil EOF
256 1.1 kamil cat > pic.cpp << EOF
257 1.1 kamil #include <mutex>
258 1.1 kamil #include <thread>
259 1.1 kamil #include <iostream>
260 1.1 kamil std::once_flag flag, flag_throw;
261 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
262 1.1 kamil void throw_once(void) { throw std::exception(); }
263 1.1 kamil int callpic(void) {
264 1.1 kamil static const int nr_threads(4);
265 1.1 kamil std::thread threads[nr_threads];
266 1.1 kamil
267 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
268 1.1 kamil threads[i] = std::thread(print_once);
269 1.1 kamil }
270 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
271 1.1 kamil threads[i].join();
272 1.1 kamil }
273 1.1 kamil
274 1.1 kamil try {
275 1.1 kamil std::call_once(flag_throw, throw_once);
276 1.1 kamil } catch (...) {
277 1.1 kamil std::cout << "world!" << std::endl;
278 1.1 kamil }
279 1.1 kamil return 0;
280 1.1 kamil }
281 1.1 kamil EOF
282 1.1 kamil
283 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
284 1.1 kamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp
285 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
286 1.1 kamil c++ -m32 -o call_once2 test.cpp -L. -ltest -pthread
287 1.1 kamil
288 1.1 kamil export LD_LIBRARY_PATH=.
289 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
290 1.1 kamil }
291 1.1 kamil
292 1.1 kamil call_once2_pic_profile_body() {
293 1.2 christos atf_expect_fail "profiling option doesn't work with pic"
294 1.1 kamil cat > test.cpp << EOF
295 1.1 kamil #include <stdlib.h>
296 1.1 kamil int callpic(void);
297 1.1 kamil int main(void) {callpic();exit(0);}
298 1.1 kamil EOF
299 1.1 kamil cat > pic.cpp << EOF
300 1.1 kamil #include <mutex>
301 1.1 kamil #include <thread>
302 1.1 kamil #include <iostream>
303 1.1 kamil std::once_flag flag, flag_throw;
304 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
305 1.1 kamil void throw_once(void) { throw std::exception(); }
306 1.1 kamil int callpic(void) {
307 1.1 kamil static const int nr_threads(4);
308 1.1 kamil std::thread threads[nr_threads];
309 1.1 kamil
310 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
311 1.1 kamil threads[i] = std::thread(print_once);
312 1.1 kamil }
313 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
314 1.1 kamil threads[i].join();
315 1.1 kamil }
316 1.1 kamil
317 1.1 kamil try {
318 1.1 kamil std::call_once(flag_throw, throw_once);
319 1.1 kamil } catch (...) {
320 1.1 kamil std::cout << "world!" << std::endl;
321 1.1 kamil }
322 1.1 kamil return 0;
323 1.1 kamil }
324 1.1 kamil EOF
325 1.1 kamil
326 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
327 1.1 kamil c++ -pg -fPIC -shared -o libtest.so pic.cpp
328 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
329 1.1 kamil c++ -pg -o call_once2 test.cpp -L. -ltest -pthread
330 1.1 kamil
331 1.1 kamil export LD_LIBRARY_PATH=.
332 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
333 1.1 kamil }
334 1.1 kamil
335 1.1 kamil call_once2_pic_profile_32_body() {
336 1.2 christos atf_expect_fail "profiling option doesn't work with shared libraries"
337 1.1 kamil # check whether this arch is 64bit
338 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
339 1.1 kamil atf_skip "this is not a 64 bit architecture"
340 1.1 kamil fi
341 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
342 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
343 1.1 kamil else
344 1.1 kamil if fgrep -q _LP64 ./def32; then
345 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
346 1.1 kamil fi
347 1.1 kamil fi
348 1.1 kamil
349 1.1 kamil cat > test.cpp << EOF
350 1.1 kamil #include <stdlib.h>
351 1.1 kamil int callpic(void);
352 1.1 kamil int main(void) {callpic();exit(0);}
353 1.1 kamil EOF
354 1.1 kamil cat > pic.cpp << EOF
355 1.1 kamil #include <mutex>
356 1.1 kamil #include <thread>
357 1.1 kamil #include <iostream>
358 1.1 kamil std::once_flag flag, flag_throw;
359 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
360 1.1 kamil void throw_once(void) { throw std::exception(); }
361 1.1 kamil int callpic(void) {
362 1.1 kamil static const int nr_threads(4);
363 1.1 kamil std::thread threads[nr_threads];
364 1.1 kamil
365 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
366 1.1 kamil threads[i] = std::thread(print_once);
367 1.1 kamil }
368 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
369 1.1 kamil threads[i].join();
370 1.1 kamil }
371 1.1 kamil
372 1.1 kamil try {
373 1.1 kamil std::call_once(flag_throw, throw_once);
374 1.1 kamil } catch (...) {
375 1.1 kamil std::cout << "world!" << std::endl;
376 1.1 kamil }
377 1.1 kamil return 0;
378 1.1 kamil }
379 1.1 kamil EOF
380 1.1 kamil
381 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
382 1.1 kamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
383 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
384 1.1 kamil c++ -m32 -pg -o call_once2 test.cpp -L. -ltest -pthread
385 1.1 kamil
386 1.1 kamil export LD_LIBRARY_PATH=.
387 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
388 1.1 kamil }
389 1.1 kamil
390 1.1 kamil call_once2_pie_body() {
391 1.1 kamil # check whether this arch supports -pie
392 1.1 kamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
393 1.1 kamil atf_skip "c++ -pie not supported on this architecture"
394 1.1 kamil fi
395 1.1 kamil cat > test.cpp << EOF
396 1.1 kamil #include <mutex>
397 1.1 kamil #include <thread>
398 1.1 kamil #include <iostream>
399 1.1 kamil std::once_flag flag, flag_throw;
400 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
401 1.1 kamil void throw_once(void) { throw std::exception(); }
402 1.1 kamil int main(void) {
403 1.1 kamil static const int nr_threads(4);
404 1.1 kamil std::thread threads[nr_threads];
405 1.1 kamil
406 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
407 1.1 kamil threads[i] = std::thread(print_once);
408 1.1 kamil }
409 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
410 1.1 kamil threads[i].join();
411 1.1 kamil }
412 1.1 kamil
413 1.1 kamil try {
414 1.1 kamil std::call_once(flag_throw, throw_once);
415 1.1 kamil } catch (...) {
416 1.1 kamil std::cout << "world!" << std::endl;
417 1.1 kamil }
418 1.1 kamil return 0;
419 1.1 kamil }
420 1.1 kamil EOF
421 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once2 test.cpp -pthread
422 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
423 1.1 kamil }
424 1.1 kamil
425 1.1 kamil call_once2_32_body() {
426 1.1 kamil # check whether this arch is 64bit
427 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
428 1.1 kamil atf_skip "this is not a 64 bit architecture"
429 1.1 kamil fi
430 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
431 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
432 1.1 kamil else
433 1.1 kamil if fgrep -q _LP64 ./def32; then
434 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
435 1.1 kamil fi
436 1.1 kamil fi
437 1.1 kamil
438 1.1 kamil cat > test.cpp << EOF
439 1.1 kamil #include <mutex>
440 1.1 kamil #include <thread>
441 1.1 kamil #include <iostream>
442 1.1 kamil std::once_flag flag, flag_throw;
443 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
444 1.1 kamil void throw_once(void) { throw std::exception(); }
445 1.1 kamil int main(void) {
446 1.1 kamil static const int nr_threads(4);
447 1.1 kamil std::thread threads[nr_threads];
448 1.1 kamil
449 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
450 1.1 kamil threads[i] = std::thread(print_once);
451 1.1 kamil }
452 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
453 1.1 kamil threads[i].join();
454 1.1 kamil }
455 1.1 kamil
456 1.1 kamil try {
457 1.1 kamil std::call_once(flag_throw, throw_once);
458 1.1 kamil } catch (...) {
459 1.1 kamil std::cout << "world!" << std::endl;
460 1.1 kamil }
461 1.1 kamil return 0;
462 1.1 kamil }
463 1.1 kamil EOF
464 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_32 -m32 test.cpp -pthread
465 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_64 test.cpp -pthread
466 1.1 kamil file -b ./call_once2_32 > ./ftype32
467 1.1 kamil file -b ./call_once2_64 > ./ftype64
468 1.1 kamil if diff ./ftype32 ./ftype64 >/dev/null; then
469 1.1 kamil atf_fail "generated binaries do not differ"
470 1.1 kamil fi
471 1.1 kamil echo "32bit binaries on this platform are:"
472 1.1 kamil cat ./ftype32
473 1.1 kamil echo "While native (64bit) binaries are:"
474 1.1 kamil cat ./ftype64
475 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2_32
476 1.1 kamil
477 1.1 kamil # do another test with static 32bit binaries
478 1.1 kamil cat > test.cpp << EOF
479 1.1 kamil #include <mutex>
480 1.1 kamil #include <thread>
481 1.1 kamil #include <iostream>
482 1.1 kamil std::once_flag flag, flag_throw;
483 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
484 1.1 kamil void throw_once(void) { throw std::exception(); }
485 1.1 kamil int main(void) {
486 1.1 kamil static const int nr_threads(4);
487 1.1 kamil std::thread threads[nr_threads];
488 1.1 kamil
489 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
490 1.1 kamil threads[i] = std::thread(print_once);
491 1.1 kamil }
492 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
493 1.1 kamil threads[i].join();
494 1.1 kamil }
495 1.1 kamil
496 1.1 kamil try {
497 1.1 kamil std::call_once(flag_throw, throw_once);
498 1.1 kamil } catch (...) {
499 1.1 kamil std::cout << "world!" << std::endl;
500 1.1 kamil }
501 1.1 kamil return 0;
502 1.1 kamil }
503 1.1 kamil EOF
504 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 -m32 -pthread \
505 1.1 kamil -static test.cpp
506 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
507 1.1 kamil }
508 1.1 kamil
509 1.1 kamil call_once2_static_body() {
510 1.1 kamil cat > test.cpp << EOF
511 1.1 kamil #include <mutex>
512 1.1 kamil #include <thread>
513 1.1 kamil #include <iostream>
514 1.1 kamil std::once_flag flag, flag_throw;
515 1.1 kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
516 1.1 kamil void throw_once(void) { throw std::exception(); }
517 1.1 kamil int main(void) {
518 1.1 kamil static const int nr_threads(4);
519 1.1 kamil std::thread threads[nr_threads];
520 1.1 kamil
521 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
522 1.1 kamil threads[i] = std::thread(print_once);
523 1.1 kamil }
524 1.1 kamil for (int i = 0; i < nr_threads; ++i) {
525 1.1 kamil threads[i].join();
526 1.1 kamil }
527 1.1 kamil
528 1.1 kamil try {
529 1.1 kamil std::call_once(flag_throw, throw_once);
530 1.1 kamil } catch (...) {
531 1.1 kamil std::cout << "world!" << std::endl;
532 1.1 kamil }
533 1.1 kamil return 0;
534 1.1 kamil }
535 1.1 kamil EOF
536 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once2 test.cpp -pthread
537 1.1 kamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
538 1.1 kamil }
539 1.1 kamil
540 1.1 kamil atf_init_test_cases()
541 1.1 kamil {
542 1.1 kamil
543 1.1 kamil atf_add_test_case call_once2
544 1.1 kamil atf_add_test_case call_once2_profile
545 1.1 kamil atf_add_test_case call_once2_pic
546 1.1 kamil atf_add_test_case call_once2_pie
547 1.1 kamil atf_add_test_case call_once2_32
548 1.1 kamil atf_add_test_case call_once2_static
549 1.1 kamil atf_add_test_case call_once2_pic_32
550 1.1 kamil atf_add_test_case call_once2_pic_profile
551 1.1 kamil atf_add_test_case call_once2_pic_profile_32
552 1.1 kamil atf_add_test_case call_once2_profile_32
553 1.1 kamil }
554