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