Home | History | Annotate | Line # | Download | only in c++
t_call_once.sh revision 1.3
      1 #	$NetBSD: t_call_once.sh,v 1.3 2020/02/11 06:26:19 riastradh Exp $
      2 #
      3 # Copyright (c) 2018 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 atf_test_case call_once
     29 call_once_head() {
     30 	atf_set "descr" "compile and run std::call_once"
     31 	atf_set "require.progs" "c++"
     32 }
     33 
     34 atf_test_case call_once_profile
     35 call_once_profile_head() {
     36 	atf_set "descr" "compile and run std::call_once with profiling option"
     37 	atf_set "require.progs" "c++"
     38 }
     39 
     40 atf_test_case call_once_pic
     41 call_once_pic_head() {
     42 	atf_set "descr" "compile and run PIC std::call_once"
     43 	atf_set "require.progs" "c++"
     44 }
     45 
     46 atf_test_case call_once_pic_32
     47 call_once_pic_32_head() {
     48 	atf_set "descr" "compile and run 32-bit PIC std::call_once"
     49 	atf_set "require.progs" "c++"
     50 }
     51 
     52 atf_test_case call_once_pic_profile
     53 call_once_pic_head() {
     54 	atf_set "descr" "compile and run PIC std::call_once with profiling flag"
     55 	atf_set "require.progs" "c++"
     56 }
     57 
     58 atf_test_case call_once_pic_profile_32
     59 call_once_pic_profile_32_head() {
     60 	atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag"
     61 	atf_set "require.progs" "c++"
     62 }
     63 
     64 atf_test_case call_once_profile_32
     65 call_once_profile_32_head() {
     66 	atf_set "descr" "compile and run 32-bit std::call_once with profiling flag"
     67 	atf_set "require.progs" "c++"
     68 }
     69 
     70 atf_test_case call_once_pie
     71 call_once_pie_head() {
     72 	atf_set "descr" "compile and run position independent (PIE) std::call_once"
     73 	atf_set "require.progs" "c++"
     74 }
     75 
     76 atf_test_case call_once_32
     77 call_once_32_head() {
     78 	atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation"
     79 	atf_set "require.progs" "c++ file diff cat"
     80 }
     81 
     82 atf_test_case call_once_static
     83 call_once_static_head() {
     84 	atf_set "descr" "compile and run std::call_once with static flag"
     85 	atf_set "require.progs" "c++"
     86 }
     87 
     88 call_once_body() {
     89 	cat > test.cpp << EOF
     90 #include <cstdio>
     91 #include <thread>
     92 #include <mutex>
     93 std::once_flag flag;
     94 int main(void) {
     95         std::call_once(flag, [](){ printf("hello, world!\n"); });
     96         return 0;
     97 }
     98 EOF
     99 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once test.cpp -pthread
    100 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    101 }
    102 
    103 call_once_profile_body() {
    104 	cat > test.cpp << EOF
    105 #include <cstdio>
    106 #include <thread>
    107 #include <mutex>
    108 std::once_flag flag;
    109 int main(void) {
    110         std::call_once(flag, [](){ printf("hello, world!\n"); });
    111         return 0;
    112 }
    113 EOF
    114 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once test.cpp -pthread
    115 	case `uname -p` in
    116 	aarch64)
    117 		atf_expect_fail 'cc -pg is busted on aarch64'
    118 		;;
    119 	esac
    120 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    121 }
    122 
    123 call_once_profile_32_body() {
    124 	# check whether this arch is 64bit
    125 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    126 		atf_skip "this is not a 64 bit architecture"
    127 	fi
    128 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    129 		atf_skip "c++ -m32 not supported on this architecture"
    130 	else
    131 		if fgrep -q _LP64 ./def32; then
    132 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    133 		fi
    134 	fi
    135 
    136 	cat > test.cpp << EOF
    137 #include <cstdio>
    138 #include <thread>
    139 #include <mutex>
    140 std::once_flag flag;
    141 int main(void) {
    142         std::call_once(flag, [](){ printf("hello, world!\n"); });
    143         return 0;
    144 }
    145 EOF
    146 	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once test.cpp -pthread
    147 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    148 }
    149 
    150 call_once_pic_body() {
    151 	cat > test.cpp << EOF
    152 #include <stdlib.h>
    153 int callpic(void);
    154 int main(void) {callpic();exit(0);}
    155 EOF
    156 	cat > pic.cpp << EOF
    157 #include <cstdio>
    158 #include <thread>
    159 #include <mutex>
    160 std::once_flag flag;
    161 int callpic(void) {
    162         std::call_once(flag, [](){ printf("hello, world!\n"); });
    163         return 0;
    164 }
    165 EOF
    166 
    167 	atf_check -s exit:0 -o ignore -e ignore \
    168 	    c++ -fPIC -shared -o libtest.so pic.cpp
    169 	atf_check -s exit:0 -o ignore -e ignore \
    170 	    c++ -o call_once test.cpp -L. -ltest -pthread
    171 
    172 	export LD_LIBRARY_PATH=.
    173 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    174 }
    175 
    176 call_once_pic_32_body() {
    177 	# check whether this arch is 64bit
    178 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    179 		atf_skip "this is not a 64 bit architecture"
    180 	fi
    181 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    182 		atf_skip "c++ -m32 not supported on this architecture"
    183 	else
    184 		if fgrep -q _LP64 ./def32; then
    185 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    186 		fi
    187 	fi
    188 
    189 	cat > test.cpp << EOF
    190 #include <stdlib.h>
    191 int callpic(void);
    192 int main(void) {callpic();exit(0);}
    193 EOF
    194 	cat > pic.cpp << EOF
    195 #include <cstdio>
    196 #include <thread>
    197 #include <mutex>
    198 std::once_flag flag;
    199 int callpic(void) {
    200         std::call_once(flag, [](){ printf("hello, world!\n"); });
    201         return 0;
    202 }
    203 EOF
    204 
    205 	atf_check -s exit:0 -o ignore -e ignore \
    206 	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
    207 	atf_check -s exit:0 -o ignore -e ignore \
    208 	    c++ -m32 -o call_once test.cpp -L. -ltest -pthread
    209 
    210 	export LD_LIBRARY_PATH=.
    211 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    212 }
    213 
    214 call_once_pic_profile_body() {
    215 	cat > test.cpp << EOF
    216 #include <stdlib.h>
    217 int callpic(void);
    218 int main(void) {callpic();exit(0);}
    219 EOF
    220 	cat > pic.cpp << EOF
    221 #include <cstdio>
    222 #include <thread>
    223 #include <mutex>
    224 std::once_flag flag;
    225 int callpic(void) {
    226         std::call_once(flag, [](){ printf("hello, world!\n"); });
    227         return 0;
    228 }
    229 EOF
    230 
    231 	atf_check -s exit:0 -o ignore -e ignore \
    232 	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
    233 	atf_check -s exit:0 -o ignore -e ignore \
    234 	    c++ -pg -o call_once test.cpp -L. -ltest -pthread
    235 
    236 	case `uname -p` in
    237 	aarch64)
    238 		atf_expect_fail 'cc -pg is busted on aarch64'
    239 		;;
    240 	esac
    241 	export LD_LIBRARY_PATH=.
    242 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    243 }
    244 
    245 call_once_pic_profile_32_body() {
    246 	# check whether this arch is 64bit
    247 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    248 		atf_skip "this is not a 64 bit architecture"
    249 	fi
    250 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    251 		atf_skip "c++ -m32 not supported on this architecture"
    252 	else
    253 		if fgrep -q _LP64 ./def32; then
    254 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    255 		fi
    256 	fi
    257 
    258 	cat > test.cpp << EOF
    259 #include <stdlib.h>
    260 int callpic(void);
    261 int main(void) {callpic();exit(0);}
    262 EOF
    263 	cat > pic.cpp << EOF
    264 #include <cstdio>
    265 #include <thread>
    266 #include <mutex>
    267 std::once_flag flag;
    268 int callpic(void) {
    269         std::call_once(flag, [](){ printf("hello, world!\n"); });
    270         return 0;
    271 }
    272 EOF
    273 
    274 	atf_check -s exit:0 -o ignore -e ignore \
    275 	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
    276 	atf_check -s exit:0 -o ignore -e ignore \
    277 	    c++ -m32 -pg -o call_once test.cpp -L. -ltest -pthread
    278 
    279 	export LD_LIBRARY_PATH=.
    280 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    281 }
    282 
    283 call_once_pie_body() {
    284 	# check whether this arch supports -pie
    285 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    286 		atf_skip "c++ -pie not supported on this architecture"
    287 	fi
    288 	cat > test.cpp << EOF
    289 #include <cstdio>
    290 #include <thread>
    291 #include <mutex>
    292 std::once_flag flag;
    293 int main(void) {
    294         std::call_once(flag, [](){ printf("hello, world!\n"); });
    295         return 0;
    296 }
    297 EOF
    298 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once test.cpp -pthread
    299 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    300 }
    301 
    302 call_once_32_body() {
    303 	# check whether this arch is 64bit
    304 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    305 		atf_skip "this is not a 64 bit architecture"
    306 	fi
    307 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    308 		atf_skip "c++ -m32 not supported on this architecture"
    309 	else
    310 		if fgrep -q _LP64 ./def32; then
    311 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    312 		fi
    313 	fi
    314 
    315 	cat > test.cpp << EOF
    316 #include <cstdio>
    317 #include <thread>
    318 #include <mutex>
    319 std::once_flag flag;
    320 int main(void) {
    321         std::call_once(flag, [](){ printf("hello, world!\n"); });
    322         return 0;
    323 }
    324 EOF
    325 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_32 -m32 test.cpp -pthread
    326 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_64 test.cpp -pthread
    327 	file -b ./call_once_32 > ./ftype32
    328 	file -b ./call_once_64 > ./ftype64
    329 	if diff ./ftype32 ./ftype64 >/dev/null; then
    330 		atf_fail "generated binaries do not differ"
    331 	fi
    332 	echo "32bit binaries on this platform are:"
    333 	cat ./ftype32
    334 	echo "While native (64bit) binaries are:"
    335 	cat ./ftype64
    336 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once_32
    337 
    338 	# do another test with static 32bit binaries
    339 	cat > test.cpp << EOF
    340 #include <cstdio>
    341 #include <thread>
    342 #include <mutex>
    343 std::once_flag flag;
    344 int main(void) {
    345         std::call_once(flag, [](){ printf("hello, world!\n"); });
    346         return 0;
    347 }
    348 EOF
    349 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once -m32 -pthread \
    350 	    -static test.cpp
    351 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    352 }
    353 
    354 call_once_static_body() {
    355 	cat > test.cpp << EOF
    356 #include <cstdio>
    357 #include <thread>
    358 #include <mutex>
    359 std::once_flag flag;
    360 int main(void) {
    361         std::call_once(flag, [](){ printf("hello, world!\n"); });
    362         return 0;
    363 }
    364 EOF
    365 	atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once test.cpp -pthread
    366 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    367 }
    368 
    369 atf_init_test_cases()
    370 {
    371 
    372 	atf_add_test_case call_once
    373 	atf_add_test_case call_once_profile
    374 	atf_add_test_case call_once_pic
    375 	atf_add_test_case call_once_pie
    376 	atf_add_test_case call_once_32
    377 	atf_add_test_case call_once_static
    378 	atf_add_test_case call_once_pic_32
    379 	atf_add_test_case call_once_pic_profile
    380 	atf_add_test_case call_once_pic_profile_32
    381 	atf_add_test_case call_once_profile_32
    382 }
    383