t_hello.sh revision 1.1 1 1.1 kamil # $NetBSD: t_hello.sh,v 1.1 2017/05/14 00:07:07 kamil 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.1 kamil atf_test_case hello_pic
35 1.1 kamil hello_pic_head() {
36 1.1 kamil atf_set "descr" "compile and run PIC \"hello world\""
37 1.1 kamil atf_set "require.progs" "c++"
38 1.1 kamil }
39 1.1 kamil
40 1.1 kamil atf_test_case hello_pie
41 1.1 kamil hello_pie_head() {
42 1.1 kamil atf_set "descr" "compile and run position independent (PIE) \"hello world\""
43 1.1 kamil atf_set "require.progs" "c++"
44 1.1 kamil }
45 1.1 kamil
46 1.1 kamil atf_test_case hello32
47 1.1 kamil hello32_head() {
48 1.1 kamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
49 1.1 kamil atf_set "require.progs" "c++ file diff cat"
50 1.1 kamil }
51 1.1 kamil
52 1.1 kamil hello_body() {
53 1.1 kamil cat > test.cpp << EOF
54 1.1 kamil #include <stdio.h>
55 1.1 kamil #include <stdlib.h>
56 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
57 1.1 kamil EOF
58 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
59 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
60 1.1 kamil }
61 1.1 kamil
62 1.1 kamil hello_pic_body() {
63 1.1 kamil cat > test.cpp << EOF
64 1.1 kamil #include <stdlib.h>
65 1.1 kamil int callpic(void);
66 1.1 kamil int main(void) {callpic();exit(0);}
67 1.1 kamil EOF
68 1.1 kamil cat > pic.cpp << EOF
69 1.1 kamil #include <stdio.h>
70 1.1 kamil int callpic(void) {printf("hello world\n");return 0;}
71 1.1 kamil EOF
72 1.1 kamil
73 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
74 1.1 kamil c++ -fPIC -shared -o libtest.so pic.cpp
75 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \
76 1.1 kamil c++ -o hello test.cpp -L. -ltest
77 1.1 kamil
78 1.1 kamil export LD_LIBRARY_PATH=.
79 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
80 1.1 kamil }
81 1.1 kamil
82 1.1 kamil hello_pie_body() {
83 1.1 kamil # check whether this arch supports -pie
84 1.1 kamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
85 1.1 kamil atf_skip "c++ -pie not supported on this architecture"
86 1.1 kamil fi
87 1.1 kamil cat > test.cpp << EOF
88 1.1 kamil #include <stdio.h>
89 1.1 kamil #include <stdlib.h>
90 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
91 1.1 kamil EOF
92 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
93 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello
94 1.1 kamil }
95 1.1 kamil
96 1.1 kamil hello32_body() {
97 1.1 kamil # check whether this arch is 64bit
98 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
99 1.1 kamil atf_skip "this is not a 64 bit architecture"
100 1.1 kamil fi
101 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
102 1.1 kamil atf_skip "c++ -m32 not supported on this architecture"
103 1.1 kamil else
104 1.1 kamil if fgrep -q _LP64 ./def32; then
105 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries"
106 1.1 kamil fi
107 1.1 kamil fi
108 1.1 kamil
109 1.1 kamil cat > test.cpp << EOF
110 1.1 kamil #include <stdio.h>
111 1.1 kamil #include <stdlib.h>
112 1.1 kamil int main(void) {printf("hello world\n");exit(0);}
113 1.1 kamil EOF
114 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
115 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
116 1.1 kamil file -b ./hello32 > ./ftype32
117 1.1 kamil file -b ./hello64 > ./ftype64
118 1.1 kamil if diff ./ftype32 ./ftype64 >/dev/null; then
119 1.1 kamil atf_fail "generated binaries do not differ"
120 1.1 kamil fi
121 1.1 kamil echo "32bit binaries on this platform are:"
122 1.1 kamil cat ./ftype32
123 1.1 kamil echo "While native (64bit) binaries are:"
124 1.1 kamil cat ./ftype64
125 1.1 kamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32
126 1.1 kamil
127 1.1 kamil # do another test with static 32bit binaries
128 1.1 kamil cat > test.cpp << EOF
129 1.1 kamil #include <stdio.h>
130 1.1 kamil #include <stdlib.h>
131 1.1 kamil int main(void) {printf("hello static world\n");exit(0);}
132 1.1 kamil EOF
133 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
134 1.1 kamil -static test.cpp
135 1.1 kamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello
136 1.1 kamil }
137 1.1 kamil
138 1.1 kamil atf_init_test_cases()
139 1.1 kamil {
140 1.1 kamil
141 1.1 kamil atf_add_test_case hello
142 1.1 kamil atf_add_test_case hello_pic
143 1.1 kamil atf_add_test_case hello_pie
144 1.1 kamil atf_add_test_case hello32
145 1.1 kamil }
146