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