t_hello.sh revision 1.7 1 1.7 skrll # $NetBSD: t_hello.sh,v 1.7 2022/06/12 15:08:38 skrll Exp $
2 1.1 kamil #
3 1.1 kamil # Copyright (c) 2011 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 hello
29 1.1 kamil hello_head() {
30 1.1 kamil atf_set "descr" "compile and run \"hello world\""
31 1.1 kamil atf_set "require.progs" "c++"
32 1.1 kamil }
33 1.1 kamil
34 1.2 martin atf_test_case hello_profile
35 1.3 kamil hello_profile_head() {
36 1.2 martin atf_set "descr" "compile and run \"hello world\" with profiling option"
37 1.2 martin atf_set "require.progs" "c++"
38 1.2 martin }
39 1.2 martin
40 1.3 kamil atf_test_case hello_profile
41 1.3 kamil hello_profile_32_head() {
42 1.3 kamil atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
43 1.3 kamil atf_set "require.progs" "c++"
44 1.3 kamil }
45 1.3 kamil
46 1.3 kamil atf_test_case hello_static
47 1.3 kamil hello_static_head() {
48 1.3 kamil atf_set "descr" "compile and run \"hello world\" with static option"
49 1.3 kamil atf_set "require.progs" "c++"
50 1.3 kamil }
51 1.3 kamil
52 1.1 kamil atf_test_case hello_pic
53 1.1 kamil hello_pic_head() {
54 1.1 kamil atf_set "descr" "compile and run PIC \"hello world\""
55 1.1 kamil atf_set "require.progs" "c++"
56 1.1 kamil }
57 1.1 kamil
58 1.3 kamil atf_test_case hello_pic_32
59 1.3 kamil hello_pic_32_head() {
60 1.3 kamil atf_set "descr" "compile and run 32-bit PIC \"hello world\""
61 1.3 kamil atf_set "require.progs" "c++"
62 1.3 kamil }
63 1.3 kamil
64 1.3 kamil atf_test_case hello_pic_profile
65 1.3 kamil hello_pic_profile_head() {
66 1.3 kamil atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
67 1.3 kamil atf_set "require.progs" "c++"
68 1.3 kamil }
69 1.3 kamil
70 1.3 kamil atf_test_case hello_pic_profile_32
71 1.3 kamil hello_pic_profile_32_head() {
72 1.3 kamil atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
73 1.3 kamil atf_set "require.progs" "c++"
74 1.3 kamil }
75 1.3 kamil
76 1.1 kamil atf_test_case hello_pie
77 1.1 kamil hello_pie_head() {
78 1.1 kamil atf_set "descr" "compile and run position independent (PIE) \"hello world\""
79 1.1 kamil atf_set "require.progs" "c++"
80 1.1 kamil }
81 1.1 kamil
82 1.1 kamil atf_test_case hello32
83 1.1 kamil hello32_head() {
84 1.1 kamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
85 1.1 kamil atf_set "require.progs" "c++ file diff cat"
86 1.1 kamil }
87 1.1 kamil
88 1.1 kamil hello_body() {
89 1.1 kamil cat > test.cpp << EOF
90 1.1 kamil #include <stdio.h>
91 1.1 kamil #include <stdlib.h>
92 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
93 1.1 kamil EOF
94 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
95 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
96 1.1 kamil }
97 1.1 kamil
98 1.2 martin hello_profile_body() {
99 1.2 martin cat > test.cpp << EOF
100 1.2 martin #include <stdio.h>
101 1.2 martin #include <stdlib.h>
102 1.2 martin int main(void) {printf("hello world\n");exit(0);}
103 1.2 martin EOF
104 1.7 skrll atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp
105 1.2 martin atf_check -s exit:0 -o inline:"hello world\n" ./hello
106 1.2 martin }
107 1.2 martin
108 1.3 kamil hello_profile_32_body() {
109 1.3 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
110 1.3 kamil atf_skip "this is not a 64 bit architecture"
111 1.3 kamil fi
112 1.3 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
113 1.3 kamil atf_skip "c++ -m32 not supported on this architecture"
114 1.3 kamil else
115 1.3 kamil if fgrep -q _LP64 ./def32; then
116 1.3 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
117 1.3 kamil fi
118 1.3 kamil fi
119 1.3 kamil
120 1.3 kamil cat > test.cpp << EOF
121 1.3 kamil #include <stdio.h>
122 1.3 kamil #include <stdlib.h>
123 1.3 kamil int main(void) {printf("hello world\n");exit(0);}
124 1.3 kamil EOF
125 1.7 skrll atf_check -s exit:0 -o ignore -e ignore c++ -static -m32 -pg -o hello test.cpp
126 1.3 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
127 1.3 kamil }
128 1.3 kamil
129 1.3 kamil
130 1.3 kamil hello_static_body() {
131 1.3 kamil cat > test.cpp << EOF
132 1.3 kamil #include <stdio.h>
133 1.3 kamil #include <stdlib.h>
134 1.3 kamil int main(void) {printf("hello world\n");exit(0);}
135 1.3 kamil EOF
136 1.3 kamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
137 1.3 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
138 1.3 kamil }
139 1.3 kamil
140 1.1 kamil hello_pic_body() {
141 1.1 kamil cat > test.cpp << EOF
142 1.1 kamil #include <stdlib.h>
143 1.1 kamil int callpic(void);
144 1.1 kamil int main(void) {callpic();exit(0);}
145 1.1 kamil EOF
146 1.1 kamil cat > pic.cpp << EOF
147 1.1 kamil #include <stdio.h>
148 1.1 kamil int callpic(void) {printf("hello world\n");return 0;}
149 1.1 kamil EOF
150 1.1 kamil
151 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
152 1.1 kamil c++ -fPIC -shared -o libtest.so pic.cpp
153 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
154 1.1 kamil c++ -o hello test.cpp -L. -ltest
155 1.1 kamil
156 1.1 kamil export LD_LIBRARY_PATH=.
157 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
158 1.1 kamil }
159 1.1 kamil
160 1.3 kamil hello_pic_32_body() {
161 1.3 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
162 1.3 kamil atf_skip "this is not a 64 bit architecture"
163 1.3 kamil fi
164 1.3 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
165 1.3 kamil atf_skip "c++ -m32 not supported on this architecture"
166 1.3 kamil else
167 1.3 kamil if fgrep -q _LP64 ./def32; then
168 1.3 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
169 1.3 kamil fi
170 1.3 kamil fi
171 1.3 kamil cat > test.cpp << EOF
172 1.3 kamil #include <stdlib.h>
173 1.3 kamil int callpic(void);
174 1.3 kamil int main(void) {callpic();exit(0);}
175 1.3 kamil EOF
176 1.3 kamil cat > pic.cpp << EOF
177 1.3 kamil #include <stdio.h>
178 1.3 kamil int callpic(void) {printf("hello world\n");return 0;}
179 1.3 kamil EOF
180 1.3 kamil
181 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
182 1.3 kamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp
183 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
184 1.3 kamil c++ -m32 -o hello test.cpp -L. -ltest
185 1.3 kamil
186 1.3 kamil export LD_LIBRARY_PATH=.
187 1.3 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
188 1.3 kamil }
189 1.3 kamil
190 1.3 kamil hello_pic_profile_body() {
191 1.3 kamil cat > test.cpp << EOF
192 1.3 kamil #include <stdlib.h>
193 1.3 kamil int callpic(void);
194 1.3 kamil int main(void) {callpic();exit(0);}
195 1.3 kamil EOF
196 1.3 kamil cat > pic.cpp << EOF
197 1.3 kamil #include <stdio.h>
198 1.3 kamil int callpic(void) {printf("hello world\n");return 0;}
199 1.3 kamil EOF
200 1.3 kamil
201 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
202 1.3 kamil c++ -pg -fPIC -shared -o libtest.so pic.cpp
203 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
204 1.3 kamil c++ -pg -o hello test.cpp -L. -ltest
205 1.3 kamil
206 1.3 kamil export LD_LIBRARY_PATH=.
207 1.3 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
208 1.3 kamil }
209 1.3 kamil
210 1.3 kamil hello_pic_profile_32_body() {
211 1.3 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
212 1.3 kamil atf_skip "this is not a 64 bit architecture"
213 1.3 kamil fi
214 1.3 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
215 1.3 kamil atf_skip "c++ -m32 not supported on this architecture"
216 1.3 kamil else
217 1.3 kamil if fgrep -q _LP64 ./def32; then
218 1.3 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
219 1.3 kamil fi
220 1.3 kamil fi
221 1.3 kamil
222 1.3 kamil cat > test.cpp << EOF
223 1.3 kamil #include <stdlib.h>
224 1.3 kamil int callpic(void);
225 1.3 kamil int main(void) {callpic();exit(0);}
226 1.3 kamil EOF
227 1.3 kamil cat > pic.cpp << EOF
228 1.3 kamil #include <stdio.h>
229 1.3 kamil int callpic(void) {printf("hello world\n");return 0;}
230 1.3 kamil EOF
231 1.3 kamil
232 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
233 1.3 kamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
234 1.3 kamil atf_check -s exit:0 -o ignore -e ignore \
235 1.3 kamil c++ -m32 -pg -o hello test.cpp -L. -ltest
236 1.3 kamil
237 1.3 kamil export LD_LIBRARY_PATH=.
238 1.3 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
239 1.3 kamil }
240 1.3 kamil
241 1.1 kamil hello_pie_body() {
242 1.1 kamil # check whether this arch supports -pie
243 1.1 kamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
244 1.1 kamil atf_skip "c++ -pie not supported on this architecture"
245 1.1 kamil fi
246 1.1 kamil cat > test.cpp << EOF
247 1.1 kamil #include <stdio.h>
248 1.1 kamil #include <stdlib.h>
249 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
250 1.1 kamil EOF
251 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
252 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
253 1.1 kamil }
254 1.1 kamil
255 1.1 kamil hello32_body() {
256 1.1 kamil # check whether this arch is 64bit
257 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
258 1.1 kamil atf_skip "this is not a 64 bit architecture"
259 1.1 kamil fi
260 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
261 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
262 1.1 kamil else
263 1.1 kamil if fgrep -q _LP64 ./def32; then
264 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
265 1.1 kamil fi
266 1.1 kamil fi
267 1.1 kamil
268 1.1 kamil cat > test.cpp << EOF
269 1.1 kamil #include <stdio.h>
270 1.1 kamil #include <stdlib.h>
271 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
272 1.1 kamil EOF
273 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
274 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
275 1.1 kamil file -b ./hello32 > ./ftype32
276 1.1 kamil file -b ./hello64 > ./ftype64
277 1.1 kamil if diff ./ftype32 ./ftype64 >/dev/null; then
278 1.1 kamil atf_fail "generated binaries do not differ"
279 1.1 kamil fi
280 1.1 kamil echo "32bit binaries on this platform are:"
281 1.1 kamil cat ./ftype32
282 1.1 kamil echo "While native (64bit) binaries are:"
283 1.1 kamil cat ./ftype64
284 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32
285 1.1 kamil
286 1.1 kamil # do another test with static 32bit binaries
287 1.1 kamil cat > test.cpp << EOF
288 1.1 kamil #include <stdio.h>
289 1.1 kamil #include <stdlib.h>
290 1.1 kamil int main(void) {printf("hello static world\n");exit(0);}
291 1.1 kamil EOF
292 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
293 1.1 kamil -static test.cpp
294 1.1 kamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello
295 1.1 kamil }
296 1.1 kamil
297 1.1 kamil atf_init_test_cases()
298 1.1 kamil {
299 1.1 kamil
300 1.1 kamil atf_add_test_case hello
301 1.2 martin atf_add_test_case hello_profile
302 1.1 kamil atf_add_test_case hello_pic
303 1.1 kamil atf_add_test_case hello_pie
304 1.1 kamil atf_add_test_case hello32
305 1.3 kamil atf_add_test_case hello_static
306 1.3 kamil atf_add_test_case hello_pic_32
307 1.3 kamil atf_add_test_case hello_pic_profile
308 1.3 kamil atf_add_test_case hello_pic_profile_32
309 1.3 kamil atf_add_test_case hello_profile_32
310 1.1 kamil }
311