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