Home | History | Annotate | Line # | Download | only in c++
t_call_once.sh revision 1.1.2.2
      1 #	$NetBSD: t_call_once.sh,v 1.1.2.2 2018/03/30 06:20:16 pgoyette 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 	atf_expect_fail "profiling option doesn't work now"
    105 	cat > test.cpp << EOF
    106 #include <cstdio>
    107 #include <thread>
    108 #include <mutex>
    109 std::once_flag flag;
    110 int main(void) {
    111         std::call_once(flag, [](){ printf("hello, world!\n"); });
    112         return 0;
    113 }
    114 EOF
    115 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once test.cpp -pthread
    116 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    117 }
    118 
    119 call_once_profile_32_body() {
    120 	atf_expect_fail "profiling option doesn't work now"
    121 	# check whether this arch is 64bit
    122 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    123 		atf_skip "this is not a 64 bit architecture"
    124 	fi
    125 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    126 		atf_skip "c++ -m32 not supported on this architecture"
    127 	else
    128 		if fgrep -q _LP64 ./def32; then
    129 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    130 		fi
    131 	fi
    132 
    133 	cat > test.cpp << EOF
    134 #include <cstdio>
    135 #include <thread>
    136 #include <mutex>
    137 std::once_flag flag;
    138 int main(void) {
    139         std::call_once(flag, [](){ printf("hello, world!\n"); });
    140         return 0;
    141 }
    142 EOF
    143 	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once test.cpp -pthread
    144 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    145 	atf_expect_fail "The combination of 32-bit and profiling should be fail"
    146 }
    147 
    148 call_once_pic_body() {
    149 	cat > test.cpp << EOF
    150 #include <stdlib.h>
    151 int callpic(void);
    152 int main(void) {callpic();exit(0);}
    153 EOF
    154 	cat > pic.cpp << EOF
    155 #include <cstdio>
    156 #include <thread>
    157 #include <mutex>
    158 std::once_flag flag;
    159 int callpic(void) {
    160         std::call_once(flag, [](){ printf("hello, world!\n"); });
    161         return 0;
    162 }
    163 EOF
    164 
    165 	atf_check -s exit:0 -o ignore -e ignore \
    166 	    c++ -fPIC -shared -o libtest.so pic.cpp
    167 	atf_check -s exit:0 -o ignore -e ignore \
    168 	    c++ -o call_once test.cpp -L. -ltest -pthread
    169 
    170 	export LD_LIBRARY_PATH=.
    171 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    172 }
    173 
    174 call_once_pic_32_body() {
    175 	# check whether this arch is 64bit
    176 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    177 		atf_skip "this is not a 64 bit architecture"
    178 	fi
    179 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    180 		atf_skip "c++ -m32 not supported on this architecture"
    181 	else
    182 		if fgrep -q _LP64 ./def32; then
    183 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    184 		fi
    185 	fi
    186 
    187 	cat > test.cpp << EOF
    188 #include <stdlib.h>
    189 int callpic(void);
    190 int main(void) {callpic();exit(0);}
    191 EOF
    192 	cat > pic.cpp << EOF
    193 #include <cstdio>
    194 #include <thread>
    195 #include <mutex>
    196 std::once_flag flag;
    197 int callpic(void) {
    198         std::call_once(flag, [](){ printf("hello, world!\n"); });
    199         return 0;
    200 }
    201 EOF
    202 
    203 	atf_check -s exit:0 -o ignore -e ignore \
    204 	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
    205 	atf_check -s exit:0 -o ignore -e ignore \
    206 	    c++ -m32 -o call_once test.cpp -L. -ltest -pthread
    207 
    208 	export LD_LIBRARY_PATH=.
    209 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    210 }
    211 
    212 call_once_pic_profile_body() {
    213 	atf_expect_fail "profiling option doesn't work now"
    214 	cat > test.cpp << EOF
    215 #include <stdlib.h>
    216 int callpic(void);
    217 int main(void) {callpic();exit(0);}
    218 EOF
    219 	cat > pic.cpp << EOF
    220 #include <cstdio>
    221 #include <thread>
    222 #include <mutex>
    223 std::once_flag flag;
    224 int callpic(void) {
    225         std::call_once(flag, [](){ printf("hello, world!\n"); });
    226         return 0;
    227 }
    228 EOF
    229 
    230 	atf_check -s exit:0 -o ignore -e ignore \
    231 	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
    232 	atf_check -s exit:0 -o ignore -e ignore \
    233 	    c++ -pg -o call_once test.cpp -L. -ltest -pthread
    234 
    235 	export LD_LIBRARY_PATH=.
    236 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    237 }
    238 
    239 call_once_pic_profile_32_body() {
    240 	atf_expect_fail "profiling option doesn't work now"
    241 	# check whether this arch is 64bit
    242 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    243 		atf_skip "this is not a 64 bit architecture"
    244 	fi
    245 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    246 		atf_skip "c++ -m32 not supported on this architecture"
    247 	else
    248 		if fgrep -q _LP64 ./def32; then
    249 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    250 		fi
    251 	fi
    252 
    253 	cat > test.cpp << EOF
    254 #include <stdlib.h>
    255 int callpic(void);
    256 int main(void) {callpic();exit(0);}
    257 EOF
    258 	cat > pic.cpp << EOF
    259 #include <cstdio>
    260 #include <thread>
    261 #include <mutex>
    262 std::once_flag flag;
    263 int callpic(void) {
    264         std::call_once(flag, [](){ printf("hello, world!\n"); });
    265         return 0;
    266 }
    267 EOF
    268 
    269 	atf_check -s exit:0 -o ignore -e ignore \
    270 	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
    271 	atf_check -s exit:0 -o ignore -e ignore \
    272 	    c++ -m32 -pg -o call_once test.cpp -L. -ltest -pthread
    273 
    274 	export LD_LIBRARY_PATH=.
    275 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    276 }
    277 
    278 call_once_pie_body() {
    279 	# check whether this arch supports -pie
    280 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    281 		atf_skip "c++ -pie not supported on this architecture"
    282 	fi
    283 	cat > test.cpp << EOF
    284 #include <cstdio>
    285 #include <thread>
    286 #include <mutex>
    287 std::once_flag flag;
    288 int main(void) {
    289         std::call_once(flag, [](){ printf("hello, world!\n"); });
    290         return 0;
    291 }
    292 EOF
    293 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once test.cpp -pthread
    294 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    295 }
    296 
    297 call_once_32_body() {
    298 	# check whether this arch is 64bit
    299 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    300 		atf_skip "this is not a 64 bit architecture"
    301 	fi
    302 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    303 		atf_skip "c++ -m32 not supported on this architecture"
    304 	else
    305 		if fgrep -q _LP64 ./def32; then
    306 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    307 		fi
    308 	fi
    309 
    310 	cat > test.cpp << EOF
    311 #include <cstdio>
    312 #include <thread>
    313 #include <mutex>
    314 std::once_flag flag;
    315 int main(void) {
    316         std::call_once(flag, [](){ printf("hello, world!\n"); });
    317         return 0;
    318 }
    319 EOF
    320 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_32 -m32 test.cpp -pthread
    321 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_64 test.cpp -pthread
    322 	file -b ./call_once_32 > ./ftype32
    323 	file -b ./call_once_64 > ./ftype64
    324 	if diff ./ftype32 ./ftype64 >/dev/null; then
    325 		atf_fail "generated binaries do not differ"
    326 	fi
    327 	echo "32bit binaries on this platform are:"
    328 	cat ./ftype32
    329 	echo "While native (64bit) binaries are:"
    330 	cat ./ftype64
    331 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once_32
    332 
    333 	# do another test with static 32bit binaries
    334 	cat > test.cpp << EOF
    335 #include <cstdio>
    336 #include <thread>
    337 #include <mutex>
    338 std::once_flag flag;
    339 int main(void) {
    340         std::call_once(flag, [](){ printf("hello, world!\n"); });
    341         return 0;
    342 }
    343 EOF
    344 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once -m32 -pthread \
    345 	    -static test.cpp
    346 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    347 }
    348 
    349 call_once_static_body() {
    350 	cat > test.cpp << EOF
    351 #include <cstdio>
    352 #include <thread>
    353 #include <mutex>
    354 std::once_flag flag;
    355 int main(void) {
    356         std::call_once(flag, [](){ printf("hello, world!\n"); });
    357         return 0;
    358 }
    359 EOF
    360 	atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once test.cpp -pthread
    361 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
    362 }
    363 
    364 atf_init_test_cases()
    365 {
    366 
    367 	atf_add_test_case call_once
    368 	atf_add_test_case call_once_profile
    369 	atf_add_test_case call_once_pic
    370 	atf_add_test_case call_once_pie
    371 	atf_add_test_case call_once_32
    372 	atf_add_test_case call_once_static
    373 	atf_add_test_case call_once_pic_32
    374 	atf_add_test_case call_once_pic_profile
    375 	atf_add_test_case call_once_pic_profile_32
    376 	atf_add_test_case call_once_profile_32
    377 }
    378