t_cxxruntime.sh revision 1.3
11.3Skamil#	$NetBSD: t_cxxruntime.sh,v 1.3 2018/03/24 00:26:51 kamil Exp $
21.1Skamil#
31.1Skamil# Copyright (c) 2017 The NetBSD Foundation, Inc.
41.1Skamil# All rights reserved.
51.1Skamil#
61.1Skamil# This code is derived from software contributed to The NetBSD Foundation
71.1Skamil# by Kamil Rytarowski.
81.1Skamil#
91.1Skamil# Redistribution and use in source and binary forms, with or without
101.1Skamil# modification, are permitted provided that the following conditions
111.1Skamil# are met:
121.1Skamil# 1. Redistributions of source code must retain the above copyright
131.1Skamil#    notice, this list of conditions and the following disclaimer.
141.1Skamil# 2. Redistributions in binary form must reproduce the above copyright
151.1Skamil#    notice, this list of conditions and the following disclaimer in the
161.1Skamil#    documentation and/or other materials provided with the distribution.
171.1Skamil#
181.1Skamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Skamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Skamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Skamil# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Skamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Skamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Skamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Skamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Skamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Skamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Skamil# POSSIBILITY OF SUCH DAMAGE.
291.1Skamil#
301.1Skamil
311.1Skamilatf_test_case cxxruntime
321.1Skamilcxxruntime_head() {
331.1Skamil	atf_set "descr" "compile and run \"hello world\""
341.1Skamil	atf_set "require.progs" "c++"
351.1Skamil}
361.1Skamil
371.3Skamilatf_test_case cxxruntime_profile
381.3Skamilcxxruntime_profile_head() {
391.3Skamil	atf_set "descr" "compile and run \"hello world\" with profiling option"
401.3Skamil	atf_set "require.progs" "c++"
411.3Skamil}
421.3Skamil
431.3Skamilatf_test_case cxxruntime_profile_32
441.3Skamilcxxruntime_profile_32_head() {
451.3Skamil	atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
461.3Skamil	atf_set "require.progs" "c++"
471.3Skamil}
481.3Skamil
491.3Skamilatf_test_case cxxruntime_static
501.3Skamilcxxruntime_static_head() {
511.3Skamil	atf_set "descr" "compile and run \"hello world\" with static flags"
521.3Skamil	atf_set "require.progs" "c++"
531.3Skamil}
541.3Skamil
551.1Skamilatf_test_case cxxruntime_pic
561.1Skamilcxxruntime_pic_head() {
571.1Skamil	atf_set "descr" "compile and run PIC \"hello world\""
581.1Skamil	atf_set "require.progs" "c++"
591.1Skamil}
601.1Skamil
611.3Skamilatf_test_case cxxruntime_pic_32
621.3Skamilcxxruntime_pic_32_head() {
631.3Skamil	atf_set "descr" "compile and run 32-bit PIC \"hello world\""
641.3Skamil	atf_set "require.progs" "c++"
651.3Skamil}
661.3Skamil
671.3Skamilatf_test_case cxxruntime_pic_profile
681.3Skamilcxxruntime_pic_profile_head() {
691.3Skamil	atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
701.3Skamil	atf_set "require.progs" "c++"
711.3Skamil}
721.3Skamil
731.3Skamilatf_test_case cxxruntime_pic_profile_32
741.3Skamilcxxruntime_pic_profile_32_head() {
751.3Skamil	atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
761.3Skamil	atf_set "require.progs" "c++"
771.3Skamil}
781.3Skamil
791.1Skamilatf_test_case cxxruntime_pie
801.1Skamilcxxruntime_pie_head() {
811.1Skamil	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
821.1Skamil	atf_set "require.progs" "c++"
831.1Skamil}
841.1Skamil
851.1Skamilatf_test_case cxxruntime32
861.1Skamilcxxruntime32_head() {
871.1Skamil	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
881.1Skamil	atf_set "require.progs" "c++ file diff cat"
891.1Skamil}
901.1Skamil
911.1Skamilcxxruntime_body() {
921.1Skamil	cat > test.cpp << EOF
931.1Skamil#include <cstdlib>
941.1Skamil#include <iostream>
951.1Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
961.1SkamilEOF
971.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
981.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
991.1Skamil}
1001.1Skamil
1011.3Skamilcxxruntime_profile_body() {
1021.3Skamil	cat > test.cpp << EOF
1031.3Skamil#include <cstdlib>
1041.3Skamil#include <iostream>
1051.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
1061.3SkamilEOF
1071.3Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
1081.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1091.3Skamil}
1101.3Skamil
1111.3Skamilcxxruntime_profile_32_body() {
1121.3Skamil	# check whether this arch is 64bit
1131.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1141.3Skamil		atf_skip "this is not a 64 bit architecture"
1151.3Skamil	fi
1161.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1171.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1181.3Skamil	else
1191.3Skamil		if fgrep -q _LP64 ./def32; then
1201.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1211.3Skamil		fi
1221.3Skamil	fi
1231.3Skamil
1241.3Skamil	cat > test.cpp << EOF
1251.3Skamil#include <cstdlib>
1261.3Skamil#include <iostream>
1271.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
1281.3SkamilEOF
1291.3Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
1301.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1311.3Skamil}
1321.3Skamil
1331.3Skamilcxxruntime_static_body() {
1341.3Skamil	cat > test.cpp << EOF
1351.3Skamil#include <cstdlib>
1361.3Skamil#include <iostream>
1371.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
1381.3SkamilEOF
1391.3Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
1401.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1411.3Skamil}
1421.3Skamil
1431.1Skamilcxxruntime_pic_body() {
1441.1Skamil	cat > test.cpp << EOF
1451.1Skamil#include <cstdlib>
1461.1Skamilint callpic(void);
1471.1Skamilint main(void) {callpic();exit(0);}
1481.1SkamilEOF
1491.1Skamil	cat > pic.cpp << EOF
1501.1Skamil#include <iostream>
1511.1Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;}
1521.1SkamilEOF
1531.1Skamil
1541.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1551.1Skamil	    c++ -fPIC -shared -o libtest.so pic.cpp
1561.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1571.1Skamil	    c++ -o hello test.cpp -L. -ltest
1581.1Skamil
1591.1Skamil	export LD_LIBRARY_PATH=.
1601.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1611.1Skamil}
1621.1Skamil
1631.3Skamilcxxruntime_pic_32_body() {
1641.3Skamil	# check whether this arch is 64bit
1651.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1661.3Skamil		atf_skip "this is not a 64 bit architecture"
1671.3Skamil	fi
1681.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1691.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1701.3Skamil	else
1711.3Skamil		if fgrep -q _LP64 ./def32; then
1721.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1731.3Skamil		fi
1741.3Skamil	fi
1751.3Skamil
1761.3Skamil	cat > test.cpp << EOF
1771.3Skamil#include <cstdlib>
1781.3Skamilint callpic(void);
1791.3Skamilint main(void) {callpic();exit(0);}
1801.3SkamilEOF
1811.3Skamil	cat > pic.cpp << EOF
1821.3Skamil#include <iostream>
1831.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;}
1841.3SkamilEOF
1851.3Skamil
1861.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1871.3Skamil	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
1881.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1891.3Skamil	    c++ -m32 -o hello test.cpp -L. -ltest
1901.3Skamil
1911.3Skamil	export LD_LIBRARY_PATH=.
1921.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1931.3Skamil}
1941.3Skamil
1951.3Skamilcxxruntime_pic_profile_body() {
1961.3Skamil	cat > test.cpp << EOF
1971.3Skamil#include <cstdlib>
1981.3Skamilint callpic(void);
1991.3Skamilint main(void) {callpic();exit(0);}
2001.3SkamilEOF
2011.3Skamil	cat > pic.cpp << EOF
2021.3Skamil#include <iostream>
2031.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;}
2041.3SkamilEOF
2051.3Skamil
2061.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2071.3Skamil	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
2081.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2091.3Skamil	    c++ -pg -o hello test.cpp -L. -ltest
2101.3Skamil
2111.3Skamil	export LD_LIBRARY_PATH=.
2121.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2131.3Skamil}
2141.3Skamil
2151.3Skamilcxxruntime_pic_profile_32_body() {
2161.3Skamil	# check whether this arch is 64bit
2171.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2181.3Skamil		atf_skip "this is not a 64 bit architecture"
2191.3Skamil	fi
2201.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2211.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
2221.3Skamil	else
2231.3Skamil		if fgrep -q _LP64 ./def32; then
2241.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2251.3Skamil		fi
2261.3Skamil	fi
2271.3Skamil
2281.3Skamil	cat > test.cpp << EOF
2291.3Skamil#include <cstdlib>
2301.3Skamilint callpic(void);
2311.3Skamilint main(void) {callpic();exit(0);}
2321.3SkamilEOF
2331.3Skamil	cat > pic.cpp << EOF
2341.3Skamil#include <iostream>
2351.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;}
2361.3SkamilEOF
2371.3Skamil
2381.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2391.3Skamil	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
2401.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2411.3Skamil	    c++ -m32 -pg -o hello test.cpp -L. -ltest
2421.3Skamil
2431.3Skamil	export LD_LIBRARY_PATH=.
2441.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2451.3Skamil}
2461.3Skamil
2471.1Skamilcxxruntime_pie_body() {
2481.1Skamil	# check whether this arch supports -pie
2491.1Skamil	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
2501.1Skamil		atf_skip "c++ -pie not supported on this architecture"
2511.1Skamil	fi
2521.1Skamil	cat > test.cpp << EOF
2531.1Skamil#include <cstdlib>
2541.1Skamil#include <iostream>
2551.1Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
2561.1SkamilEOF
2571.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
2581.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2591.1Skamil}
2601.1Skamil
2611.1Skamilcxxruntime32_body() {
2621.1Skamil	# check whether this arch is 64bit
2631.1Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2641.1Skamil		atf_skip "this is not a 64 bit architecture"
2651.1Skamil	fi
2661.1Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2671.1Skamil		atf_skip "c++ -m32 not supported on this architecture"
2681.1Skamil	else
2691.1Skamil		if fgrep -q _LP64 ./def32; then
2701.1Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2711.1Skamil		fi
2721.1Skamil	fi
2731.1Skamil
2741.1Skamil	cat > test.cpp << EOF
2751.2Skamil#include <cstdlib>
2761.2Skamil#include <iostream>
2771.2Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);}
2781.1SkamilEOF
2791.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
2801.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
2811.1Skamil	file -b ./hello32 > ./ftype32
2821.1Skamil	file -b ./hello64 > ./ftype64
2831.1Skamil	if diff ./ftype32 ./ftype64 >/dev/null; then
2841.1Skamil		atf_fail "generated binaries do not differ"
2851.1Skamil	fi
2861.1Skamil	echo "32bit binaries on this platform are:"
2871.1Skamil	cat ./ftype32
2881.1Skamil	echo "While native (64bit) binaries are:"
2891.1Skamil	cat ./ftype64
2901.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
2911.1Skamil
2921.1Skamil	# do another test with static 32bit binaries
2931.1Skamil	cat > test.cpp << EOF
2941.2Skamil#include <cstdlib>
2951.1Skamil#include <iostream>
2961.1Skamilint main(void) {std::cout << "hello static world" << std::endl;exit(0);}
2971.1SkamilEOF
2981.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
2991.1Skamil	    -static test.cpp
3001.1Skamil	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
3011.1Skamil}
3021.1Skamil
3031.1Skamilatf_init_test_cases()
3041.1Skamil{
3051.1Skamil	atf_add_test_case cxxruntime
3061.3Skamil	atf_add_test_case cxxruntime_profile
3071.1Skamil	atf_add_test_case cxxruntime_pic
3081.1Skamil	atf_add_test_case cxxruntime_pie
3091.1Skamil	atf_add_test_case cxxruntime32
3101.3Skamil	atf_add_test_case cxxruntime_static
3111.3Skamil	atf_add_test_case cxxruntime_pic_32
3121.3Skamil	atf_add_test_case cxxruntime_pic_profile
3131.3Skamil	atf_add_test_case cxxruntime_pic_profile_32
3141.3Skamil	atf_add_test_case cxxruntime_profile_32
3151.1Skamil}
316