Home | History | Annotate | Line # | Download | only in c++
t_pthread_once.sh revision 1.1.2.2
      1 #	$NetBSD: t_pthread_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 pthread_once
     29 pthread_once_head() {
     30 	atf_set "descr" "compile and run std::pthread_once"
     31 	atf_set "require.progs" "c++"
     32 }
     33 
     34 atf_test_case pthread_once_profile
     35 pthread_once_profile_head() {
     36 	atf_set "descr" "compile and run std::pthread_once with profiling option"
     37 	atf_set "require.progs" "c++"
     38 }
     39 
     40 atf_test_case pthread_once_pic
     41 pthread_once_pic_head() {
     42 	atf_set "descr" "compile and run PIC std::pthread_once"
     43 	atf_set "require.progs" "c++"
     44 }
     45 
     46 atf_test_case pthread_once_pic_32
     47 pthread_once_pic_32_head() {
     48 	atf_set "descr" "compile and run 32-bit PIC std::pthread_once"
     49 	atf_set "require.progs" "c++"
     50 }
     51 
     52 atf_test_case pthread_once_pic_profile
     53 pthread_once_pic_head() {
     54 	atf_set "descr" "compile and run PIC std::pthread_once with profiling &flag"
     55 	atf_set "require.progs" "c++"
     56 }
     57 
     58 atf_test_case pthread_once_pic_profile_32
     59 pthread_once_pic_profile_32_head() {
     60 	atf_set "descr" "compile and run 32-bit PIC std::pthread_once with profiling &flag"
     61 	atf_set "require.progs" "c++"
     62 }
     63 
     64 atf_test_case pthread_once_profile_32
     65 pthread_once_profile_32_head() {
     66 	atf_set "descr" "compile and run 32-bit std::pthread_once with profiling &flag"
     67 	atf_set "require.progs" "c++"
     68 }
     69 
     70 atf_test_case pthread_once_pie
     71 pthread_once_pie_head() {
     72 	atf_set "descr" "compile and run position independent (PIE) std::pthread_once"
     73 	atf_set "require.progs" "c++"
     74 }
     75 
     76 atf_test_case pthread_once_32
     77 pthread_once_32_head() {
     78 	atf_set "descr" "compile and run std::pthread_once for/in netbsd32 emulation"
     79 	atf_set "require.progs" "c++ file diff cat"
     80 }
     81 
     82 atf_test_case pthread_once_static
     83 pthread_once_static_head() {
     84 	atf_set "descr" "compile and run std::pthread_once with static &flag"
     85 	atf_set "require.progs" "c++"
     86 }
     87 
     88 pthread_once_body() {
     89 	cat > test.cpp << EOF
     90 #include <cstdio>
     91 #include <thread>
     92 int main(void) {
     93         pthread_once_t flag = PTHREAD_ONCE_INIT;
     94         pthread_once(&flag, [](){ printf("hello, world!\n"); });
     95         return 0;
     96 }
     97 EOF
     98 	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once test.cpp -pthread
     99 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    100 }
    101 
    102 pthread_once_profile_body() {
    103 	atf_expect_fail "profiling option doesn't work now"
    104 	cat > test.cpp << EOF
    105 #include <cstdio>
    106 #include <thread>
    107 int main(void) {
    108         pthread_once_t flag = PTHREAD_ONCE_INIT;
    109         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    110         return 0;
    111 }
    112 EOF
    113 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o pthread_once test.cpp -pthread
    114 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    115 }
    116 
    117 pthread_once_profile_32_body() {
    118 	atf_expect_fail "profiling option doesn't work now"
    119 	# check whether this arch is 64bit
    120 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    121 		atf_skip "this is not a 64 bit architecture"
    122 	fi
    123 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    124 		atf_skip "c++ -m32 not supported on this architecture"
    125 	else
    126 		if fgrep -q _LP64 ./def32; then
    127 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    128 		fi
    129 	fi
    130 
    131 	cat > test.cpp << EOF
    132 #include <cstdio>
    133 #include <thread>
    134 int main(void) {
    135         pthread_once_t flag = PTHREAD_ONCE_INIT;
    136         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    137         return 0;
    138 }
    139 EOF
    140 	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o pthread_once test.cpp -pthread
    141 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    142 	atf_expect_fail "The combination of 32-bit and profiling should be fail"
    143 }
    144 
    145 pthread_once_pic_body() {
    146 	cat > test.cpp << EOF
    147 #include <stdlib.h>
    148 int callpic(void);
    149 int main(void) {callpic();exit(0);}
    150 EOF
    151 	cat > pic.cpp << EOF
    152 #include <cstdio>
    153 #include <thread>
    154 int callpic(void) {
    155         pthread_once_t flag = PTHREAD_ONCE_INIT;
    156         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    157         return 0;
    158 }
    159 EOF
    160 
    161 	atf_check -s exit:0 -o ignore -e ignore \
    162 	    c++ -fPIC -shared -o libtest.so pic.cpp
    163 	atf_check -s exit:0 -o ignore -e ignore \
    164 	    c++ -o pthread_once test.cpp -L. -ltest -pthread
    165 
    166 	export LD_LIBRARY_PATH=.
    167 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    168 }
    169 
    170 pthread_once_pic_32_body() {
    171 	# check whether this arch is 64bit
    172 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    173 		atf_skip "this is not a 64 bit architecture"
    174 	fi
    175 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    176 		atf_skip "c++ -m32 not supported on this architecture"
    177 	else
    178 		if fgrep -q _LP64 ./def32; then
    179 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    180 		fi
    181 	fi
    182 
    183 	cat > test.cpp << EOF
    184 #include <stdlib.h>
    185 int callpic(void);
    186 int main(void) {callpic();exit(0);}
    187 EOF
    188 	cat > pic.cpp << EOF
    189 #include <cstdio>
    190 #include <thread>
    191 int callpic(void) {
    192         pthread_once_t flag = PTHREAD_ONCE_INIT;
    193         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    194         return 0;
    195 }
    196 EOF
    197 
    198 	atf_check -s exit:0 -o ignore -e ignore \
    199 	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
    200 	atf_check -s exit:0 -o ignore -e ignore \
    201 	    c++ -m32 -o pthread_once test.cpp -L. -ltest -pthread
    202 
    203 	export LD_LIBRARY_PATH=.
    204 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    205 }
    206 
    207 pthread_once_pic_profile_body() {
    208 	atf_expect_fail "profiling option doesn't work now"
    209 	cat > test.cpp << EOF
    210 #include <stdlib.h>
    211 int callpic(void);
    212 int main(void) {callpic();exit(0);}
    213 EOF
    214 	cat > pic.cpp << EOF
    215 #include <cstdio>
    216 #include <thread>
    217 int callpic(void) {
    218         pthread_once_t flag = PTHREAD_ONCE_INIT;
    219         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    220         return 0;
    221 }
    222 EOF
    223 
    224 	atf_check -s exit:0 -o ignore -e ignore \
    225 	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
    226 	atf_check -s exit:0 -o ignore -e ignore \
    227 	    c++ -pg -o pthread_once test.cpp -L. -ltest -pthread
    228 
    229 	export LD_LIBRARY_PATH=.
    230 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    231 }
    232 
    233 pthread_once_pic_profile_32_body() {
    234 	atf_expect_fail "profiling option doesn't work now"
    235 	# check whether this arch is 64bit
    236 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    237 		atf_skip "this is not a 64 bit architecture"
    238 	fi
    239 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    240 		atf_skip "c++ -m32 not supported on this architecture"
    241 	else
    242 		if fgrep -q _LP64 ./def32; then
    243 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    244 		fi
    245 	fi
    246 
    247 	cat > test.cpp << EOF
    248 #include <stdlib.h>
    249 int callpic(void);
    250 int main(void) {callpic();exit(0);}
    251 EOF
    252 	cat > pic.cpp << EOF
    253 #include <cstdio>
    254 #include <thread>
    255 int callpic(void) {
    256         pthread_once_t flag = PTHREAD_ONCE_INIT;
    257         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    258         return 0;
    259 }
    260 EOF
    261 
    262 	atf_check -s exit:0 -o ignore -e ignore \
    263 	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
    264 	atf_check -s exit:0 -o ignore -e ignore \
    265 	    c++ -m32 -pg -o pthread_once test.cpp -L. -ltest -pthread
    266 
    267 	export LD_LIBRARY_PATH=.
    268 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    269 }
    270 
    271 pthread_once_pie_body() {
    272 	# check whether this arch supports -pie
    273 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    274 		atf_skip "c++ -pie not supported on this architecture"
    275 	fi
    276 	cat > test.cpp << EOF
    277 #include <cstdio>
    278 #include <thread>
    279 int main(void) {
    280         pthread_once_t flag = PTHREAD_ONCE_INIT;
    281         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    282         return 0;
    283 }
    284 EOF
    285 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o pthread_once test.cpp -pthread
    286 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    287 }
    288 
    289 pthread_once_32_body() {
    290 	# check whether this arch is 64bit
    291 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    292 		atf_skip "this is not a 64 bit architecture"
    293 	fi
    294 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    295 		atf_skip "c++ -m32 not supported on this architecture"
    296 	else
    297 		if fgrep -q _LP64 ./def32; then
    298 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    299 		fi
    300 	fi
    301 
    302 	cat > test.cpp << EOF
    303 #include <cstdio>
    304 #include <thread>
    305 int main(void) {
    306         pthread_once_t flag = PTHREAD_ONCE_INIT;
    307         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    308         return 0;
    309 }
    310 EOF
    311 	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_32 -m32 test.cpp -pthread
    312 	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_64 test.cpp -pthread
    313 	file -b ./pthread_once_32 > ./ftype32
    314 	file -b ./pthread_once_64 > ./ftype64
    315 	if diff ./ftype32 ./ftype64 >/dev/null; then
    316 		atf_fail "generated binaries do not differ"
    317 	fi
    318 	echo "32bit binaries on this platform are:"
    319 	cat ./ftype32
    320 	echo "While native (64bit) binaries are:"
    321 	cat ./ftype64
    322 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once_32
    323 
    324 	# do another test with static 32bit binaries
    325 	cat > test.cpp << EOF
    326 #include <cstdio>
    327 #include <thread>
    328 int main(void) {
    329         pthread_once_t flag = PTHREAD_ONCE_INIT;
    330         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    331         return 0;
    332 }
    333 EOF
    334 	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once -m32 -pthread \
    335 	    -static test.cpp
    336 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    337 }
    338 
    339 pthread_once_static_body() {
    340 	cat > test.cpp << EOF
    341 #include <cstdio>
    342 #include <thread>
    343 int main(void) {
    344         pthread_once_t flag = PTHREAD_ONCE_INIT;
    345         pthread_once(&flag, [](){ printf("hello, world!\n"); });
    346         return 0;
    347 }
    348 EOF
    349 	atf_check -s exit:0 -o ignore -e ignore c++ -static -o pthread_once test.cpp -pthread
    350 	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
    351 }
    352 
    353 atf_init_test_cases()
    354 {
    355 
    356 	atf_add_test_case pthread_once
    357 	atf_add_test_case pthread_once_profile
    358 	atf_add_test_case pthread_once_pic
    359 	atf_add_test_case pthread_once_pie
    360 	atf_add_test_case pthread_once_32
    361 	atf_add_test_case pthread_once_static
    362 	atf_add_test_case pthread_once_pic_32
    363 	atf_add_test_case pthread_once_pic_profile
    364 	atf_add_test_case pthread_once_pic_profile_32
    365 	atf_add_test_case pthread_once_profile_32
    366 }
    367