t_call_once.sh revision 1.1
11.1Skamil# $NetBSD: t_call_once.sh,v 1.1 2018/03/24 00:26:51 kamil 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 atf_expect_fail "profiling option doesn't work now" 1051.1Skamil cat > test.cpp << EOF 1061.1Skamil#include <cstdio> 1071.1Skamil#include <thread> 1081.1Skamil#include <mutex> 1091.1Skamilstd::once_flag flag; 1101.1Skamilint main(void) { 1111.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1121.1Skamil return 0; 1131.1Skamil} 1141.1SkamilEOF 1151.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once test.cpp -pthread 1161.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1171.1Skamil} 1181.1Skamil 1191.1Skamilcall_once_profile_32_body() { 1201.1Skamil atf_expect_fail "profiling option doesn't work now" 1211.1Skamil # check whether this arch is 64bit 1221.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1231.1Skamil atf_skip "this is not a 64 bit architecture" 1241.1Skamil fi 1251.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1261.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1271.1Skamil else 1281.1Skamil if fgrep -q _LP64 ./def32; then 1291.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1301.1Skamil fi 1311.1Skamil fi 1321.1Skamil 1331.1Skamil cat > test.cpp << EOF 1341.1Skamil#include <cstdio> 1351.1Skamil#include <thread> 1361.1Skamil#include <mutex> 1371.1Skamilstd::once_flag flag; 1381.1Skamilint main(void) { 1391.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1401.1Skamil return 0; 1411.1Skamil} 1421.1SkamilEOF 1431.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once test.cpp -pthread 1441.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1451.1Skamil atf_expect_fail "The combination of 32-bit and profiling should be fail" 1461.1Skamil} 1471.1Skamil 1481.1Skamilcall_once_pic_body() { 1491.1Skamil cat > test.cpp << EOF 1501.1Skamil#include <stdlib.h> 1511.1Skamilint callpic(void); 1521.1Skamilint main(void) {callpic();exit(0);} 1531.1SkamilEOF 1541.1Skamil cat > pic.cpp << EOF 1551.1Skamil#include <cstdio> 1561.1Skamil#include <thread> 1571.1Skamil#include <mutex> 1581.1Skamilstd::once_flag flag; 1591.1Skamilint callpic(void) { 1601.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1611.1Skamil return 0; 1621.1Skamil} 1631.1SkamilEOF 1641.1Skamil 1651.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1661.1Skamil c++ -fPIC -shared -o libtest.so pic.cpp 1671.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 1681.1Skamil c++ -o call_once test.cpp -L. -ltest -pthread 1691.1Skamil 1701.1Skamil export LD_LIBRARY_PATH=. 1711.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 1721.1Skamil} 1731.1Skamil 1741.1Skamilcall_once_pic_32_body() { 1751.1Skamil # check whether this arch is 64bit 1761.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 1771.1Skamil atf_skip "this is not a 64 bit architecture" 1781.1Skamil fi 1791.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1801.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1811.1Skamil else 1821.1Skamil if fgrep -q _LP64 ./def32; then 1831.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1841.1Skamil fi 1851.1Skamil fi 1861.1Skamil 1871.1Skamil cat > test.cpp << EOF 1881.1Skamil#include <stdlib.h> 1891.1Skamilint callpic(void); 1901.1Skamilint main(void) {callpic();exit(0);} 1911.1SkamilEOF 1921.1Skamil cat > pic.cpp << EOF 1931.1Skamil#include <cstdio> 1941.1Skamil#include <thread> 1951.1Skamil#include <mutex> 1961.1Skamilstd::once_flag flag; 1971.1Skamilint callpic(void) { 1981.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 1991.1Skamil return 0; 2001.1Skamil} 2011.1SkamilEOF 2021.1Skamil 2031.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2041.1Skamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp 2051.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2061.1Skamil c++ -m32 -o call_once test.cpp -L. -ltest -pthread 2071.1Skamil 2081.1Skamil export LD_LIBRARY_PATH=. 2091.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2101.1Skamil} 2111.1Skamil 2121.1Skamilcall_once_pic_profile_body() { 2131.1Skamil atf_expect_fail "profiling option doesn't work now" 2141.1Skamil cat > test.cpp << EOF 2151.1Skamil#include <stdlib.h> 2161.1Skamilint callpic(void); 2171.1Skamilint main(void) {callpic();exit(0);} 2181.1SkamilEOF 2191.1Skamil cat > pic.cpp << EOF 2201.1Skamil#include <cstdio> 2211.1Skamil#include <thread> 2221.1Skamil#include <mutex> 2231.1Skamilstd::once_flag flag; 2241.1Skamilint callpic(void) { 2251.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2261.1Skamil return 0; 2271.1Skamil} 2281.1SkamilEOF 2291.1Skamil 2301.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2311.1Skamil c++ -pg -fPIC -shared -o libtest.so pic.cpp 2321.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2331.1Skamil c++ -pg -o call_once test.cpp -L. -ltest -pthread 2341.1Skamil 2351.1Skamil export LD_LIBRARY_PATH=. 2361.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2371.1Skamil} 2381.1Skamil 2391.1Skamilcall_once_pic_profile_32_body() { 2401.1Skamil atf_expect_fail "profiling option doesn't work now" 2411.1Skamil # check whether this arch is 64bit 2421.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 2431.1Skamil atf_skip "this is not a 64 bit architecture" 2441.1Skamil fi 2451.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 2461.1Skamil atf_skip "c++ -m32 not supported on this architecture" 2471.1Skamil else 2481.1Skamil if fgrep -q _LP64 ./def32; then 2491.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 2501.1Skamil fi 2511.1Skamil fi 2521.1Skamil 2531.1Skamil cat > test.cpp << EOF 2541.1Skamil#include <stdlib.h> 2551.1Skamilint callpic(void); 2561.1Skamilint main(void) {callpic();exit(0);} 2571.1SkamilEOF 2581.1Skamil cat > pic.cpp << EOF 2591.1Skamil#include <cstdio> 2601.1Skamil#include <thread> 2611.1Skamil#include <mutex> 2621.1Skamilstd::once_flag flag; 2631.1Skamilint callpic(void) { 2641.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2651.1Skamil return 0; 2661.1Skamil} 2671.1SkamilEOF 2681.1Skamil 2691.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2701.1Skamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp 2711.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 2721.1Skamil c++ -m32 -pg -o call_once test.cpp -L. -ltest -pthread 2731.1Skamil 2741.1Skamil export LD_LIBRARY_PATH=. 2751.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2761.1Skamil} 2771.1Skamil 2781.1Skamilcall_once_pie_body() { 2791.1Skamil # check whether this arch supports -pie 2801.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 2811.1Skamil atf_skip "c++ -pie not supported on this architecture" 2821.1Skamil fi 2831.1Skamil cat > test.cpp << EOF 2841.1Skamil#include <cstdio> 2851.1Skamil#include <thread> 2861.1Skamil#include <mutex> 2871.1Skamilstd::once_flag flag; 2881.1Skamilint main(void) { 2891.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 2901.1Skamil return 0; 2911.1Skamil} 2921.1SkamilEOF 2931.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once test.cpp -pthread 2941.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 2951.1Skamil} 2961.1Skamil 2971.1Skamilcall_once_32_body() { 2981.1Skamil # check whether this arch is 64bit 2991.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 3001.1Skamil atf_skip "this is not a 64 bit architecture" 3011.1Skamil fi 3021.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 3031.1Skamil atf_skip "c++ -m32 not supported on this architecture" 3041.1Skamil else 3051.1Skamil if fgrep -q _LP64 ./def32; then 3061.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 3071.1Skamil fi 3081.1Skamil fi 3091.1Skamil 3101.1Skamil cat > test.cpp << EOF 3111.1Skamil#include <cstdio> 3121.1Skamil#include <thread> 3131.1Skamil#include <mutex> 3141.1Skamilstd::once_flag flag; 3151.1Skamilint main(void) { 3161.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3171.1Skamil return 0; 3181.1Skamil} 3191.1SkamilEOF 3201.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_32 -m32 test.cpp -pthread 3211.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_64 test.cpp -pthread 3221.1Skamil file -b ./call_once_32 > ./ftype32 3231.1Skamil file -b ./call_once_64 > ./ftype64 3241.1Skamil if diff ./ftype32 ./ftype64 >/dev/null; then 3251.1Skamil atf_fail "generated binaries do not differ" 3261.1Skamil fi 3271.1Skamil echo "32bit binaries on this platform are:" 3281.1Skamil cat ./ftype32 3291.1Skamil echo "While native (64bit) binaries are:" 3301.1Skamil cat ./ftype64 3311.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once_32 3321.1Skamil 3331.1Skamil # do another test with static 32bit binaries 3341.1Skamil cat > test.cpp << EOF 3351.1Skamil#include <cstdio> 3361.1Skamil#include <thread> 3371.1Skamil#include <mutex> 3381.1Skamilstd::once_flag flag; 3391.1Skamilint main(void) { 3401.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3411.1Skamil return 0; 3421.1Skamil} 3431.1SkamilEOF 3441.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o call_once -m32 -pthread \ 3451.1Skamil -static test.cpp 3461.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 3471.1Skamil} 3481.1Skamil 3491.1Skamilcall_once_static_body() { 3501.1Skamil cat > test.cpp << EOF 3511.1Skamil#include <cstdio> 3521.1Skamil#include <thread> 3531.1Skamil#include <mutex> 3541.1Skamilstd::once_flag flag; 3551.1Skamilint main(void) { 3561.1Skamil std::call_once(flag, [](){ printf("hello, world!\n"); }); 3571.1Skamil return 0; 3581.1Skamil} 3591.1SkamilEOF 3601.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once test.cpp -pthread 3611.1Skamil atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once 3621.1Skamil} 3631.1Skamil 3641.1Skamilatf_init_test_cases() 3651.1Skamil{ 3661.1Skamil 3671.1Skamil atf_add_test_case call_once 3681.1Skamil atf_add_test_case call_once_profile 3691.1Skamil atf_add_test_case call_once_pic 3701.1Skamil atf_add_test_case call_once_pie 3711.1Skamil atf_add_test_case call_once_32 3721.1Skamil atf_add_test_case call_once_static 3731.1Skamil atf_add_test_case call_once_pic_32 3741.1Skamil atf_add_test_case call_once_pic_profile 3751.1Skamil atf_add_test_case call_once_pic_profile_32 3761.1Skamil atf_add_test_case call_once_profile_32 3771.1Skamil} 378