t_cxxruntime.sh revision 1.2
11.2Skamil# $NetBSD: t_cxxruntime.sh,v 1.2 2017/05/14 01:13:44 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.1Skamilatf_test_case cxxruntime_pic 381.1Skamilcxxruntime_pic_head() { 391.1Skamil atf_set "descr" "compile and run PIC \"hello world\"" 401.1Skamil atf_set "require.progs" "c++" 411.1Skamil} 421.1Skamil 431.1Skamilatf_test_case cxxruntime_pie 441.1Skamilcxxruntime_pie_head() { 451.1Skamil atf_set "descr" "compile and run position independent (PIE) \"hello world\"" 461.1Skamil atf_set "require.progs" "c++" 471.1Skamil} 481.1Skamil 491.1Skamilatf_test_case cxxruntime32 501.1Skamilcxxruntime32_head() { 511.1Skamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation" 521.1Skamil atf_set "require.progs" "c++ file diff cat" 531.1Skamil} 541.1Skamil 551.1Skamilcxxruntime_body() { 561.1Skamil cat > test.cpp << EOF 571.1Skamil#include <cstdlib> 581.1Skamil#include <iostream> 591.1Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 601.1SkamilEOF 611.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp 621.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 631.1Skamil} 641.1Skamil 651.1Skamilcxxruntime_pic_body() { 661.1Skamil cat > test.cpp << EOF 671.1Skamil#include <cstdlib> 681.1Skamilint callpic(void); 691.1Skamilint main(void) {callpic();exit(0);} 701.1SkamilEOF 711.1Skamil cat > pic.cpp << EOF 721.1Skamil#include <iostream> 731.1Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 741.1SkamilEOF 751.1Skamil 761.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 771.1Skamil c++ -fPIC -shared -o libtest.so pic.cpp 781.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 791.1Skamil c++ -o hello test.cpp -L. -ltest 801.1Skamil 811.1Skamil export LD_LIBRARY_PATH=. 821.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 831.1Skamil} 841.1Skamil 851.1Skamilcxxruntime_pie_body() { 861.1Skamil # check whether this arch supports -pie 871.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 881.1Skamil atf_skip "c++ -pie not supported on this architecture" 891.1Skamil fi 901.1Skamil cat > test.cpp << EOF 911.1Skamil#include <cstdlib> 921.1Skamil#include <iostream> 931.1Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 941.1SkamilEOF 951.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp 961.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 971.1Skamil} 981.1Skamil 991.1Skamilcxxruntime32_body() { 1001.1Skamil # check whether this arch is 64bit 1011.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1021.1Skamil atf_skip "this is not a 64 bit architecture" 1031.1Skamil fi 1041.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1051.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1061.1Skamil else 1071.1Skamil if fgrep -q _LP64 ./def32; then 1081.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1091.1Skamil fi 1101.1Skamil fi 1111.1Skamil 1121.1Skamil cat > test.cpp << EOF 1131.2Skamil#include <cstdlib> 1141.2Skamil#include <iostream> 1151.2Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 1161.1SkamilEOF 1171.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp 1181.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp 1191.1Skamil file -b ./hello32 > ./ftype32 1201.1Skamil file -b ./hello64 > ./ftype64 1211.1Skamil if diff ./ftype32 ./ftype64 >/dev/null; then 1221.1Skamil atf_fail "generated binaries do not differ" 1231.1Skamil fi 1241.1Skamil echo "32bit binaries on this platform are:" 1251.1Skamil cat ./ftype32 1261.1Skamil echo "While native (64bit) binaries are:" 1271.1Skamil cat ./ftype64 1281.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32 1291.1Skamil 1301.1Skamil # do another test with static 32bit binaries 1311.1Skamil cat > test.cpp << EOF 1321.2Skamil#include <cstdlib> 1331.1Skamil#include <iostream> 1341.1Skamilint main(void) {std::cout << "hello static world" << std::endl;exit(0);} 1351.1SkamilEOF 1361.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \ 1371.1Skamil -static test.cpp 1381.1Skamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello 1391.1Skamil} 1401.1Skamil 1411.1Skamilatf_init_test_cases() 1421.1Skamil{ 1431.1Skamil 1441.1Skamil atf_add_test_case cxxruntime 1451.1Skamil atf_add_test_case cxxruntime_pic 1461.1Skamil atf_add_test_case cxxruntime_pie 1471.1Skamil atf_add_test_case cxxruntime32 1481.1Skamil} 149