Home | History | Annotate | Line # | Download | only in c++
t_cxxruntime.sh revision 1.2.2.2
      1  1.2.2.2  pgoyette #	$NetBSD: t_cxxruntime.sh,v 1.2.2.2 2017/05/19 00:22:59 pgoyette Exp $
      2  1.2.2.2  pgoyette #
      3  1.2.2.2  pgoyette # Copyright (c) 2017 The NetBSD Foundation, Inc.
      4  1.2.2.2  pgoyette # All rights reserved.
      5  1.2.2.2  pgoyette #
      6  1.2.2.2  pgoyette # This code is derived from software contributed to The NetBSD Foundation
      7  1.2.2.2  pgoyette # by Kamil Rytarowski.
      8  1.2.2.2  pgoyette #
      9  1.2.2.2  pgoyette # Redistribution and use in source and binary forms, with or without
     10  1.2.2.2  pgoyette # modification, are permitted provided that the following conditions
     11  1.2.2.2  pgoyette # are met:
     12  1.2.2.2  pgoyette # 1. Redistributions of source code must retain the above copyright
     13  1.2.2.2  pgoyette #    notice, this list of conditions and the following disclaimer.
     14  1.2.2.2  pgoyette # 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.2.2  pgoyette #    notice, this list of conditions and the following disclaimer in the
     16  1.2.2.2  pgoyette #    documentation and/or other materials provided with the distribution.
     17  1.2.2.2  pgoyette #
     18  1.2.2.2  pgoyette # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.2.2.2  pgoyette # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.2.2.2  pgoyette # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.2.2.2  pgoyette # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.2.2.2  pgoyette # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.2.2.2  pgoyette # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.2.2.2  pgoyette # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.2.2.2  pgoyette # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.2.2.2  pgoyette # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.2.2.2  pgoyette # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.2.2.2  pgoyette # POSSIBILITY OF SUCH DAMAGE.
     29  1.2.2.2  pgoyette #
     30  1.2.2.2  pgoyette 
     31  1.2.2.2  pgoyette atf_test_case cxxruntime
     32  1.2.2.2  pgoyette cxxruntime_head() {
     33  1.2.2.2  pgoyette 	atf_set "descr" "compile and run \"hello world\""
     34  1.2.2.2  pgoyette 	atf_set "require.progs" "c++"
     35  1.2.2.2  pgoyette }
     36  1.2.2.2  pgoyette 
     37  1.2.2.2  pgoyette atf_test_case cxxruntime_pic
     38  1.2.2.2  pgoyette cxxruntime_pic_head() {
     39  1.2.2.2  pgoyette 	atf_set "descr" "compile and run PIC \"hello world\""
     40  1.2.2.2  pgoyette 	atf_set "require.progs" "c++"
     41  1.2.2.2  pgoyette }
     42  1.2.2.2  pgoyette 
     43  1.2.2.2  pgoyette atf_test_case cxxruntime_pie
     44  1.2.2.2  pgoyette cxxruntime_pie_head() {
     45  1.2.2.2  pgoyette 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
     46  1.2.2.2  pgoyette 	atf_set "require.progs" "c++"
     47  1.2.2.2  pgoyette }
     48  1.2.2.2  pgoyette 
     49  1.2.2.2  pgoyette atf_test_case cxxruntime32
     50  1.2.2.2  pgoyette cxxruntime32_head() {
     51  1.2.2.2  pgoyette 	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
     52  1.2.2.2  pgoyette 	atf_set "require.progs" "c++ file diff cat"
     53  1.2.2.2  pgoyette }
     54  1.2.2.2  pgoyette 
     55  1.2.2.2  pgoyette cxxruntime_body() {
     56  1.2.2.2  pgoyette 	cat > test.cpp << EOF
     57  1.2.2.2  pgoyette #include <cstdlib>
     58  1.2.2.2  pgoyette #include <iostream>
     59  1.2.2.2  pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
     60  1.2.2.2  pgoyette EOF
     61  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
     62  1.2.2.2  pgoyette 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     63  1.2.2.2  pgoyette }
     64  1.2.2.2  pgoyette 
     65  1.2.2.2  pgoyette cxxruntime_pic_body() {
     66  1.2.2.2  pgoyette 	cat > test.cpp << EOF
     67  1.2.2.2  pgoyette #include <cstdlib>
     68  1.2.2.2  pgoyette int callpic(void);
     69  1.2.2.2  pgoyette int main(void) {callpic();exit(0);}
     70  1.2.2.2  pgoyette EOF
     71  1.2.2.2  pgoyette 	cat > pic.cpp << EOF
     72  1.2.2.2  pgoyette #include <iostream>
     73  1.2.2.2  pgoyette int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
     74  1.2.2.2  pgoyette EOF
     75  1.2.2.2  pgoyette 
     76  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore \
     77  1.2.2.2  pgoyette 	    c++ -fPIC -shared -o libtest.so pic.cpp
     78  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore \
     79  1.2.2.2  pgoyette 	    c++ -o hello test.cpp -L. -ltest
     80  1.2.2.2  pgoyette 
     81  1.2.2.2  pgoyette 	export LD_LIBRARY_PATH=.
     82  1.2.2.2  pgoyette 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     83  1.2.2.2  pgoyette }
     84  1.2.2.2  pgoyette 
     85  1.2.2.2  pgoyette cxxruntime_pie_body() {
     86  1.2.2.2  pgoyette 	# check whether this arch supports -pie
     87  1.2.2.2  pgoyette 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
     88  1.2.2.2  pgoyette 		atf_skip "c++ -pie not supported on this architecture"
     89  1.2.2.2  pgoyette 	fi
     90  1.2.2.2  pgoyette 	cat > test.cpp << EOF
     91  1.2.2.2  pgoyette #include <cstdlib>
     92  1.2.2.2  pgoyette #include <iostream>
     93  1.2.2.2  pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
     94  1.2.2.2  pgoyette EOF
     95  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
     96  1.2.2.2  pgoyette 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     97  1.2.2.2  pgoyette }
     98  1.2.2.2  pgoyette 
     99  1.2.2.2  pgoyette cxxruntime32_body() {
    100  1.2.2.2  pgoyette 	# check whether this arch is 64bit
    101  1.2.2.2  pgoyette 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    102  1.2.2.2  pgoyette 		atf_skip "this is not a 64 bit architecture"
    103  1.2.2.2  pgoyette 	fi
    104  1.2.2.2  pgoyette 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    105  1.2.2.2  pgoyette 		atf_skip "c++ -m32 not supported on this architecture"
    106  1.2.2.2  pgoyette 	else
    107  1.2.2.2  pgoyette 		if fgrep -q _LP64 ./def32; then
    108  1.2.2.2  pgoyette 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    109  1.2.2.2  pgoyette 		fi
    110  1.2.2.2  pgoyette 	fi
    111  1.2.2.2  pgoyette 
    112  1.2.2.2  pgoyette 	cat > test.cpp << EOF
    113  1.2.2.2  pgoyette #include <cstdlib>
    114  1.2.2.2  pgoyette #include <iostream>
    115  1.2.2.2  pgoyette int main(void) {std::cout << "hello world" << std::endl;exit(0);}
    116  1.2.2.2  pgoyette EOF
    117  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
    118  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
    119  1.2.2.2  pgoyette 	file -b ./hello32 > ./ftype32
    120  1.2.2.2  pgoyette 	file -b ./hello64 > ./ftype64
    121  1.2.2.2  pgoyette 	if diff ./ftype32 ./ftype64 >/dev/null; then
    122  1.2.2.2  pgoyette 		atf_fail "generated binaries do not differ"
    123  1.2.2.2  pgoyette 	fi
    124  1.2.2.2  pgoyette 	echo "32bit binaries on this platform are:"
    125  1.2.2.2  pgoyette 	cat ./ftype32
    126  1.2.2.2  pgoyette 	echo "While native (64bit) binaries are:"
    127  1.2.2.2  pgoyette 	cat ./ftype64
    128  1.2.2.2  pgoyette 	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
    129  1.2.2.2  pgoyette 
    130  1.2.2.2  pgoyette 	# do another test with static 32bit binaries
    131  1.2.2.2  pgoyette 	cat > test.cpp << EOF
    132  1.2.2.2  pgoyette #include <cstdlib>
    133  1.2.2.2  pgoyette #include <iostream>
    134  1.2.2.2  pgoyette int main(void) {std::cout << "hello static world" << std::endl;exit(0);}
    135  1.2.2.2  pgoyette EOF
    136  1.2.2.2  pgoyette 	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
    137  1.2.2.2  pgoyette 	    -static test.cpp
    138  1.2.2.2  pgoyette 	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
    139  1.2.2.2  pgoyette }
    140  1.2.2.2  pgoyette 
    141  1.2.2.2  pgoyette atf_init_test_cases()
    142  1.2.2.2  pgoyette {
    143  1.2.2.2  pgoyette 
    144  1.2.2.2  pgoyette 	atf_add_test_case cxxruntime
    145  1.2.2.2  pgoyette 	atf_add_test_case cxxruntime_pic
    146  1.2.2.2  pgoyette 	atf_add_test_case cxxruntime_pie
    147  1.2.2.2  pgoyette 	atf_add_test_case cxxruntime32
    148  1.2.2.2  pgoyette }
    149