t_cxxruntime.sh revision 1.8
11.8Sriastrad# $NetBSD: t_cxxruntime.sh,v 1.8 2025/04/16 01:52:42 riastradh 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.8Sriastrad case `uname -m` in 1031.8Sriastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 1041.8Sriastrad " riscv: missing MKPROFILE=yes support" 1051.8Sriastrad ;; 1061.8Sriastrad esac 1071.8Sriastrad 1081.3Skamil cat > test.cpp << EOF 1091.3Skamil#include <cstdlib> 1101.3Skamil#include <iostream> 1111.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 1121.3SkamilEOF 1131.7Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp 1141.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 1151.3Skamil} 1161.3Skamil 1171.3Skamilcxxruntime_profile_32_body() { 1181.3Skamil # check whether this arch is 64bit 1191.3Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1201.3Skamil atf_skip "this is not a 64 bit architecture" 1211.3Skamil fi 1221.3Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1231.3Skamil atf_skip "c++ -m32 not supported on this architecture" 1241.3Skamil else 1251.3Skamil if fgrep -q _LP64 ./def32; then 1261.3Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1271.3Skamil fi 1281.3Skamil fi 1291.3Skamil 1301.8Sriastrad case `uname -m` in 1311.8Sriastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 1321.8Sriastrad " riscv: missing MKPROFILE=yes support" 1331.8Sriastrad ;; 1341.8Sriastrad esac 1351.8Sriastrad 1361.3Skamil cat > test.cpp << EOF 1371.3Skamil#include <cstdlib> 1381.3Skamil#include <iostream> 1391.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 1401.3SkamilEOF 1411.7Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -m32 -pg -o hello test.cpp 1421.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 1431.3Skamil} 1441.3Skamil 1451.3Skamilcxxruntime_static_body() { 1461.3Skamil cat > test.cpp << EOF 1471.3Skamil#include <cstdlib> 1481.3Skamil#include <iostream> 1491.3Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 1501.3SkamilEOF 1511.3Skamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp 1521.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 1531.3Skamil} 1541.3Skamil 1551.1Skamilcxxruntime_pic_body() { 1561.1Skamil cat > test.cpp << EOF 1571.1Skamil#include <cstdlib> 1581.1Skamilint callpic(void); 1591.1Skamilint main(void) {callpic();exit(0);} 1601.1SkamilEOF 1611.1Skamil cat > pic.cpp << EOF 1621.1Skamil#include <iostream> 1631.1Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 1641.1SkamilEOF 1651.1Skamil 1661.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1671.1Skamil c++ -fPIC -shared -o libtest.so pic.cpp 1681.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1691.1Skamil c++ -o hello test.cpp -L. -ltest 1701.1Skamil 1711.1Skamil export LD_LIBRARY_PATH=. 1721.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 1731.1Skamil} 1741.1Skamil 1751.3Skamilcxxruntime_pic_32_body() { 1761.3Skamil # check whether this arch is 64bit 1771.3Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1781.3Skamil atf_skip "this is not a 64 bit architecture" 1791.3Skamil fi 1801.3Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1811.3Skamil atf_skip "c++ -m32 not supported on this architecture" 1821.3Skamil else 1831.3Skamil if fgrep -q _LP64 ./def32; then 1841.3Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1851.3Skamil fi 1861.3Skamil fi 1871.3Skamil 1881.3Skamil cat > test.cpp << EOF 1891.3Skamil#include <cstdlib> 1901.3Skamilint callpic(void); 1911.3Skamilint main(void) {callpic();exit(0);} 1921.3SkamilEOF 1931.3Skamil cat > pic.cpp << EOF 1941.3Skamil#include <iostream> 1951.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 1961.3SkamilEOF 1971.3Skamil 1981.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 1991.3Skamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp 2001.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 2011.3Skamil c++ -m32 -o hello test.cpp -L. -ltest 2021.3Skamil 2031.3Skamil export LD_LIBRARY_PATH=. 2041.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 2051.3Skamil} 2061.3Skamil 2071.3Skamilcxxruntime_pic_profile_body() { 2081.8Sriastrad case `uname -m` in 2091.8Sriastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 2101.8Sriastrad " riscv: missing MKPROFILE=yes support" 2111.8Sriastrad ;; 2121.8Sriastrad esac 2131.8Sriastrad 2141.3Skamil cat > test.cpp << EOF 2151.3Skamil#include <cstdlib> 2161.3Skamilint callpic(void); 2171.3Skamilint main(void) {callpic();exit(0);} 2181.3SkamilEOF 2191.3Skamil cat > pic.cpp << EOF 2201.3Skamil#include <iostream> 2211.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 2221.3SkamilEOF 2231.3Skamil 2241.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 2251.3Skamil c++ -pg -fPIC -shared -o libtest.so pic.cpp 2261.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 2271.3Skamil c++ -pg -o hello test.cpp -L. -ltest 2281.3Skamil 2291.3Skamil export LD_LIBRARY_PATH=. 2301.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 2311.3Skamil} 2321.3Skamil 2331.3Skamilcxxruntime_pic_profile_32_body() { 2341.3Skamil # check whether this arch is 64bit 2351.3Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2361.3Skamil atf_skip "this is not a 64 bit architecture" 2371.3Skamil fi 2381.3Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2391.3Skamil atf_skip "c++ -m32 not supported on this architecture" 2401.3Skamil else 2411.3Skamil if fgrep -q _LP64 ./def32; then 2421.3Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 2431.3Skamil fi 2441.3Skamil fi 2451.3Skamil 2461.8Sriastrad case `uname -m` in 2471.8Sriastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 2481.8Sriastrad " riscv: missing MKPROFILE=yes support" 2491.8Sriastrad ;; 2501.8Sriastrad esac 2511.8Sriastrad 2521.3Skamil cat > test.cpp << EOF 2531.3Skamil#include <cstdlib> 2541.3Skamilint callpic(void); 2551.3Skamilint main(void) {callpic();exit(0);} 2561.3SkamilEOF 2571.3Skamil cat > pic.cpp << EOF 2581.3Skamil#include <iostream> 2591.3Skamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 2601.3SkamilEOF 2611.3Skamil 2621.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 2631.3Skamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp 2641.3Skamil atf_check -s exit:0 -o ignore -e ignore \ 2651.3Skamil c++ -m32 -pg -o hello test.cpp -L. -ltest 2661.3Skamil 2671.3Skamil export LD_LIBRARY_PATH=. 2681.3Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 2691.3Skamil} 2701.3Skamil 2711.1Skamilcxxruntime_pie_body() { 2721.1Skamil # check whether this arch supports -pie 2731.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 2741.1Skamil atf_skip "c++ -pie not supported on this architecture" 2751.1Skamil fi 2761.1Skamil cat > test.cpp << EOF 2771.1Skamil#include <cstdlib> 2781.1Skamil#include <iostream> 2791.1Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 2801.1SkamilEOF 2811.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp 2821.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 2831.1Skamil} 2841.1Skamil 2851.1Skamilcxxruntime32_body() { 2861.1Skamil # check whether this arch is 64bit 2871.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2881.1Skamil atf_skip "this is not a 64 bit architecture" 2891.1Skamil fi 2901.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2911.1Skamil atf_skip "c++ -m32 not supported on this architecture" 2921.1Skamil else 2931.1Skamil if fgrep -q _LP64 ./def32; then 2941.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 2951.1Skamil fi 2961.1Skamil fi 2971.1Skamil 2981.1Skamil cat > test.cpp << EOF 2991.2Skamil#include <cstdlib> 3001.2Skamil#include <iostream> 3011.2Skamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 3021.1SkamilEOF 3031.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp 3041.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp 3051.1Skamil file -b ./hello32 > ./ftype32 3061.1Skamil file -b ./hello64 > ./ftype64 3071.1Skamil if diff ./ftype32 ./ftype64 >/dev/null; then 3081.1Skamil atf_fail "generated binaries do not differ" 3091.1Skamil fi 3101.1Skamil echo "32bit binaries on this platform are:" 3111.1Skamil cat ./ftype32 3121.1Skamil echo "While native (64bit) binaries are:" 3131.1Skamil cat ./ftype64 3141.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32 3151.1Skamil 3161.1Skamil # do another test with static 32bit binaries 3171.1Skamil cat > test.cpp << EOF 3181.2Skamil#include <cstdlib> 3191.1Skamil#include <iostream> 3201.1Skamilint main(void) {std::cout << "hello static world" << std::endl;exit(0);} 3211.1SkamilEOF 3221.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \ 3231.1Skamil -static test.cpp 3241.1Skamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello 3251.1Skamil} 3261.1Skamil 3271.1Skamilatf_init_test_cases() 3281.1Skamil{ 3291.1Skamil atf_add_test_case cxxruntime 3301.3Skamil atf_add_test_case cxxruntime_profile 3311.1Skamil atf_add_test_case cxxruntime_pic 3321.1Skamil atf_add_test_case cxxruntime_pie 3331.1Skamil atf_add_test_case cxxruntime32 3341.3Skamil atf_add_test_case cxxruntime_static 3351.3Skamil atf_add_test_case cxxruntime_pic_32 3361.3Skamil atf_add_test_case cxxruntime_pic_profile 3371.3Skamil atf_add_test_case cxxruntime_pic_profile_32 3381.3Skamil atf_add_test_case cxxruntime_profile_32 3391.1Skamil} 340