t_hello.sh revision 1.1 1 1.1 jruoho # $NetBSD: t_hello.sh,v 1.1 2012/03/17 17:15:29 jruoho Exp $
2 1.1 jruoho #
3 1.1 jruoho # Copyright (c) 2011 The NetBSD Foundation, Inc.
4 1.1 jruoho # All rights reserved.
5 1.1 jruoho #
6 1.1 jruoho # Redistribution and use in source and binary forms, with or without
7 1.1 jruoho # modification, are permitted provided that the following conditions
8 1.1 jruoho # are met:
9 1.1 jruoho # 1. Redistributions of source code must retain the above copyright
10 1.1 jruoho # notice, this list of conditions and the following disclaimer.
11 1.1 jruoho # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jruoho # notice, this list of conditions and the following disclaimer in the
13 1.1 jruoho # documentation and/or other materials provided with the distribution.
14 1.1 jruoho #
15 1.1 jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 jruoho # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 jruoho # POSSIBILITY OF SUCH DAMAGE.
26 1.1 jruoho #
27 1.1 jruoho
28 1.1 jruoho atf_test_case hello
29 1.1 jruoho hello_head() {
30 1.1 jruoho atf_set "descr" "compile and run \"hello world\""
31 1.1 jruoho atf_set "require.progs" "cc"
32 1.1 jruoho }
33 1.1 jruoho
34 1.1 jruoho atf_test_case hello_pic
35 1.1 jruoho hello_pic_head() {
36 1.1 jruoho atf_set "descr" "compile and run PIC \"hello world\""
37 1.1 jruoho atf_set "require.progs" "cc"
38 1.1 jruoho }
39 1.1 jruoho
40 1.1 jruoho atf_test_case hello32
41 1.1 jruoho hello32_head() {
42 1.1 jruoho atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
43 1.1 jruoho atf_set "require.progs" "cc file diff cat"
44 1.1 jruoho }
45 1.1 jruoho
46 1.1 jruoho hello_body() {
47 1.1 jruoho cat > test.c << EOF
48 1.1 jruoho #include <stdio.h>
49 1.1 jruoho #include <stdlib.h>
50 1.1 jruoho int main(void) {printf("hello world\n");exit(0);}
51 1.1 jruoho EOF
52 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore cc -o hello test.c
53 1.1 jruoho atf_check -s exit:0 -o inline:"hello world\n" ./hello
54 1.1 jruoho }
55 1.1 jruoho
56 1.1 jruoho hello_pic_body() {
57 1.1 jruoho cat > test.c << EOF
58 1.1 jruoho #include <stdlib.h>
59 1.1 jruoho int main(void) {callpic();exit(0);}
60 1.1 jruoho EOF
61 1.1 jruoho cat > pic.c << EOF
62 1.1 jruoho #include <stdio.h>
63 1.1 jruoho int callpic(void) {printf("hello world\n");}
64 1.1 jruoho EOF
65 1.1 jruoho
66 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore \
67 1.1 jruoho cc -fPIC -dPIC -shared -o libtest.so pic.c
68 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore \
69 1.1 jruoho cc -o hello test.c -L. -ltest
70 1.1 jruoho
71 1.1 jruoho export LD_LIBRARY_PATH=.
72 1.1 jruoho atf_check -s exit:0 -o inline:"hello world\n" ./hello
73 1.1 jruoho }
74 1.1 jruoho
75 1.1 jruoho hello32_body() {
76 1.1 jruoho # check whether this arch is 64bit
77 1.1 jruoho if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then
78 1.1 jruoho atf_skip "this is not a 64 bit architecture"
79 1.1 jruoho fi
80 1.1 jruoho if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
81 1.1 jruoho atf_skip "cc -m32 not supported on this architecture"
82 1.1 jruoho else
83 1.1 jruoho if fgrep -q _LP64 ./def32; then
84 1.1 jruoho atf_fail "cc -m32 does not generate netbsd32 binaries"
85 1.1 jruoho fi
86 1.1 jruoho fi
87 1.1 jruoho
88 1.1 jruoho cat > test.c << EOF
89 1.1 jruoho #include <stdio.h>
90 1.1 jruoho #include <stdlib.h>
91 1.1 jruoho int main(void) {printf("hello world\n");exit(0);}
92 1.1 jruoho EOF
93 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore cc -o hello32 -m32 test.c
94 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore cc -o hello64 test.c
95 1.1 jruoho file -b ./hello32 > ./ftype32
96 1.1 jruoho file -b ./hello64 > ./ftype64
97 1.1 jruoho if diff ./ftype32 ./ftype64 >/dev/null; then
98 1.1 jruoho atf_fail "generated binaries do not differ"
99 1.1 jruoho fi
100 1.1 jruoho echo "32bit binaries on this platform are:"
101 1.1 jruoho cat ./ftype32
102 1.1 jruoho echo "While native (64bit) binaries are:"
103 1.1 jruoho cat ./ftype64
104 1.1 jruoho atf_check -s exit:0 -o inline:"hello world\n" ./hello32
105 1.1 jruoho
106 1.1 jruoho # do another test with static 32bit binaries
107 1.1 jruoho cat > test.c << EOF
108 1.1 jruoho #include <stdio.h>
109 1.1 jruoho #include <stdlib.h>
110 1.1 jruoho int main(void) {printf("hello static world\n");exit(0);}
111 1.1 jruoho EOF
112 1.1 jruoho atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \
113 1.1 jruoho -static test.c
114 1.1 jruoho atf_check -s exit:0 -o inline:"hello static world\n" ./hello
115 1.1 jruoho }
116 1.1 jruoho
117 1.1 jruoho atf_init_test_cases()
118 1.1 jruoho {
119 1.1 jruoho
120 1.1 jruoho atf_add_test_case hello
121 1.1 jruoho atf_add_test_case hello_pic
122 1.1 jruoho atf_add_test_case hello32
123 1.1 jruoho }
124