t_cxxruntime.sh revision 1.2.10.1 1 1.2.10.1 pgoyette # $NetBSD: t_cxxruntime.sh,v 1.2.10.1 2018/03/30 06:20:16 pgoyette 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.2.10.1 pgoyette atf_test_case cxxruntime_profile
38 1.2.10.1 pgoyette cxxruntime_profile_head() {
39 1.2.10.1 pgoyette atf_set "descr" "compile and run \"hello world\" with profiling option"
40 1.2.10.1 pgoyette atf_set "require.progs" "c++"
41 1.2.10.1 pgoyette }
42 1.2.10.1 pgoyette
43 1.2.10.1 pgoyette atf_test_case cxxruntime_profile_32
44 1.2.10.1 pgoyette cxxruntime_profile_32_head() {
45 1.2.10.1 pgoyette atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
46 1.2.10.1 pgoyette atf_set "require.progs" "c++"
47 1.2.10.1 pgoyette }
48 1.2.10.1 pgoyette
49 1.2.10.1 pgoyette atf_test_case cxxruntime_static
50 1.2.10.1 pgoyette cxxruntime_static_head() {
51 1.2.10.1 pgoyette atf_set "descr" "compile and run \"hello world\" with static flags"
52 1.2.10.1 pgoyette atf_set "require.progs" "c++"
53 1.2.10.1 pgoyette }
54 1.2.10.1 pgoyette
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.2.10.1 pgoyette atf_test_case cxxruntime_pic_32
62 1.2.10.1 pgoyette cxxruntime_pic_32_head() {
63 1.2.10.1 pgoyette atf_set "descr" "compile and run 32-bit PIC \"hello world\""
64 1.2.10.1 pgoyette atf_set "require.progs" "c++"
65 1.2.10.1 pgoyette }
66 1.2.10.1 pgoyette
67 1.2.10.1 pgoyette atf_test_case cxxruntime_pic_profile
68 1.2.10.1 pgoyette cxxruntime_pic_profile_head() {
69 1.2.10.1 pgoyette atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
70 1.2.10.1 pgoyette atf_set "require.progs" "c++"
71 1.2.10.1 pgoyette }
72 1.2.10.1 pgoyette
73 1.2.10.1 pgoyette atf_test_case cxxruntime_pic_profile_32
74 1.2.10.1 pgoyette cxxruntime_pic_profile_32_head() {
75 1.2.10.1 pgoyette atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
76 1.2.10.1 pgoyette atf_set "require.progs" "c++"
77 1.2.10.1 pgoyette }
78 1.2.10.1 pgoyette
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.2.10.1 pgoyette cxxruntime_profile_body() {
102 1.2.10.1 pgoyette cat > test.cpp << EOF
103 1.2.10.1 pgoyette #include <cstdlib>
104 1.2.10.1 pgoyette #include <iostream>
105 1.2.10.1 pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
106 1.2.10.1 pgoyette EOF
107 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
108 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
109 1.2.10.1 pgoyette }
110 1.2.10.1 pgoyette
111 1.2.10.1 pgoyette cxxruntime_profile_32_body() {
112 1.2.10.1 pgoyette # check whether this arch is 64bit
113 1.2.10.1 pgoyette if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
114 1.2.10.1 pgoyette atf_skip "this is not a 64 bit architecture"
115 1.2.10.1 pgoyette fi
116 1.2.10.1 pgoyette if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
117 1.2.10.1 pgoyette atf_skip "c++ -m32 not supported on this architecture"
118 1.2.10.1 pgoyette else
119 1.2.10.1 pgoyette if fgrep -q _LP64 ./def32; then
120 1.2.10.1 pgoyette atf_fail "c++ -m32 does not generate netbsd32 binaries"
121 1.2.10.1 pgoyette fi
122 1.2.10.1 pgoyette fi
123 1.2.10.1 pgoyette
124 1.2.10.1 pgoyette cat > test.cpp << EOF
125 1.2.10.1 pgoyette #include <cstdlib>
126 1.2.10.1 pgoyette #include <iostream>
127 1.2.10.1 pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
128 1.2.10.1 pgoyette EOF
129 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
130 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
131 1.2.10.1 pgoyette }
132 1.2.10.1 pgoyette
133 1.2.10.1 pgoyette cxxruntime_static_body() {
134 1.2.10.1 pgoyette cat > test.cpp << EOF
135 1.2.10.1 pgoyette #include <cstdlib>
136 1.2.10.1 pgoyette #include <iostream>
137 1.2.10.1 pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
138 1.2.10.1 pgoyette EOF
139 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
140 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
141 1.2.10.1 pgoyette }
142 1.2.10.1 pgoyette
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.2.10.1 pgoyette cxxruntime_pic_32_body() {
164 1.2.10.1 pgoyette # check whether this arch is 64bit
165 1.2.10.1 pgoyette if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
166 1.2.10.1 pgoyette atf_skip "this is not a 64 bit architecture"
167 1.2.10.1 pgoyette fi
168 1.2.10.1 pgoyette if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
169 1.2.10.1 pgoyette atf_skip "c++ -m32 not supported on this architecture"
170 1.2.10.1 pgoyette else
171 1.2.10.1 pgoyette if fgrep -q _LP64 ./def32; then
172 1.2.10.1 pgoyette atf_fail "c++ -m32 does not generate netbsd32 binaries"
173 1.2.10.1 pgoyette fi
174 1.2.10.1 pgoyette fi
175 1.2.10.1 pgoyette
176 1.2.10.1 pgoyette cat > test.cpp << EOF
177 1.2.10.1 pgoyette #include <cstdlib>
178 1.2.10.1 pgoyette int callpic(void);
179 1.2.10.1 pgoyette int main(void) {callpic();exit(0);}
180 1.2.10.1 pgoyette EOF
181 1.2.10.1 pgoyette cat > pic.cpp << EOF
182 1.2.10.1 pgoyette #include <iostream>
183 1.2.10.1 pgoyette int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
184 1.2.10.1 pgoyette EOF
185 1.2.10.1 pgoyette
186 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
187 1.2.10.1 pgoyette c++ -m32 -fPIC -shared -o libtest.so pic.cpp
188 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
189 1.2.10.1 pgoyette c++ -m32 -o hello test.cpp -L. -ltest
190 1.2.10.1 pgoyette
191 1.2.10.1 pgoyette export LD_LIBRARY_PATH=.
192 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
193 1.2.10.1 pgoyette }
194 1.2.10.1 pgoyette
195 1.2.10.1 pgoyette cxxruntime_pic_profile_body() {
196 1.2.10.1 pgoyette cat > test.cpp << EOF
197 1.2.10.1 pgoyette #include <cstdlib>
198 1.2.10.1 pgoyette int callpic(void);
199 1.2.10.1 pgoyette int main(void) {callpic();exit(0);}
200 1.2.10.1 pgoyette EOF
201 1.2.10.1 pgoyette cat > pic.cpp << EOF
202 1.2.10.1 pgoyette #include <iostream>
203 1.2.10.1 pgoyette int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
204 1.2.10.1 pgoyette EOF
205 1.2.10.1 pgoyette
206 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
207 1.2.10.1 pgoyette c++ -pg -fPIC -shared -o libtest.so pic.cpp
208 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
209 1.2.10.1 pgoyette c++ -pg -o hello test.cpp -L. -ltest
210 1.2.10.1 pgoyette
211 1.2.10.1 pgoyette export LD_LIBRARY_PATH=.
212 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
213 1.2.10.1 pgoyette }
214 1.2.10.1 pgoyette
215 1.2.10.1 pgoyette cxxruntime_pic_profile_32_body() {
216 1.2.10.1 pgoyette # check whether this arch is 64bit
217 1.2.10.1 pgoyette if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
218 1.2.10.1 pgoyette atf_skip "this is not a 64 bit architecture"
219 1.2.10.1 pgoyette fi
220 1.2.10.1 pgoyette if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
221 1.2.10.1 pgoyette atf_skip "c++ -m32 not supported on this architecture"
222 1.2.10.1 pgoyette else
223 1.2.10.1 pgoyette if fgrep -q _LP64 ./def32; then
224 1.2.10.1 pgoyette atf_fail "c++ -m32 does not generate netbsd32 binaries"
225 1.2.10.1 pgoyette fi
226 1.2.10.1 pgoyette fi
227 1.2.10.1 pgoyette
228 1.2.10.1 pgoyette cat > test.cpp << EOF
229 1.2.10.1 pgoyette #include <cstdlib>
230 1.2.10.1 pgoyette int callpic(void);
231 1.2.10.1 pgoyette int main(void) {callpic();exit(0);}
232 1.2.10.1 pgoyette EOF
233 1.2.10.1 pgoyette cat > pic.cpp << EOF
234 1.2.10.1 pgoyette #include <iostream>
235 1.2.10.1 pgoyette int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
236 1.2.10.1 pgoyette EOF
237 1.2.10.1 pgoyette
238 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
239 1.2.10.1 pgoyette c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
240 1.2.10.1 pgoyette atf_check -s exit:0 -o ignore -e ignore \
241 1.2.10.1 pgoyette c++ -m32 -pg -o hello test.cpp -L. -ltest
242 1.2.10.1 pgoyette
243 1.2.10.1 pgoyette export LD_LIBRARY_PATH=.
244 1.2.10.1 pgoyette atf_check -s exit:0 -o inline:"hello world\n" ./hello
245 1.2.10.1 pgoyette }
246 1.2.10.1 pgoyette
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.2.10.1 pgoyette 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.2.10.1 pgoyette atf_add_test_case cxxruntime_static
311 1.2.10.1 pgoyette atf_add_test_case cxxruntime_pic_32
312 1.2.10.1 pgoyette atf_add_test_case cxxruntime_pic_profile
313 1.2.10.1 pgoyette atf_add_test_case cxxruntime_pic_profile_32
314 1.2.10.1 pgoyette atf_add_test_case cxxruntime_profile_32
315 1.1 kamil }
316