1*ac615257Sskrll# $NetBSD: t_cxxruntime.sh,v 1.7 2022/06/12 15:08:38 skrll Exp $ 29fab767dSkamil# 39fab767dSkamil# Copyright (c) 2017 The NetBSD Foundation, Inc. 49fab767dSkamil# All rights reserved. 59fab767dSkamil# 69fab767dSkamil# This code is derived from software contributed to The NetBSD Foundation 79fab767dSkamil# by Kamil Rytarowski. 89fab767dSkamil# 99fab767dSkamil# Redistribution and use in source and binary forms, with or without 109fab767dSkamil# modification, are permitted provided that the following conditions 119fab767dSkamil# are met: 129fab767dSkamil# 1. Redistributions of source code must retain the above copyright 139fab767dSkamil# notice, this list of conditions and the following disclaimer. 149fab767dSkamil# 2. Redistributions in binary form must reproduce the above copyright 159fab767dSkamil# notice, this list of conditions and the following disclaimer in the 169fab767dSkamil# documentation and/or other materials provided with the distribution. 179fab767dSkamil# 189fab767dSkamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 199fab767dSkamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 209fab767dSkamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 219fab767dSkamil# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 229fab767dSkamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 239fab767dSkamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 249fab767dSkamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 259fab767dSkamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 269fab767dSkamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 279fab767dSkamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 289fab767dSkamil# POSSIBILITY OF SUCH DAMAGE. 299fab767dSkamil# 309fab767dSkamil 319fab767dSkamilatf_test_case cxxruntime 329fab767dSkamilcxxruntime_head() { 339fab767dSkamil atf_set "descr" "compile and run \"hello world\"" 349fab767dSkamil atf_set "require.progs" "c++" 359fab767dSkamil} 369fab767dSkamil 3777dc83faSkamilatf_test_case cxxruntime_profile 3877dc83faSkamilcxxruntime_profile_head() { 3977dc83faSkamil atf_set "descr" "compile and run \"hello world\" with profiling option" 4077dc83faSkamil atf_set "require.progs" "c++" 4177dc83faSkamil} 4277dc83faSkamil 4377dc83faSkamilatf_test_case cxxruntime_profile_32 4477dc83faSkamilcxxruntime_profile_32_head() { 4577dc83faSkamil atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option" 4677dc83faSkamil atf_set "require.progs" "c++" 4777dc83faSkamil} 4877dc83faSkamil 4977dc83faSkamilatf_test_case cxxruntime_static 5077dc83faSkamilcxxruntime_static_head() { 5177dc83faSkamil atf_set "descr" "compile and run \"hello world\" with static flags" 5277dc83faSkamil atf_set "require.progs" "c++" 5377dc83faSkamil} 5477dc83faSkamil 559fab767dSkamilatf_test_case cxxruntime_pic 569fab767dSkamilcxxruntime_pic_head() { 579fab767dSkamil atf_set "descr" "compile and run PIC \"hello world\"" 589fab767dSkamil atf_set "require.progs" "c++" 599fab767dSkamil} 609fab767dSkamil 6177dc83faSkamilatf_test_case cxxruntime_pic_32 6277dc83faSkamilcxxruntime_pic_32_head() { 6377dc83faSkamil atf_set "descr" "compile and run 32-bit PIC \"hello world\"" 6477dc83faSkamil atf_set "require.progs" "c++" 6577dc83faSkamil} 6677dc83faSkamil 6777dc83faSkamilatf_test_case cxxruntime_pic_profile 6877dc83faSkamilcxxruntime_pic_profile_head() { 6977dc83faSkamil atf_set "descr" "compile and run PIC \"hello world\" with profiling option" 7077dc83faSkamil atf_set "require.progs" "c++" 7177dc83faSkamil} 7277dc83faSkamil 7377dc83faSkamilatf_test_case cxxruntime_pic_profile_32 7477dc83faSkamilcxxruntime_pic_profile_32_head() { 7577dc83faSkamil atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option" 7677dc83faSkamil atf_set "require.progs" "c++" 7777dc83faSkamil} 7877dc83faSkamil 799fab767dSkamilatf_test_case cxxruntime_pie 809fab767dSkamilcxxruntime_pie_head() { 819fab767dSkamil atf_set "descr" "compile and run position independent (PIE) \"hello world\"" 829fab767dSkamil atf_set "require.progs" "c++" 839fab767dSkamil} 849fab767dSkamil 859fab767dSkamilatf_test_case cxxruntime32 869fab767dSkamilcxxruntime32_head() { 879fab767dSkamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation" 889fab767dSkamil atf_set "require.progs" "c++ file diff cat" 899fab767dSkamil} 909fab767dSkamil 919fab767dSkamilcxxruntime_body() { 929fab767dSkamil cat > test.cpp << EOF 939fab767dSkamil#include <cstdlib> 949fab767dSkamil#include <iostream> 959fab767dSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 969fab767dSkamilEOF 979fab767dSkamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp 989fab767dSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 999fab767dSkamil} 1009fab767dSkamil 10177dc83faSkamilcxxruntime_profile_body() { 10277dc83faSkamil cat > test.cpp << EOF 10377dc83faSkamil#include <cstdlib> 10477dc83faSkamil#include <iostream> 10577dc83faSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 10677dc83faSkamilEOF 107*ac615257Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp 10877dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 10977dc83faSkamil} 11077dc83faSkamil 11177dc83faSkamilcxxruntime_profile_32_body() { 11277dc83faSkamil # check whether this arch is 64bit 11377dc83faSkamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 11477dc83faSkamil atf_skip "this is not a 64 bit architecture" 11577dc83faSkamil fi 11677dc83faSkamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 11777dc83faSkamil atf_skip "c++ -m32 not supported on this architecture" 11877dc83faSkamil else 11977dc83faSkamil if fgrep -q _LP64 ./def32; then 12077dc83faSkamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 12177dc83faSkamil fi 12277dc83faSkamil fi 12377dc83faSkamil 12477dc83faSkamil cat > test.cpp << EOF 12577dc83faSkamil#include <cstdlib> 12677dc83faSkamil#include <iostream> 12777dc83faSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 12877dc83faSkamilEOF 129*ac615257Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -m32 -pg -o hello test.cpp 13077dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 13177dc83faSkamil} 13277dc83faSkamil 13377dc83faSkamilcxxruntime_static_body() { 13477dc83faSkamil cat > test.cpp << EOF 13577dc83faSkamil#include <cstdlib> 13677dc83faSkamil#include <iostream> 13777dc83faSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 13877dc83faSkamilEOF 13977dc83faSkamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp 14077dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 14177dc83faSkamil} 14277dc83faSkamil 1439fab767dSkamilcxxruntime_pic_body() { 1449fab767dSkamil cat > test.cpp << EOF 1459fab767dSkamil#include <cstdlib> 1469fab767dSkamilint callpic(void); 1479fab767dSkamilint main(void) {callpic();exit(0);} 1489fab767dSkamilEOF 1499fab767dSkamil cat > pic.cpp << EOF 1509fab767dSkamil#include <iostream> 1519fab767dSkamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 1529fab767dSkamilEOF 1539fab767dSkamil 1549fab767dSkamil atf_check -s exit:0 -o ignore -e ignore \ 1559fab767dSkamil c++ -fPIC -shared -o libtest.so pic.cpp 1569fab767dSkamil atf_check -s exit:0 -o ignore -e ignore \ 1579fab767dSkamil c++ -o hello test.cpp -L. -ltest 1589fab767dSkamil 1599fab767dSkamil export LD_LIBRARY_PATH=. 1609fab767dSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 1619fab767dSkamil} 1629fab767dSkamil 16377dc83faSkamilcxxruntime_pic_32_body() { 16477dc83faSkamil # check whether this arch is 64bit 16577dc83faSkamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 16677dc83faSkamil atf_skip "this is not a 64 bit architecture" 16777dc83faSkamil fi 16877dc83faSkamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 16977dc83faSkamil atf_skip "c++ -m32 not supported on this architecture" 17077dc83faSkamil else 17177dc83faSkamil if fgrep -q _LP64 ./def32; then 17277dc83faSkamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 17377dc83faSkamil fi 17477dc83faSkamil fi 17577dc83faSkamil 17677dc83faSkamil cat > test.cpp << EOF 17777dc83faSkamil#include <cstdlib> 17877dc83faSkamilint callpic(void); 17977dc83faSkamilint main(void) {callpic();exit(0);} 18077dc83faSkamilEOF 18177dc83faSkamil cat > pic.cpp << EOF 18277dc83faSkamil#include <iostream> 18377dc83faSkamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 18477dc83faSkamilEOF 18577dc83faSkamil 18677dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 18777dc83faSkamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp 18877dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 18977dc83faSkamil c++ -m32 -o hello test.cpp -L. -ltest 19077dc83faSkamil 19177dc83faSkamil export LD_LIBRARY_PATH=. 19277dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 19377dc83faSkamil} 19477dc83faSkamil 19577dc83faSkamilcxxruntime_pic_profile_body() { 19677dc83faSkamil cat > test.cpp << EOF 19777dc83faSkamil#include <cstdlib> 19877dc83faSkamilint callpic(void); 19977dc83faSkamilint main(void) {callpic();exit(0);} 20077dc83faSkamilEOF 20177dc83faSkamil cat > pic.cpp << EOF 20277dc83faSkamil#include <iostream> 20377dc83faSkamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 20477dc83faSkamilEOF 20577dc83faSkamil 20677dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 20777dc83faSkamil c++ -pg -fPIC -shared -o libtest.so pic.cpp 20877dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 20977dc83faSkamil c++ -pg -o hello test.cpp -L. -ltest 21077dc83faSkamil 21177dc83faSkamil export LD_LIBRARY_PATH=. 21277dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 21377dc83faSkamil} 21477dc83faSkamil 21577dc83faSkamilcxxruntime_pic_profile_32_body() { 21677dc83faSkamil # check whether this arch is 64bit 21777dc83faSkamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 21877dc83faSkamil atf_skip "this is not a 64 bit architecture" 21977dc83faSkamil fi 22077dc83faSkamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 22177dc83faSkamil atf_skip "c++ -m32 not supported on this architecture" 22277dc83faSkamil else 22377dc83faSkamil if fgrep -q _LP64 ./def32; then 22477dc83faSkamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 22577dc83faSkamil fi 22677dc83faSkamil fi 22777dc83faSkamil 22877dc83faSkamil cat > test.cpp << EOF 22977dc83faSkamil#include <cstdlib> 23077dc83faSkamilint callpic(void); 23177dc83faSkamilint main(void) {callpic();exit(0);} 23277dc83faSkamilEOF 23377dc83faSkamil cat > pic.cpp << EOF 23477dc83faSkamil#include <iostream> 23577dc83faSkamilint callpic(void) {std::cout << "hello world" << std::endl;return 0;} 23677dc83faSkamilEOF 23777dc83faSkamil 23877dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 23977dc83faSkamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp 24077dc83faSkamil atf_check -s exit:0 -o ignore -e ignore \ 24177dc83faSkamil c++ -m32 -pg -o hello test.cpp -L. -ltest 24277dc83faSkamil 24377dc83faSkamil export LD_LIBRARY_PATH=. 24477dc83faSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 24577dc83faSkamil} 24677dc83faSkamil 2479fab767dSkamilcxxruntime_pie_body() { 2489fab767dSkamil # check whether this arch supports -pie 2499fab767dSkamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 2509fab767dSkamil atf_skip "c++ -pie not supported on this architecture" 2519fab767dSkamil fi 2529fab767dSkamil cat > test.cpp << EOF 2539fab767dSkamil#include <cstdlib> 2549fab767dSkamil#include <iostream> 2559fab767dSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 2569fab767dSkamilEOF 2579fab767dSkamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp 2589fab767dSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 2599fab767dSkamil} 2609fab767dSkamil 2619fab767dSkamilcxxruntime32_body() { 2629fab767dSkamil # check whether this arch is 64bit 2639fab767dSkamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2649fab767dSkamil atf_skip "this is not a 64 bit architecture" 2659fab767dSkamil fi 2669fab767dSkamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2679fab767dSkamil atf_skip "c++ -m32 not supported on this architecture" 2689fab767dSkamil else 2699fab767dSkamil if fgrep -q _LP64 ./def32; then 2709fab767dSkamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 2719fab767dSkamil fi 2729fab767dSkamil fi 2739fab767dSkamil 2749fab767dSkamil cat > test.cpp << EOF 275179f19cfSkamil#include <cstdlib> 276179f19cfSkamil#include <iostream> 277179f19cfSkamilint main(void) {std::cout << "hello world" << std::endl;exit(0);} 2789fab767dSkamilEOF 2799fab767dSkamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp 2809fab767dSkamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp 2819fab767dSkamil file -b ./hello32 > ./ftype32 2829fab767dSkamil file -b ./hello64 > ./ftype64 2839fab767dSkamil if diff ./ftype32 ./ftype64 >/dev/null; then 2849fab767dSkamil atf_fail "generated binaries do not differ" 2859fab767dSkamil fi 2869fab767dSkamil echo "32bit binaries on this platform are:" 2879fab767dSkamil cat ./ftype32 2889fab767dSkamil echo "While native (64bit) binaries are:" 2899fab767dSkamil cat ./ftype64 2909fab767dSkamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32 2919fab767dSkamil 2929fab767dSkamil # do another test with static 32bit binaries 2939fab767dSkamil cat > test.cpp << EOF 2949fab767dSkamil#include <cstdlib> 295179f19cfSkamil#include <iostream> 2969fab767dSkamilint main(void) {std::cout << "hello static world" << std::endl;exit(0);} 2979fab767dSkamilEOF 2989fab767dSkamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \ 2999fab767dSkamil -static test.cpp 3009fab767dSkamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello 3019fab767dSkamil} 3029fab767dSkamil 3039fab767dSkamilatf_init_test_cases() 3049fab767dSkamil{ 3059fab767dSkamil atf_add_test_case cxxruntime 30677dc83faSkamil atf_add_test_case cxxruntime_profile 3079fab767dSkamil atf_add_test_case cxxruntime_pic 3089fab767dSkamil atf_add_test_case cxxruntime_pie 3099fab767dSkamil atf_add_test_case cxxruntime32 31077dc83faSkamil atf_add_test_case cxxruntime_static 31177dc83faSkamil atf_add_test_case cxxruntime_pic_32 31277dc83faSkamil atf_add_test_case cxxruntime_pic_profile 31377dc83faSkamil atf_add_test_case cxxruntime_pic_profile_32 31477dc83faSkamil atf_add_test_case cxxruntime_profile_32 3159fab767dSkamil} 316