Home | History | Annotate | Line # | Download | only in c++
t_hello.sh revision 1.2
      1 #	$NetBSD: t_hello.sh,v 1.2 2017/05/18 10:29:47 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_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_pic
     41 hello_pic_head() {
     42 	atf_set "descr" "compile and run PIC \"hello world\""
     43 	atf_set "require.progs" "c++"
     44 }
     45 
     46 atf_test_case hello_pie
     47 hello_pie_head() {
     48 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
     49 	atf_set "require.progs" "c++"
     50 }
     51 
     52 atf_test_case hello32
     53 hello32_head() {
     54 	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
     55 	atf_set "require.progs" "c++ file diff cat"
     56 }
     57 
     58 hello_body() {
     59 	cat > test.cpp << EOF
     60 #include <stdio.h>
     61 #include <stdlib.h>
     62 int main(void) {printf("hello world\n");exit(0);}
     63 EOF
     64 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
     65 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     66 }
     67 
     68 hello_profile_body() {
     69 	cat > test.cpp << EOF
     70 #include <stdio.h>
     71 #include <stdlib.h>
     72 int main(void) {printf("hello world\n");exit(0);}
     73 EOF
     74 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
     75 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     76 }
     77 
     78 hello_pic_body() {
     79 	cat > test.cpp << EOF
     80 #include <stdlib.h>
     81 int callpic(void);
     82 int main(void) {callpic();exit(0);}
     83 EOF
     84 	cat > pic.cpp << EOF
     85 #include <stdio.h>
     86 int callpic(void) {printf("hello world\n");return 0;}
     87 EOF
     88 
     89 	atf_check -s exit:0 -o ignore -e ignore \
     90 	    c++ -fPIC -shared -o libtest.so pic.cpp
     91 	atf_check -s exit:0 -o ignore -e ignore \
     92 	    c++ -o hello test.cpp -L. -ltest
     93 
     94 	export LD_LIBRARY_PATH=.
     95 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     96 }
     97 
     98 hello_pie_body() {
     99 	# check whether this arch supports -pie
    100 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    101 		atf_skip "c++ -pie not supported on this architecture"
    102 	fi
    103 	cat > test.cpp << EOF
    104 #include <stdio.h>
    105 #include <stdlib.h>
    106 int main(void) {printf("hello world\n");exit(0);}
    107 EOF
    108 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
    109 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    110 }
    111 
    112 hello32_body() {
    113 	# check whether this arch is 64bit
    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++ -o hello32 -m32 test.cpp
    131 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
    132 	file -b ./hello32 > ./ftype32
    133 	file -b ./hello64 > ./ftype64
    134 	if diff ./ftype32 ./ftype64 >/dev/null; then
    135 		atf_fail "generated binaries do not differ"
    136 	fi
    137 	echo "32bit binaries on this platform are:"
    138 	cat ./ftype32
    139 	echo "While native (64bit) binaries are:"
    140 	cat ./ftype64
    141 	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
    142 
    143 	# do another test with static 32bit binaries
    144 	cat > test.cpp << EOF
    145 #include <stdio.h>
    146 #include <stdlib.h>
    147 int main(void) {printf("hello static world\n");exit(0);}
    148 EOF
    149 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
    150 	    -static test.cpp
    151 	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
    152 }
    153 
    154 atf_init_test_cases()
    155 {
    156 
    157 	atf_add_test_case hello
    158 	atf_add_test_case hello_profile
    159 	atf_add_test_case hello_pic
    160 	atf_add_test_case hello_pie
    161 	atf_add_test_case hello32
    162 }
    163