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