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