Home | History | Annotate | Line # | Download | only in c++
      1  1.8     skrll #	$NetBSD: t_call_once2.sh,v 1.8 2022/09/29 07:22:49 skrll Exp $
      2  1.1     kamil #
      3  1.1     kamil # Copyright (c) 2018 The NetBSD Foundation, Inc.
      4  1.1     kamil # All rights reserved.
      5  1.1     kamil #
      6  1.1     kamil # Redistribution and use in source and binary forms, with or without
      7  1.1     kamil # modification, are permitted provided that the following conditions
      8  1.1     kamil # are met:
      9  1.1     kamil # 1. Redistributions of source code must retain the above copyright
     10  1.1     kamil #    notice, this list of conditions and the following disclaimer.
     11  1.1     kamil # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1     kamil #    notice, this list of conditions and the following disclaimer in the
     13  1.1     kamil #    documentation and/or other materials provided with the distribution.
     14  1.1     kamil #
     15  1.1     kamil # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1     kamil # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1     kamil # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1     kamil # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1     kamil # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1     kamil # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1     kamil # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1     kamil # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1     kamil # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1     kamil # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1     kamil # POSSIBILITY OF SUCH DAMAGE.
     26  1.1     kamil #
     27  1.1     kamil 
     28  1.1     kamil atf_test_case call_once2
     29  1.1     kamil call_once2_head() {
     30  1.1     kamil 	atf_set "descr" "compile and run std::call_once"
     31  1.1     kamil 	atf_set "require.progs" "c++"
     32  1.4       rin 	atf_set "timeout" "600"
     33  1.1     kamil }
     34  1.1     kamil 
     35  1.1     kamil atf_test_case call_once2_profile
     36  1.1     kamil call_once2_profile_head() {
     37  1.1     kamil 	atf_set "descr" "compile and run std::call_once with profiling option"
     38  1.1     kamil 	atf_set "require.progs" "c++"
     39  1.4       rin 	atf_set "timeout" "600"
     40  1.1     kamil }
     41  1.1     kamil 
     42  1.1     kamil atf_test_case call_once2_pic
     43  1.1     kamil call_once2_pic_head() {
     44  1.1     kamil 	atf_set "descr" "compile and run PIC std::call_once"
     45  1.1     kamil 	atf_set "require.progs" "c++"
     46  1.4       rin 	atf_set "timeout" "600"
     47  1.1     kamil }
     48  1.1     kamil 
     49  1.1     kamil atf_test_case call_once2_pic_32
     50  1.1     kamil call_once2_pic_32_head() {
     51  1.1     kamil 	atf_set "descr" "compile and run 32-bit PIC std::call_once"
     52  1.1     kamil 	atf_set "require.progs" "c++"
     53  1.4       rin 	atf_set "timeout" "600"
     54  1.1     kamil }
     55  1.1     kamil 
     56  1.1     kamil atf_test_case call_once2_pic_profile
     57  1.3       rin call_once2_pic_profile_head() {
     58  1.1     kamil 	atf_set "descr" "compile and run PIC std::call_once with profiling flag"
     59  1.1     kamil 	atf_set "require.progs" "c++"
     60  1.4       rin 	atf_set "timeout" "600"
     61  1.1     kamil }
     62  1.1     kamil 
     63  1.1     kamil atf_test_case call_once2_pic_profile_32
     64  1.1     kamil call_once2_pic_profile_32_head() {
     65  1.1     kamil 	atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag"
     66  1.1     kamil 	atf_set "require.progs" "c++"
     67  1.4       rin 	atf_set "timeout" "600"
     68  1.1     kamil }
     69  1.1     kamil 
     70  1.1     kamil atf_test_case call_once2_profile_32
     71  1.1     kamil call_once2_profile_32_head() {
     72  1.1     kamil 	atf_set "descr" "compile and run 32-bit std::call_once with profiling flag"
     73  1.1     kamil 	atf_set "require.progs" "c++"
     74  1.4       rin 	atf_set "timeout" "600"
     75  1.1     kamil }
     76  1.1     kamil 
     77  1.1     kamil atf_test_case call_once2_pie
     78  1.1     kamil call_once2_pie_head() {
     79  1.1     kamil 	atf_set "descr" "compile and run position independent (PIE) std::call_once"
     80  1.1     kamil 	atf_set "require.progs" "c++"
     81  1.4       rin 	atf_set "timeout" "600"
     82  1.1     kamil }
     83  1.1     kamil 
     84  1.1     kamil atf_test_case call_once2_32
     85  1.1     kamil call_once2_32_head() {
     86  1.1     kamil 	atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation"
     87  1.1     kamil 	atf_set "require.progs" "c++ file diff cat"
     88  1.4       rin 	atf_set "timeout" "600"
     89  1.1     kamil }
     90  1.1     kamil 
     91  1.1     kamil atf_test_case call_once2_static
     92  1.1     kamil call_once2_static_head() {
     93  1.1     kamil 	atf_set "descr" "compile and run std::call_once with static flag"
     94  1.1     kamil 	atf_set "require.progs" "c++"
     95  1.4       rin 	atf_set "timeout" "600"
     96  1.1     kamil }
     97  1.1     kamil 
     98  1.1     kamil call_once2_body() {
     99  1.1     kamil 	cat > test.cpp << EOF
    100  1.1     kamil #include <mutex>
    101  1.1     kamil #include <thread>
    102  1.1     kamil #include <iostream>
    103  1.1     kamil std::once_flag flag, flag_throw;
    104  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    105  1.1     kamil void throw_once(void) { throw std::exception(); }
    106  1.1     kamil int main(void) {
    107  1.1     kamil         static const int nr_threads(4);
    108  1.1     kamil         std::thread threads[nr_threads];
    109  1.1     kamil 
    110  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    111  1.1     kamil                 threads[i] = std::thread(print_once);
    112  1.1     kamil         }
    113  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    114  1.1     kamil                 threads[i].join();
    115  1.1     kamil         }
    116  1.1     kamil 
    117  1.1     kamil         try {
    118  1.1     kamil                 std::call_once(flag_throw, throw_once);
    119  1.1     kamil         } catch (...) {
    120  1.1     kamil                 std::cout << "world!" << std::endl;
    121  1.1     kamil         }
    122  1.1     kamil         return 0;
    123  1.1     kamil }
    124  1.1     kamil EOF
    125  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 test.cpp -pthread
    126  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    127  1.1     kamil }
    128  1.1     kamil 
    129  1.1     kamil call_once2_profile_body() {
    130  1.2  christos 	atf_expect_fail "profiling option doesn't work with shared libraries"
    131  1.1     kamil 	cat > test.cpp << EOF
    132  1.1     kamil #include <mutex>
    133  1.1     kamil #include <thread>
    134  1.1     kamil #include <iostream>
    135  1.1     kamil std::once_flag flag, flag_throw;
    136  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    137  1.1     kamil void throw_once(void) { throw std::exception(); }
    138  1.1     kamil int main(void) {
    139  1.1     kamil         static const int nr_threads(4);
    140  1.1     kamil         std::thread threads[nr_threads];
    141  1.1     kamil 
    142  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    143  1.1     kamil                 threads[i] = std::thread(print_once);
    144  1.1     kamil         }
    145  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    146  1.1     kamil                 threads[i].join();
    147  1.1     kamil         }
    148  1.1     kamil 
    149  1.1     kamil         try {
    150  1.1     kamil                 std::call_once(flag_throw, throw_once);
    151  1.1     kamil         } catch (...) {
    152  1.1     kamil                 std::cout << "world!" << std::endl;
    153  1.1     kamil         }
    154  1.1     kamil         return 0;
    155  1.1     kamil }
    156  1.1     kamil EOF
    157  1.8     skrll 	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once2 test.cpp -pthread
    158  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    159  1.1     kamil }
    160  1.1     kamil 
    161  1.1     kamil call_once2_profile_32_body() {
    162  1.1     kamil 	atf_expect_fail "profiling option doesn't work now"
    163  1.1     kamil 	# check whether this arch is 64bit
    164  1.1     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    165  1.1     kamil 		atf_skip "this is not a 64 bit architecture"
    166  1.1     kamil 	fi
    167  1.1     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    168  1.1     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    169  1.1     kamil 	else
    170  1.1     kamil 		if fgrep -q _LP64 ./def32; then
    171  1.1     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    172  1.1     kamil 		fi
    173  1.1     kamil 	fi
    174  1.1     kamil 
    175  1.1     kamil 	cat > test.cpp << EOF
    176  1.1     kamil #include <mutex>
    177  1.1     kamil #include <thread>
    178  1.1     kamil #include <iostream>
    179  1.1     kamil std::once_flag flag, flag_throw;
    180  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    181  1.1     kamil void throw_once(void) { throw std::exception(); }
    182  1.1     kamil int main(void) {
    183  1.1     kamil         static const int nr_threads(4);
    184  1.1     kamil         std::thread threads[nr_threads];
    185  1.1     kamil 
    186  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    187  1.1     kamil                 threads[i] = std::thread(print_once);
    188  1.1     kamil         }
    189  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    190  1.1     kamil                 threads[i].join();
    191  1.1     kamil         }
    192  1.1     kamil 
    193  1.1     kamil         try {
    194  1.1     kamil                 std::call_once(flag_throw, throw_once);
    195  1.1     kamil         } catch (...) {
    196  1.1     kamil                 std::cout << "world!" << std::endl;
    197  1.1     kamil         }
    198  1.1     kamil         return 0;
    199  1.1     kamil }
    200  1.1     kamil EOF
    201  1.8     skrll 	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once2 test.cpp -pthread
    202  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    203  1.1     kamil 	atf_expect_fail "The combination of 32-bit and profiling should be fail"
    204  1.1     kamil }
    205  1.1     kamil 
    206  1.1     kamil call_once2_pic_body() {
    207  1.1     kamil 	cat > test.cpp << EOF
    208  1.1     kamil #include <stdlib.h>
    209  1.1     kamil int callpic(void);
    210  1.1     kamil int main(void) {callpic();exit(0);}
    211  1.1     kamil EOF
    212  1.1     kamil 	cat > pic.cpp << EOF
    213  1.1     kamil #include <mutex>
    214  1.1     kamil #include <thread>
    215  1.1     kamil #include <iostream>
    216  1.1     kamil std::once_flag flag, flag_throw;
    217  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    218  1.1     kamil void throw_once(void) { throw std::exception(); }
    219  1.1     kamil int callpic(void) {
    220  1.1     kamil         static const int nr_threads(4);
    221  1.1     kamil         std::thread threads[nr_threads];
    222  1.1     kamil 
    223  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    224  1.1     kamil                 threads[i] = std::thread(print_once);
    225  1.1     kamil         }
    226  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    227  1.1     kamil                 threads[i].join();
    228  1.1     kamil         }
    229  1.1     kamil 
    230  1.1     kamil         try {
    231  1.1     kamil                 std::call_once(flag_throw, throw_once);
    232  1.1     kamil         } catch (...) {
    233  1.1     kamil                 std::cout << "world!" << std::endl;
    234  1.1     kamil         }
    235  1.1     kamil         return 0;
    236  1.1     kamil }
    237  1.1     kamil EOF
    238  1.1     kamil 
    239  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    240  1.1     kamil 	    c++ -fPIC -shared -o libtest.so pic.cpp
    241  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    242  1.1     kamil 	    c++ -o call_once2 test.cpp -L. -ltest -pthread
    243  1.1     kamil 
    244  1.1     kamil 	export LD_LIBRARY_PATH=.
    245  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    246  1.1     kamil }
    247  1.1     kamil 
    248  1.1     kamil call_once2_pic_32_body() {
    249  1.1     kamil 	# check whether this arch is 64bit
    250  1.1     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    251  1.1     kamil 		atf_skip "this is not a 64 bit architecture"
    252  1.1     kamil 	fi
    253  1.1     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    254  1.1     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    255  1.1     kamil 	else
    256  1.1     kamil 		if fgrep -q _LP64 ./def32; then
    257  1.1     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    258  1.1     kamil 		fi
    259  1.1     kamil 	fi
    260  1.1     kamil 
    261  1.1     kamil 	cat > test.cpp << EOF
    262  1.1     kamil #include <stdlib.h>
    263  1.1     kamil int callpic(void);
    264  1.1     kamil int main(void) {callpic();exit(0);}
    265  1.1     kamil EOF
    266  1.1     kamil 	cat > pic.cpp << EOF
    267  1.1     kamil #include <mutex>
    268  1.1     kamil #include <thread>
    269  1.1     kamil #include <iostream>
    270  1.1     kamil std::once_flag flag, flag_throw;
    271  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    272  1.1     kamil void throw_once(void) { throw std::exception(); }
    273  1.1     kamil int callpic(void) {
    274  1.1     kamil         static const int nr_threads(4);
    275  1.1     kamil         std::thread threads[nr_threads];
    276  1.1     kamil 
    277  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    278  1.1     kamil                 threads[i] = std::thread(print_once);
    279  1.1     kamil         }
    280  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    281  1.1     kamil                 threads[i].join();
    282  1.1     kamil         }
    283  1.1     kamil 
    284  1.1     kamil         try {
    285  1.1     kamil                 std::call_once(flag_throw, throw_once);
    286  1.1     kamil         } catch (...) {
    287  1.1     kamil                 std::cout << "world!" << std::endl;
    288  1.1     kamil         }
    289  1.1     kamil         return 0;
    290  1.1     kamil }
    291  1.1     kamil EOF
    292  1.1     kamil 
    293  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    294  1.1     kamil 	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
    295  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    296  1.1     kamil 	    c++ -m32 -o call_once2 test.cpp -L. -ltest -pthread
    297  1.1     kamil 
    298  1.1     kamil 	export LD_LIBRARY_PATH=.
    299  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    300  1.1     kamil }
    301  1.1     kamil 
    302  1.1     kamil call_once2_pic_profile_body() {
    303  1.2  christos 	atf_expect_fail "profiling option doesn't work with pic"
    304  1.1     kamil 	cat > test.cpp << EOF
    305  1.1     kamil #include <stdlib.h>
    306  1.1     kamil int callpic(void);
    307  1.1     kamil int main(void) {callpic();exit(0);}
    308  1.1     kamil EOF
    309  1.1     kamil 	cat > pic.cpp << EOF
    310  1.1     kamil #include <mutex>
    311  1.1     kamil #include <thread>
    312  1.1     kamil #include <iostream>
    313  1.1     kamil std::once_flag flag, flag_throw;
    314  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    315  1.1     kamil void throw_once(void) { throw std::exception(); }
    316  1.1     kamil int callpic(void) {
    317  1.1     kamil         static const int nr_threads(4);
    318  1.1     kamil         std::thread threads[nr_threads];
    319  1.1     kamil 
    320  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    321  1.1     kamil                 threads[i] = std::thread(print_once);
    322  1.1     kamil         }
    323  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    324  1.1     kamil                 threads[i].join();
    325  1.1     kamil         }
    326  1.1     kamil 
    327  1.1     kamil         try {
    328  1.1     kamil                 std::call_once(flag_throw, throw_once);
    329  1.1     kamil         } catch (...) {
    330  1.1     kamil                 std::cout << "world!" << std::endl;
    331  1.1     kamil         }
    332  1.1     kamil         return 0;
    333  1.1     kamil }
    334  1.1     kamil EOF
    335  1.1     kamil 
    336  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    337  1.1     kamil 	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
    338  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    339  1.1     kamil 	    c++ -pg -o call_once2 test.cpp -L. -ltest -pthread
    340  1.1     kamil 
    341  1.1     kamil 	export LD_LIBRARY_PATH=.
    342  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    343  1.1     kamil }
    344  1.1     kamil 
    345  1.1     kamil call_once2_pic_profile_32_body() {
    346  1.2  christos 	atf_expect_fail "profiling option doesn't work with shared libraries"
    347  1.1     kamil 	# check whether this arch is 64bit
    348  1.1     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    349  1.1     kamil 		atf_skip "this is not a 64 bit architecture"
    350  1.1     kamil 	fi
    351  1.1     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    352  1.1     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    353  1.1     kamil 	else
    354  1.1     kamil 		if fgrep -q _LP64 ./def32; then
    355  1.1     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    356  1.1     kamil 		fi
    357  1.1     kamil 	fi
    358  1.1     kamil 
    359  1.1     kamil 	cat > test.cpp << EOF
    360  1.1     kamil #include <stdlib.h>
    361  1.1     kamil int callpic(void);
    362  1.1     kamil int main(void) {callpic();exit(0);}
    363  1.1     kamil EOF
    364  1.1     kamil 	cat > pic.cpp << EOF
    365  1.1     kamil #include <mutex>
    366  1.1     kamil #include <thread>
    367  1.1     kamil #include <iostream>
    368  1.1     kamil std::once_flag flag, flag_throw;
    369  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    370  1.1     kamil void throw_once(void) { throw std::exception(); }
    371  1.1     kamil int callpic(void) {
    372  1.1     kamil         static const int nr_threads(4);
    373  1.1     kamil         std::thread threads[nr_threads];
    374  1.1     kamil 
    375  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    376  1.1     kamil                 threads[i] = std::thread(print_once);
    377  1.1     kamil         }
    378  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    379  1.1     kamil                 threads[i].join();
    380  1.1     kamil         }
    381  1.1     kamil 
    382  1.1     kamil         try {
    383  1.1     kamil                 std::call_once(flag_throw, throw_once);
    384  1.1     kamil         } catch (...) {
    385  1.1     kamil                 std::cout << "world!" << std::endl;
    386  1.1     kamil         }
    387  1.1     kamil         return 0;
    388  1.1     kamil }
    389  1.1     kamil EOF
    390  1.1     kamil 
    391  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    392  1.1     kamil 	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
    393  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore \
    394  1.1     kamil 	    c++ -m32 -pg -o call_once2 test.cpp -L. -ltest -pthread
    395  1.1     kamil 
    396  1.1     kamil 	export LD_LIBRARY_PATH=.
    397  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    398  1.1     kamil }
    399  1.1     kamil 
    400  1.1     kamil call_once2_pie_body() {
    401  1.1     kamil 	# check whether this arch supports -pie
    402  1.1     kamil 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    403  1.1     kamil 		atf_skip "c++ -pie not supported on this architecture"
    404  1.1     kamil 	fi
    405  1.1     kamil 	cat > test.cpp << EOF
    406  1.1     kamil #include <mutex>
    407  1.1     kamil #include <thread>
    408  1.1     kamil #include <iostream>
    409  1.1     kamil std::once_flag flag, flag_throw;
    410  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    411  1.1     kamil void throw_once(void) { throw std::exception(); }
    412  1.1     kamil int main(void) {
    413  1.1     kamil         static const int nr_threads(4);
    414  1.1     kamil         std::thread threads[nr_threads];
    415  1.1     kamil 
    416  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    417  1.1     kamil                 threads[i] = std::thread(print_once);
    418  1.1     kamil         }
    419  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    420  1.1     kamil                 threads[i].join();
    421  1.1     kamil         }
    422  1.1     kamil 
    423  1.1     kamil         try {
    424  1.1     kamil                 std::call_once(flag_throw, throw_once);
    425  1.1     kamil         } catch (...) {
    426  1.1     kamil                 std::cout << "world!" << std::endl;
    427  1.1     kamil         }
    428  1.1     kamil         return 0;
    429  1.1     kamil }
    430  1.1     kamil EOF
    431  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once2 test.cpp -pthread
    432  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    433  1.1     kamil }
    434  1.1     kamil 
    435  1.1     kamil call_once2_32_body() {
    436  1.1     kamil 	# check whether this arch is 64bit
    437  1.1     kamil 	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
    438  1.1     kamil 		atf_skip "this is not a 64 bit architecture"
    439  1.1     kamil 	fi
    440  1.1     kamil 	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    441  1.1     kamil 		atf_skip "c++ -m32 not supported on this architecture"
    442  1.1     kamil 	else
    443  1.1     kamil 		if fgrep -q _LP64 ./def32; then
    444  1.1     kamil 			atf_fail "c++ -m32 does not generate netbsd32 binaries"
    445  1.1     kamil 		fi
    446  1.1     kamil 	fi
    447  1.1     kamil 
    448  1.1     kamil 	cat > test.cpp << EOF
    449  1.1     kamil #include <mutex>
    450  1.1     kamil #include <thread>
    451  1.1     kamil #include <iostream>
    452  1.1     kamil std::once_flag flag, flag_throw;
    453  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    454  1.1     kamil void throw_once(void) { throw std::exception(); }
    455  1.1     kamil int main(void) {
    456  1.1     kamil         static const int nr_threads(4);
    457  1.1     kamil         std::thread threads[nr_threads];
    458  1.1     kamil 
    459  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    460  1.1     kamil                 threads[i] = std::thread(print_once);
    461  1.1     kamil         }
    462  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    463  1.1     kamil                 threads[i].join();
    464  1.1     kamil         }
    465  1.1     kamil 
    466  1.1     kamil         try {
    467  1.1     kamil                 std::call_once(flag_throw, throw_once);
    468  1.1     kamil         } catch (...) {
    469  1.1     kamil                 std::cout << "world!" << std::endl;
    470  1.1     kamil         }
    471  1.1     kamil         return 0;
    472  1.1     kamil }
    473  1.1     kamil EOF
    474  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_32 -m32 test.cpp -pthread
    475  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_64 test.cpp -pthread
    476  1.1     kamil 	file -b ./call_once2_32 > ./ftype32
    477  1.1     kamil 	file -b ./call_once2_64 > ./ftype64
    478  1.1     kamil 	if diff ./ftype32 ./ftype64 >/dev/null; then
    479  1.1     kamil 		atf_fail "generated binaries do not differ"
    480  1.1     kamil 	fi
    481  1.1     kamil 	echo "32bit binaries on this platform are:"
    482  1.1     kamil 	cat ./ftype32
    483  1.1     kamil 	echo "While native (64bit) binaries are:"
    484  1.1     kamil 	cat ./ftype64
    485  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2_32
    486  1.1     kamil 
    487  1.1     kamil 	# do another test with static 32bit binaries
    488  1.1     kamil 	cat > test.cpp << EOF
    489  1.1     kamil #include <mutex>
    490  1.1     kamil #include <thread>
    491  1.1     kamil #include <iostream>
    492  1.1     kamil std::once_flag flag, flag_throw;
    493  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    494  1.1     kamil void throw_once(void) { throw std::exception(); }
    495  1.1     kamil int main(void) {
    496  1.1     kamil         static const int nr_threads(4);
    497  1.1     kamil         std::thread threads[nr_threads];
    498  1.1     kamil 
    499  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    500  1.1     kamil                 threads[i] = std::thread(print_once);
    501  1.1     kamil         }
    502  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    503  1.1     kamil                 threads[i].join();
    504  1.1     kamil         }
    505  1.1     kamil 
    506  1.1     kamil         try {
    507  1.1     kamil                 std::call_once(flag_throw, throw_once);
    508  1.1     kamil         } catch (...) {
    509  1.1     kamil                 std::cout << "world!" << std::endl;
    510  1.1     kamil         }
    511  1.1     kamil         return 0;
    512  1.1     kamil }
    513  1.1     kamil EOF
    514  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 -m32 -pthread \
    515  1.1     kamil 	    -static test.cpp
    516  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    517  1.1     kamil }
    518  1.1     kamil 
    519  1.1     kamil call_once2_static_body() {
    520  1.1     kamil 	cat > test.cpp << EOF
    521  1.1     kamil #include <mutex>
    522  1.1     kamil #include <thread>
    523  1.1     kamil #include <iostream>
    524  1.1     kamil std::once_flag flag, flag_throw;
    525  1.1     kamil void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
    526  1.1     kamil void throw_once(void) { throw std::exception(); }
    527  1.1     kamil int main(void) {
    528  1.1     kamil         static const int nr_threads(4);
    529  1.1     kamil         std::thread threads[nr_threads];
    530  1.1     kamil 
    531  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    532  1.1     kamil                 threads[i] = std::thread(print_once);
    533  1.1     kamil         }
    534  1.1     kamil         for (int i = 0; i < nr_threads; ++i) {
    535  1.1     kamil                 threads[i].join();
    536  1.1     kamil         }
    537  1.1     kamil 
    538  1.1     kamil         try {
    539  1.1     kamil                 std::call_once(flag_throw, throw_once);
    540  1.1     kamil         } catch (...) {
    541  1.1     kamil                 std::cout << "world!" << std::endl;
    542  1.1     kamil         }
    543  1.1     kamil         return 0;
    544  1.1     kamil }
    545  1.1     kamil EOF
    546  1.1     kamil 	atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once2 test.cpp -pthread
    547  1.1     kamil 	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
    548  1.1     kamil }
    549  1.1     kamil 
    550  1.1     kamil atf_init_test_cases()
    551  1.1     kamil {
    552  1.1     kamil 
    553  1.1     kamil 	atf_add_test_case call_once2
    554  1.1     kamil 	atf_add_test_case call_once2_profile
    555  1.1     kamil 	atf_add_test_case call_once2_pic
    556  1.1     kamil 	atf_add_test_case call_once2_pie
    557  1.1     kamil 	atf_add_test_case call_once2_32
    558  1.1     kamil 	atf_add_test_case call_once2_static
    559  1.1     kamil 	atf_add_test_case call_once2_pic_32
    560  1.1     kamil 	atf_add_test_case call_once2_pic_profile
    561  1.1     kamil 	atf_add_test_case call_once2_pic_profile_32
    562  1.1     kamil 	atf_add_test_case call_once2_profile_32
    563  1.1     kamil }
    564