t_pthread_once.sh revision 1.3 1 # $NetBSD: t_pthread_once.sh,v 1.3 2020/02/11 06:26:19 riastradh Exp $
2 #
3 # Copyright (c) 2018 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 atf_test_case pthread_once
29 pthread_once_head() {
30 atf_set "descr" "compile and run std::pthread_once"
31 atf_set "require.progs" "c++"
32 }
33
34 atf_test_case pthread_once_profile
35 pthread_once_profile_head() {
36 atf_set "descr" "compile and run std::pthread_once with profiling option"
37 atf_set "require.progs" "c++"
38 }
39
40 atf_test_case pthread_once_pic
41 pthread_once_pic_head() {
42 atf_set "descr" "compile and run PIC std::pthread_once"
43 atf_set "require.progs" "c++"
44 }
45
46 atf_test_case pthread_once_pic_32
47 pthread_once_pic_32_head() {
48 atf_set "descr" "compile and run 32-bit PIC std::pthread_once"
49 atf_set "require.progs" "c++"
50 }
51
52 atf_test_case pthread_once_pic_profile
53 pthread_once_pic_head() {
54 atf_set "descr" "compile and run PIC std::pthread_once with profiling &flag"
55 atf_set "require.progs" "c++"
56 }
57
58 atf_test_case pthread_once_pic_profile_32
59 pthread_once_pic_profile_32_head() {
60 atf_set "descr" "compile and run 32-bit PIC std::pthread_once with profiling &flag"
61 atf_set "require.progs" "c++"
62 }
63
64 atf_test_case pthread_once_profile_32
65 pthread_once_profile_32_head() {
66 atf_set "descr" "compile and run 32-bit std::pthread_once with profiling &flag"
67 atf_set "require.progs" "c++"
68 }
69
70 atf_test_case pthread_once_pie
71 pthread_once_pie_head() {
72 atf_set "descr" "compile and run position independent (PIE) std::pthread_once"
73 atf_set "require.progs" "c++"
74 }
75
76 atf_test_case pthread_once_32
77 pthread_once_32_head() {
78 atf_set "descr" "compile and run std::pthread_once for/in netbsd32 emulation"
79 atf_set "require.progs" "c++ file diff cat"
80 }
81
82 atf_test_case pthread_once_static
83 pthread_once_static_head() {
84 atf_set "descr" "compile and run std::pthread_once with static &flag"
85 atf_set "require.progs" "c++"
86 }
87
88 pthread_once_body() {
89 cat > test.cpp << EOF
90 #include <cstdio>
91 #include <thread>
92 int main(void) {
93 pthread_once_t flag = PTHREAD_ONCE_INIT;
94 pthread_once(&flag, [](){ printf("hello, world!\n"); });
95 return 0;
96 }
97 EOF
98 atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once test.cpp -pthread
99 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
100 }
101
102 pthread_once_profile_body() {
103 cat > test.cpp << EOF
104 #include <cstdio>
105 #include <thread>
106 int main(void) {
107 pthread_once_t flag = PTHREAD_ONCE_INIT;
108 pthread_once(&flag, [](){ printf("hello, world!\n"); });
109 return 0;
110 }
111 EOF
112 atf_check -s exit:0 -o ignore -e ignore c++ -pg -o pthread_once test.cpp -pthread
113 case `uname -p` in
114 aarch64)
115 atf_expect_fail 'cc -pg is busted on aarch64'
116 ;;
117 esac
118 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
119 }
120
121 pthread_once_profile_32_body() {
122 # check whether this arch is 64bit
123 if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
124 atf_skip "this is not a 64 bit architecture"
125 fi
126 if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
127 atf_skip "c++ -m32 not supported on this architecture"
128 else
129 if fgrep -q _LP64 ./def32; then
130 atf_fail "c++ -m32 does not generate netbsd32 binaries"
131 fi
132 fi
133
134 cat > test.cpp << EOF
135 #include <cstdio>
136 #include <thread>
137 int main(void) {
138 pthread_once_t flag = PTHREAD_ONCE_INIT;
139 pthread_once(&flag, [](){ printf("hello, world!\n"); });
140 return 0;
141 }
142 EOF
143 atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o pthread_once test.cpp -pthread
144 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
145 }
146
147 pthread_once_pic_body() {
148 cat > test.cpp << EOF
149 #include <stdlib.h>
150 int callpic(void);
151 int main(void) {callpic();exit(0);}
152 EOF
153 cat > pic.cpp << EOF
154 #include <cstdio>
155 #include <thread>
156 int callpic(void) {
157 pthread_once_t flag = PTHREAD_ONCE_INIT;
158 pthread_once(&flag, [](){ printf("hello, world!\n"); });
159 return 0;
160 }
161 EOF
162
163 atf_check -s exit:0 -o ignore -e ignore \
164 c++ -fPIC -shared -o libtest.so pic.cpp
165 atf_check -s exit:0 -o ignore -e ignore \
166 c++ -o pthread_once test.cpp -L. -ltest -pthread
167
168 export LD_LIBRARY_PATH=.
169 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
170 }
171
172 pthread_once_pic_32_body() {
173 # check whether this arch is 64bit
174 if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
175 atf_skip "this is not a 64 bit architecture"
176 fi
177 if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
178 atf_skip "c++ -m32 not supported on this architecture"
179 else
180 if fgrep -q _LP64 ./def32; then
181 atf_fail "c++ -m32 does not generate netbsd32 binaries"
182 fi
183 fi
184
185 cat > test.cpp << EOF
186 #include <stdlib.h>
187 int callpic(void);
188 int main(void) {callpic();exit(0);}
189 EOF
190 cat > pic.cpp << EOF
191 #include <cstdio>
192 #include <thread>
193 int callpic(void) {
194 pthread_once_t flag = PTHREAD_ONCE_INIT;
195 pthread_once(&flag, [](){ printf("hello, world!\n"); });
196 return 0;
197 }
198 EOF
199
200 atf_check -s exit:0 -o ignore -e ignore \
201 c++ -m32 -fPIC -shared -o libtest.so pic.cpp
202 atf_check -s exit:0 -o ignore -e ignore \
203 c++ -m32 -o pthread_once test.cpp -L. -ltest -pthread
204
205 export LD_LIBRARY_PATH=.
206 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
207 }
208
209 pthread_once_pic_profile_body() {
210 cat > test.cpp << EOF
211 #include <stdlib.h>
212 int callpic(void);
213 int main(void) {callpic();exit(0);}
214 EOF
215 cat > pic.cpp << EOF
216 #include <cstdio>
217 #include <thread>
218 int callpic(void) {
219 pthread_once_t flag = PTHREAD_ONCE_INIT;
220 pthread_once(&flag, [](){ printf("hello, world!\n"); });
221 return 0;
222 }
223 EOF
224
225 atf_check -s exit:0 -o ignore -e ignore \
226 c++ -pg -fPIC -shared -o libtest.so pic.cpp
227 atf_check -s exit:0 -o ignore -e ignore \
228 c++ -pg -o pthread_once test.cpp -L. -ltest -pthread
229
230 case `uname -p` in
231 aarch64)
232 atf_expect_fail 'cc -pg is busted on aarch64'
233 ;;
234 esac
235 export LD_LIBRARY_PATH=.
236 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
237 }
238
239 pthread_once_pic_profile_32_body() {
240 # check whether this arch is 64bit
241 if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
242 atf_skip "this is not a 64 bit architecture"
243 fi
244 if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
245 atf_skip "c++ -m32 not supported on this architecture"
246 else
247 if fgrep -q _LP64 ./def32; then
248 atf_fail "c++ -m32 does not generate netbsd32 binaries"
249 fi
250 fi
251
252 cat > test.cpp << EOF
253 #include <stdlib.h>
254 int callpic(void);
255 int main(void) {callpic();exit(0);}
256 EOF
257 cat > pic.cpp << EOF
258 #include <cstdio>
259 #include <thread>
260 int callpic(void) {
261 pthread_once_t flag = PTHREAD_ONCE_INIT;
262 pthread_once(&flag, [](){ printf("hello, world!\n"); });
263 return 0;
264 }
265 EOF
266
267 atf_check -s exit:0 -o ignore -e ignore \
268 c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
269 atf_check -s exit:0 -o ignore -e ignore \
270 c++ -m32 -pg -o pthread_once test.cpp -L. -ltest -pthread
271
272 export LD_LIBRARY_PATH=.
273 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
274 }
275
276 pthread_once_pie_body() {
277 # check whether this arch supports -pie
278 if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
279 atf_skip "c++ -pie not supported on this architecture"
280 fi
281 cat > test.cpp << EOF
282 #include <cstdio>
283 #include <thread>
284 int main(void) {
285 pthread_once_t flag = PTHREAD_ONCE_INIT;
286 pthread_once(&flag, [](){ printf("hello, world!\n"); });
287 return 0;
288 }
289 EOF
290 atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o pthread_once test.cpp -pthread
291 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
292 }
293
294 pthread_once_32_body() {
295 # check whether this arch is 64bit
296 if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
297 atf_skip "this is not a 64 bit architecture"
298 fi
299 if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
300 atf_skip "c++ -m32 not supported on this architecture"
301 else
302 if fgrep -q _LP64 ./def32; then
303 atf_fail "c++ -m32 does not generate netbsd32 binaries"
304 fi
305 fi
306
307 cat > test.cpp << EOF
308 #include <cstdio>
309 #include <thread>
310 int main(void) {
311 pthread_once_t flag = PTHREAD_ONCE_INIT;
312 pthread_once(&flag, [](){ printf("hello, world!\n"); });
313 return 0;
314 }
315 EOF
316 atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_32 -m32 test.cpp -pthread
317 atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_64 test.cpp -pthread
318 file -b ./pthread_once_32 > ./ftype32
319 file -b ./pthread_once_64 > ./ftype64
320 if diff ./ftype32 ./ftype64 >/dev/null; then
321 atf_fail "generated binaries do not differ"
322 fi
323 echo "32bit binaries on this platform are:"
324 cat ./ftype32
325 echo "While native (64bit) binaries are:"
326 cat ./ftype64
327 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once_32
328
329 # do another test with static 32bit binaries
330 cat > test.cpp << EOF
331 #include <cstdio>
332 #include <thread>
333 int main(void) {
334 pthread_once_t flag = PTHREAD_ONCE_INIT;
335 pthread_once(&flag, [](){ printf("hello, world!\n"); });
336 return 0;
337 }
338 EOF
339 atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once -m32 -pthread \
340 -static test.cpp
341 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
342 }
343
344 pthread_once_static_body() {
345 cat > test.cpp << EOF
346 #include <cstdio>
347 #include <thread>
348 int main(void) {
349 pthread_once_t flag = PTHREAD_ONCE_INIT;
350 pthread_once(&flag, [](){ printf("hello, world!\n"); });
351 return 0;
352 }
353 EOF
354 atf_check -s exit:0 -o ignore -e ignore c++ -static -o pthread_once test.cpp -pthread
355 atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
356 }
357
358 atf_init_test_cases()
359 {
360
361 atf_add_test_case pthread_once
362 atf_add_test_case pthread_once_profile
363 atf_add_test_case pthread_once_pic
364 atf_add_test_case pthread_once_pie
365 atf_add_test_case pthread_once_32
366 atf_add_test_case pthread_once_static
367 atf_add_test_case pthread_once_pic_32
368 atf_add_test_case pthread_once_pic_profile
369 atf_add_test_case pthread_once_pic_profile_32
370 atf_add_test_case pthread_once_profile_32
371 }
372