Home | History | Annotate | Line # | Download | only in c++
t_cxxruntime.sh revision 1.4
      1  1.4  riastrad #	$NetBSD: t_cxxruntime.sh,v 1.4 2020/02/11 06:26:19 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.3     kamil 	cat > test.cpp << EOF
    103  1.3     kamil #include <cstdlib>
    104  1.3     kamil #include <iostream>
    105  1.3     kamil int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    106  1.3     kamil EOF
    107  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
    108  1.4  riastrad 	case `uname -p` in
    109  1.4  riastrad 	aarch64)
    110  1.4  riastrad 		atf_expect_fail 'cc -pg is busted on aarch64'
    111  1.4  riastrad 		;;
    112  1.4  riastrad 	esac
    113  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    114  1.3     kamil }
    115  1.3     kamil 
    116  1.3     kamil cxxruntime_profile_32_body() {
    117  1.3     kamil 	# check whether this arch is 64bit
    118  1.3     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    119  1.3     kamil 		atf_skip "this is not a 64 bit architecture"
    120  1.3     kamil 	fi
    121  1.3     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    122  1.3     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    123  1.3     kamil 	else
    124  1.3     kamil 		if fgrep -q _LP64 ./def32; then
    125  1.3     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    126  1.3     kamil 		fi
    127  1.3     kamil 	fi
    128  1.3     kamil 
    129  1.3     kamil 	cat > test.cpp << EOF
    130  1.3     kamil #include <cstdlib>
    131  1.3     kamil #include <iostream>
    132  1.3     kamil int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    133  1.3     kamil EOF
    134  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
    135  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    136  1.3     kamil }
    137  1.3     kamil 
    138  1.3     kamil cxxruntime_static_body() {
    139  1.3     kamil 	cat > test.cpp << EOF
    140  1.3     kamil #include <cstdlib>
    141  1.3     kamil #include <iostream>
    142  1.3     kamil int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    143  1.3     kamil EOF
    144  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
    145  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    146  1.3     kamil }
    147  1.3     kamil 
    148  1.1     kamil cxxruntime_pic_body() {
    149  1.1     kamil 	cat > test.cpp << EOF
    150  1.1     kamil #include <cstdlib>
    151  1.1     kamil int callpic(void);
    152  1.1     kamil int main(void) {callpic();exit(0);}
    153  1.1     kamil EOF
    154  1.1     kamil 	cat > pic.cpp << EOF
    155  1.1     kamil #include <iostream>
    156  1.1     kamil int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
    157  1.1     kamil EOF
    158  1.1     kamil 
    159  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    160  1.1     kamil 	    c++ -fPIC -shared -o libtest.so pic.cpp
    161  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    162  1.1     kamil 	    c++ -o hello test.cpp -L. -ltest
    163  1.1     kamil 
    164  1.1     kamil 	export LD_LIBRARY_PATH=.
    165  1.1     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    166  1.1     kamil }
    167  1.1     kamil 
    168  1.3     kamil cxxruntime_pic_32_body() {
    169  1.3     kamil 	# check whether this arch is 64bit
    170  1.3     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    171  1.3     kamil 		atf_skip "this is not a 64 bit architecture"
    172  1.3     kamil 	fi
    173  1.3     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    174  1.3     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    175  1.3     kamil 	else
    176  1.3     kamil 		if fgrep -q _LP64 ./def32; then
    177  1.3     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    178  1.3     kamil 		fi
    179  1.3     kamil 	fi
    180  1.3     kamil 
    181  1.3     kamil 	cat > test.cpp << EOF
    182  1.3     kamil #include <cstdlib>
    183  1.3     kamil int callpic(void);
    184  1.3     kamil int main(void) {callpic();exit(0);}
    185  1.3     kamil EOF
    186  1.3     kamil 	cat > pic.cpp << EOF
    187  1.3     kamil #include <iostream>
    188  1.3     kamil int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
    189  1.3     kamil EOF
    190  1.3     kamil 
    191  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    192  1.3     kamil 	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
    193  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    194  1.3     kamil 	    c++ -m32 -o hello test.cpp -L. -ltest
    195  1.3     kamil 
    196  1.3     kamil 	export LD_LIBRARY_PATH=.
    197  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    198  1.3     kamil }
    199  1.3     kamil 
    200  1.3     kamil cxxruntime_pic_profile_body() {
    201  1.3     kamil 	cat > test.cpp << EOF
    202  1.3     kamil #include <cstdlib>
    203  1.3     kamil int callpic(void);
    204  1.3     kamil int main(void) {callpic();exit(0);}
    205  1.3     kamil EOF
    206  1.3     kamil 	cat > pic.cpp << EOF
    207  1.3     kamil #include <iostream>
    208  1.3     kamil int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
    209  1.3     kamil EOF
    210  1.3     kamil 
    211  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    212  1.3     kamil 	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
    213  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    214  1.3     kamil 	    c++ -pg -o hello test.cpp -L. -ltest
    215  1.3     kamil 
    216  1.4  riastrad 	case `uname -p` in
    217  1.4  riastrad 	aarch64)
    218  1.4  riastrad 		atf_expect_fail 'cc -pg is busted on aarch64'
    219  1.4  riastrad 		;;
    220  1.4  riastrad 	esac
    221  1.3     kamil 	export LD_LIBRARY_PATH=.
    222  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    223  1.3     kamil }
    224  1.3     kamil 
    225  1.3     kamil cxxruntime_pic_profile_32_body() {
    226  1.3     kamil 	# check whether this arch is 64bit
    227  1.3     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    228  1.3     kamil 		atf_skip "this is not a 64 bit architecture"
    229  1.3     kamil 	fi
    230  1.3     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    231  1.3     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    232  1.3     kamil 	else
    233  1.3     kamil 		if fgrep -q _LP64 ./def32; then
    234  1.3     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    235  1.3     kamil 		fi
    236  1.3     kamil 	fi
    237  1.3     kamil 
    238  1.3     kamil 	cat > test.cpp << EOF
    239  1.3     kamil #include <cstdlib>
    240  1.3     kamil int callpic(void);
    241  1.3     kamil int main(void) {callpic();exit(0);}
    242  1.3     kamil EOF
    243  1.3     kamil 	cat > pic.cpp << EOF
    244  1.3     kamil #include <iostream>
    245  1.3     kamil int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
    246  1.3     kamil EOF
    247  1.3     kamil 
    248  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    249  1.3     kamil 	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
    250  1.3     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    251  1.3     kamil 	    c++ -m32 -pg -o hello test.cpp -L. -ltest
    252  1.3     kamil 
    253  1.3     kamil 	export LD_LIBRARY_PATH=.
    254  1.3     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    255  1.3     kamil }
    256  1.3     kamil 
    257  1.1     kamil cxxruntime_pie_body() {
    258  1.1     kamil 	# check whether this arch supports -pie
    259  1.1     kamil 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    260  1.1     kamil 		atf_skip "c++ -pie not supported on this architecture"
    261  1.1     kamil 	fi
    262  1.1     kamil 	cat > test.cpp << EOF
    263  1.1     kamil #include <cstdlib>
    264  1.1     kamil #include <iostream>
    265  1.1     kamil int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    266  1.1     kamil EOF
    267  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
    268  1.1     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    269  1.1     kamil }
    270  1.1     kamil 
    271  1.1     kamil cxxruntime32_body() {
    272  1.1     kamil 	# check whether this arch is 64bit
    273  1.1     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    274  1.1     kamil 		atf_skip "this is not a 64 bit architecture"
    275  1.1     kamil 	fi
    276  1.1     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    277  1.1     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    278  1.1     kamil 	else
    279  1.1     kamil 		if fgrep -q _LP64 ./def32; then
    280  1.1     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    281  1.1     kamil 		fi
    282  1.1     kamil 	fi
    283  1.1     kamil 
    284  1.1     kamil 	cat > test.cpp << EOF
    285  1.2     kamil #include <cstdlib>
    286  1.2     kamil #include <iostream>
    287  1.2     kamil int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    288  1.1     kamil EOF
    289  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
    290  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
    291  1.1     kamil 	file -b ./hello32 > ./ftype32
    292  1.1     kamil 	file -b ./hello64 > ./ftype64
    293  1.1     kamil 	if diff ./ftype32 ./ftype64 >/dev/null; then
    294  1.1     kamil 		atf_fail "generated binaries do not differ"
    295  1.1     kamil 	fi
    296  1.1     kamil 	echo "32bit binaries on this platform are:"
    297  1.1     kamil 	cat ./ftype32
    298  1.1     kamil 	echo "While native (64bit) binaries are:"
    299  1.1     kamil 	cat ./ftype64
    300  1.1     kamil 	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
    301  1.1     kamil 
    302  1.1     kamil 	# do another test with static 32bit binaries
    303  1.1     kamil 	cat > test.cpp << EOF
    304  1.2     kamil #include <cstdlib>
    305  1.1     kamil #include <iostream>
    306  1.1     kamil int main(void) {std::cout << "hello static world" << std::endl;exit(0);}
    307  1.1     kamil EOF
    308  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
    309  1.1     kamil 	    -static test.cpp
    310  1.1     kamil 	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
    311  1.1     kamil }
    312  1.1     kamil 
    313  1.1     kamil atf_init_test_cases()
    314  1.1     kamil {
    315  1.1     kamil 	atf_add_test_case cxxruntime
    316  1.3     kamil 	atf_add_test_case cxxruntime_profile
    317  1.1     kamil 	atf_add_test_case cxxruntime_pic
    318  1.1     kamil 	atf_add_test_case cxxruntime_pie
    319  1.1     kamil 	atf_add_test_case cxxruntime32
    320  1.3     kamil 	atf_add_test_case cxxruntime_static
    321  1.3     kamil 	atf_add_test_case cxxruntime_pic_32
    322  1.3     kamil 	atf_add_test_case cxxruntime_pic_profile
    323  1.3     kamil 	atf_add_test_case cxxruntime_pic_profile_32
    324  1.3     kamil 	atf_add_test_case cxxruntime_profile_32
    325  1.1     kamil }
    326