1 # $NetBSD: t_hello.sh,v 1.2 2012/07/21 12:30:55 martin Exp $
3 # Copyright (c) 2011 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
30 atf_set
"descr" "compile and run \"hello world\""
31 atf_set
"require.progs" "cc"
34 atf_test_case hello_pic
36 atf_set
"descr" "compile and run PIC \"hello world\""
37 atf_set
"require.progs" "cc"
40 atf_test_case hello_pie
42 atf_set
"descr" "compile and run position independend (PIE) \"hello world\""
43 atf_set
"require.progs" "cc"
48 atf_set
"descr" "compile and run \"hello world\" for/in netbsd32 emulation"
49 atf_set
"require.progs" "cc file diff cat"
56 int main(void) {printf("hello world\n");exit(0);}
58 atf_check
-s exit:0 -o ignore
-e ignore cc
-o hello
test.c
59 atf_check
-s exit:0 -o inline
:"hello world\n" .
/hello
65 int main(void) {callpic();exit(0);}
69 int callpic(void) {printf("hello world\n");}
72 atf_check
-s exit:0 -o ignore
-e ignore \
73 cc
-fPIC -dPIC -shared -o libtest.so pic.c
74 atf_check
-s exit:0 -o ignore
-e ignore \
75 cc
-o hello
test.c
-L.
-ltest
77 export LD_LIBRARY_PATH
=.
78 atf_check
-s exit:0 -o inline
:"hello world\n" .
/hello
82 # check whether this arch supports -pie
83 if ! cc
-pie -dM -E - < /dev
/null
2>/dev
/null
>/dev
/null
; then
84 atf_skip
"cc -pie not supported on this architecture"
89 int main(void) {printf("hello world\n");exit(0);}
91 atf_check
-s exit:0 -o ignore
-e ignore cc
-fpie -pie -o hello
test.c
92 atf_check
-s exit:0 -o inline
:"hello world\n" .
/hello
96 # check whether this arch is 64bit
97 if ! cc
-dM -E - < /dev
/null | fgrep
-q _LP64
; then
98 atf_skip
"this is not a 64 bit architecture"
100 if ! cc
-m32 -dM -E - < /dev
/null
2>/dev
/null
> .
/def32
; then
101 atf_skip
"cc -m32 not supported on this architecture"
103 if fgrep
-q _LP64 .
/def32
; then
104 atf_fail
"cc -m32 does not generate netbsd32 binaries"
111 int main(void) {printf("hello world\n");exit(0);}
113 atf_check
-s exit:0 -o ignore
-e ignore cc
-o hello32
-m32 test.c
114 atf_check
-s exit:0 -o ignore
-e ignore cc
-o hello64
test.c
115 file -b .
/hello32
> .
/ftype32
116 file -b .
/hello64
> .
/ftype64
117 if diff .
/ftype32 .
/ftype64
>/dev
/null
; then
118 atf_fail
"generated binaries do not differ"
120 echo "32bit binaries on this platform are:"
122 echo "While native (64bit) binaries are:"
124 atf_check
-s exit:0 -o inline
:"hello world\n" .
/hello32
126 # do another test with static 32bit binaries
130 int main(void) {printf("hello static world\n");exit(0);}
132 atf_check
-s exit:0 -o ignore
-e ignore cc
-o hello
-m32 \
134 atf_check
-s exit:0 -o inline
:"hello static world\n" .
/hello
137 atf_init_test_cases
()
140 atf_add_test_case hello
141 atf_add_test_case hello_pic
142 atf_add_test_case hello_pie
143 atf_add_test_case hello32