t_call_once.sh revision 1.6
11.6Sskrll# $NetBSD: t_call_once.sh,v 1.6 2022/06/12 15:08:38 skrll Exp $ 21.1Skamil# 31.1Skamil# Copyright (c) 2018 The NetBSD Foundation, Inc. 41.1Skamil# All rights reserved. 51.1Skamil# 61.1Skamil# Redistribution and use in source and binary forms, with or without 71.1Skamil# modification, are permitted provided that the following conditions 81.1Skamil# are met: 91.1Skamil# 1. Redistributions of source code must retain the above copyright 101.1Skamil# notice, this list of conditions and the following disclaimer. 111.1Skamil# 2. Redistributions in binary form must reproduce the above copyright 121.1Skamil# notice, this list of conditions and the following disclaimer in the 131.1Skamil# documentation and/or other materials provided with the distribution. 141.1Skamil# 151.1Skamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 161.1Skamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Skamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Skamil# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 191.1Skamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Skamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Skamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Skamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Skamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Skamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Skamil# POSSIBILITY OF SUCH DAMAGE. 261.1Skamil# 271.1Skamil 281.1Skamilatf_test_case call_once 291.1Skamilcall_once_head() { 301.1Skamil atf_set "descr" "compile and run std::call_once" 311.1Skamil atf_set "require.progs" "c++" 321.1Skamil} 331.1Skamil 341.1Skamilatf_test_case call_once_profile 351.1Skamilcall_once_profile_head() { 361.1Skamil atf_set "descr" "compile and run std::call_once with profiling option" 371.1Skamil atf_set "require.progs" "c++" 381.1Skamil} 391.1Skamil 401.1Skamilatf_test_case call_once_pic 411.1Skamilcall_once_pic_head() { 421.1Skamil atf_set "descr" "compile and run PIC std::call_once" 431.1Skamil atf_set "require.progs" "c++" 441.1Skamil} 451.1Skamil 461.1Skamilatf_test_case call_once_pic_32 471.1Skamilcall_once_pic_32_head() { 481.1Skamil atf_set "descr" "compile and run 32-bit PIC std::call_once" 491.1Skamil atf_set "require.progs" "c++" 501.1Skamil} 511.1Skamil 521.1Skamilatf_test_case call_once_pic_profile 531.1Skamilcall_once_pic_head() { 541.1Skamil atf_set "descr" "compile and run PIC std::call_once with profiling flag" 551.1Skamil atf_set "require.progs" "c++" 561.1Skamil} 571.1Skamil 581.1Skamilatf_test_case call_once_pic_profile_32 591.1Skamilcall_once_pic_profile_32_head() { 601.1Skamil atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag" 611.1Skamil atf_set "require.progs" "c++" 621.1Skamil} 631.1Skamil 641.1Skamilatf_test_case call_once_profile_32 651.1Skamilcall_once_profile_32_head() { 661.1Skamil atf_set "descr" "compile and run 32-bit std::call_once with profiling flag" 671.1Skamil atf_set "require.progs" "c++" 681.1Skamil} 691.1Skamil 701.1Skamilatf_test_case call_once_pie 711.1Skamilcall_once_pie_head() { 721.1Skamil atf_set "descr" "compile and run position independent (PIE) std::call_once" 731.1Skamil atf_set "require.progs" "c++" 741.1Skamil} 751.1Skamil 761.1Skamilatf_test_case call_once_32 771.1Skamilcall_once_32_head() { 781.1Skamil atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation" 791.1Skamil atf_set "require.progs" "c++ file diff cat" 801.1Skamil} 811.1Skamil 821.1Skamilatf_test_case call_once_static 831.1Skamilcall_once_static_head() { 841.1Skamil atf_set "descr" "compile and run std::call_once with static flag" 851.1Skamil atf_set "require.progs" "c++" 861.1Skamil} 871.1Skamil 881.1Skamilcall_once_body() { 891.1Skamil cat > test.cpp << EOF 901.1Skamil#include <cstdio> 911.1Skamil#include <thread> 921.1Skamil#include <mutex> 931.1Skamilstd::once_flag flag; 941.1Skamilint main(void) { 951.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 961.1Skamil return 0; 971.1Skamil} 981.1SkamilEOF 991.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once test.cpp -pthread 1001.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1011.1Skamil} 1021.1Skamil 1031.1Skamilcall_once_profile_body() { 1041.1Skamil cat > test.cpp << EOF 1051.1Skamil#include <cstdio> 1061.1Skamil#include <thread> 1071.1Skamil#include <mutex> 1081.1Skamilstd::once_flag flag; 1091.1Skamilint main(void) { 1101.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1111.1Skamil return 0; 1121.1Skamil} 1131.1SkamilEOF 1141.6Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o call_once test.cpp -pthread 1151.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1161.1Skamil} 1171.1Skamil 1181.1Skamilcall_once_profile_32_body() { 1191.1Skamil # check whether this arch is 64bit 1201.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1211.1Skamil atf_skip "this is not a 64 bit architecture" 1221.1Skamil fi 1231.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1241.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1251.1Skamil else 1261.1Skamil if fgrep -q _LP64 ./def32; then 1271.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1281.1Skamil fi 1291.1Skamil fi 1301.1Skamil 1311.1Skamil cat > test.cpp << EOF 1321.1Skamil#include <cstdio> 1331.1Skamil#include <thread> 1341.1Skamil#include <mutex> 1351.1Skamilstd::once_flag flag; 1361.1Skamilint main(void) { 1371.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1381.1Skamil return 0; 1391.1Skamil} 1401.1SkamilEOF 1411.6Sskrll atf_check -s exit:0 -o ignore -e ignore c++ -static -m32 -pg -o call_once test.cpp -pthread 1421.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1431.1Skamil} 1441.1Skamil 1451.1Skamilcall_once_pic_body() { 1461.1Skamil cat > test.cpp << EOF 1471.1Skamil#include <stdlib.h> 1481.1Skamilint callpic(void); 1491.1Skamilint main(void) {callpic();exit(0);} 1501.1SkamilEOF 1511.1Skamil cat > pic.cpp << EOF 1521.1Skamil#include <cstdio> 1531.1Skamil#include <thread> 1541.1Skamil#include <mutex> 1551.1Skamilstd::once_flag flag; 1561.1Skamilint callpic(void) { 1571.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1581.1Skamil return 0; 1591.1Skamil} 1601.1SkamilEOF 1611.1Skamil 1621.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1631.1Skamil c++ -fPIC -shared -o libtest.so pic.cpp 1641.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1651.1Skamil c++ -o call_once test.cpp -L. -ltest -pthread 1661.1Skamil 1671.1Skamil export LD_LIBRARY_PATH=. 1681.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1691.1Skamil} 1701.1Skamil 1711.1Skamilcall_once_pic_32_body() { 1721.1Skamil # check whether this arch is 64bit 1731.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1741.1Skamil atf_skip "this is not a 64 bit architecture" 1751.1Skamil fi 1761.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1771.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1781.1Skamil else 1791.1Skamil if fgrep -q _LP64 ./def32; then 1801.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1811.1Skamil fi 1821.1Skamil fi 1831.1Skamil 1841.1Skamil cat > test.cpp << EOF 1851.1Skamil#include <stdlib.h> 1861.1Skamilint callpic(void); 1871.1Skamilint main(void) {callpic();exit(0);} 1881.1SkamilEOF 1891.1Skamil cat > pic.cpp << EOF 1901.1Skamil#include <cstdio> 1911.1Skamil#include <thread> 1921.1Skamil#include <mutex> 1931.1Skamilstd::once_flag flag; 1941.1Skamilint callpic(void) { 1951.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1961.1Skamil return 0; 1971.1Skamil} 1981.1SkamilEOF 1991.1Skamil 2001.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2011.1Skamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp 2021.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2031.1Skamil c++ -m32 -o call_once test.cpp -L. -ltest -pthread 2041.1Skamil 2051.1Skamil export LD_LIBRARY_PATH=. 2061.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2071.1Skamil} 2081.1Skamil 2091.1Skamilcall_once_pic_profile_body() { 2101.1Skamil cat > test.cpp << EOF 2111.1Skamil#include <stdlib.h> 2121.1Skamilint callpic(void); 2131.1Skamilint main(void) {callpic();exit(0);} 2141.1SkamilEOF 2151.1Skamil cat > pic.cpp << EOF 2161.1Skamil#include <cstdio> 2171.1Skamil#include <thread> 2181.1Skamil#include <mutex> 2191.1Skamilstd::once_flag flag; 2201.1Skamilint callpic(void) { 2211.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2221.1Skamil return 0; 2231.1Skamil} 2241.1SkamilEOF 2251.1Skamil 2261.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2271.1Skamil c++ -pg -fPIC -shared -o libtest.so pic.cpp 2281.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2291.1Skamil c++ -pg -o call_once test.cpp -L. -ltest -pthread 2301.1Skamil 2311.1Skamil export LD_LIBRARY_PATH=. 2321.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2331.1Skamil} 2341.1Skamil 2351.1Skamilcall_once_pic_profile_32_body() { 2361.1Skamil # check whether this arch is 64bit 2371.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2381.1Skamil atf_skip "this is not a 64 bit architecture" 2391.1Skamil fi 2401.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2411.1Skamil atf_skip "c++ -m32 not supported on this architecture" 2421.1Skamil else 2431.1Skamil if fgrep -q _LP64 ./def32; then 2441.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 2451.1Skamil fi 2461.1Skamil fi 2471.1Skamil 2481.1Skamil cat > test.cpp << EOF 2491.1Skamil#include <stdlib.h> 2501.1Skamilint callpic(void); 2511.1Skamilint main(void) {callpic();exit(0);} 2521.1SkamilEOF 2531.1Skamil cat > pic.cpp << EOF 2541.1Skamil#include <cstdio> 2551.1Skamil#include <thread> 2561.1Skamil#include <mutex> 2571.1Skamilstd::once_flag flag; 2581.1Skamilint callpic(void) { 2591.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2601.1Skamil return 0; 2611.1Skamil} 2621.1SkamilEOF 2631.1Skamil 2641.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2651.1Skamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp 2661.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2671.1Skamil c++ -m32 -pg -o call_once test.cpp -L. -ltest -pthread 2681.1Skamil 2691.1Skamil export LD_LIBRARY_PATH=. 2701.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2711.1Skamil} 2721.1Skamil 2731.1Skamilcall_once_pie_body() { 2741.1Skamil # check whether this arch supports -pie 2751.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 2761.1Skamil atf_skip "c++ -pie not supported on this architecture" 2771.1Skamil fi 2781.1Skamil cat > test.cpp << EOF 2791.1Skamil#include <cstdio> 2801.1Skamil#include <thread> 2811.1Skamil#include <mutex> 2821.1Skamilstd::once_flag flag; 2831.1Skamilint main(void) { 2841.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2851.1Skamil return 0; 2861.1Skamil} 2871.1SkamilEOF 2881.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once test.cpp -pthread 2891.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2901.1Skamil} 2911.1Skamil 2921.1Skamilcall_once_32_body() { 2931.1Skamil # check whether this arch is 64bit 2941.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2951.1Skamil atf_skip "this is not a 64 bit architecture" 2961.1Skamil fi 2971.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2981.1Skamil atf_skip "c++ -m32 not supported on this architecture" 2991.1Skamil else 3001.1Skamil if fgrep -q _LP64 ./def32; then 3011.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 3021.1Skamil fi 3031.1Skamil fi 3041.1Skamil 3051.1Skamil cat > test.cpp << EOF 3061.1Skamil#include <cstdio> 3071.1Skamil#include <thread> 3081.1Skamil#include <mutex> 3091.1Skamilstd::once_flag flag; 3101.1Skamilint main(void) { 3111.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3121.1Skamil return 0; 3131.1Skamil} 3141.1SkamilEOF 3151.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_32 -m32 test.cpp -pthread 3161.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_64 test.cpp -pthread 3171.1Skamil file -b ./call_once_32 > ./ftype32 3181.1Skamil file -b ./call_once_64 > ./ftype64 3191.1Skamil if diff ./ftype32 ./ftype64 >/dev/null; then 3201.1Skamil atf_fail "generated binaries do not differ" 3211.1Skamil fi 3221.1Skamil echo "32bit binaries on this platform are:" 3231.1Skamil cat ./ftype32 3241.1Skamil echo "While native (64bit) binaries are:" 3251.1Skamil cat ./ftype64 3261.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once_32 3271.1Skamil 3281.1Skamil # do another test with static 32bit binaries 3291.1Skamil cat > test.cpp << EOF 3301.1Skamil#include <cstdio> 3311.1Skamil#include <thread> 3321.1Skamil#include <mutex> 3331.1Skamilstd::once_flag flag; 3341.1Skamilint main(void) { 3351.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3361.1Skamil return 0; 3371.1Skamil} 3381.1SkamilEOF 3391.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once -m32 -pthread \ 3401.1Skamil -static test.cpp 3411.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 3421.1Skamil} 3431.1Skamil 3441.1Skamilcall_once_static_body() { 3451.1Skamil cat > test.cpp << EOF 3461.1Skamil#include <cstdio> 3471.1Skamil#include <thread> 3481.1Skamil#include <mutex> 3491.1Skamilstd::once_flag flag; 3501.1Skamilint main(void) { 3511.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3521.1Skamil return 0; 3531.1Skamil} 3541.1SkamilEOF 3551.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once test.cpp -pthread 3561.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 3571.1Skamil} 3581.1Skamil 3591.1Skamilatf_init_test_cases() 3601.1Skamil{ 3611.1Skamil 3621.1Skamil atf_add_test_case call_once 3631.1Skamil atf_add_test_case call_once_profile 3641.1Skamil atf_add_test_case call_once_pic 3651.1Skamil atf_add_test_case call_once_pie 3661.1Skamil atf_add_test_case call_once_32 3671.1Skamil atf_add_test_case call_once_static 3681.1Skamil atf_add_test_case call_once_pic_32 3691.1Skamil atf_add_test_case call_once_pic_profile 3701.1Skamil atf_add_test_case call_once_pic_profile_32 3711.1Skamil atf_add_test_case call_once_profile_32 3721.1Skamil} 373