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