Module Name:    src
Committed By:   kamil
Date:           Sat Mar 24 00:26:51 UTC 2018

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/c++: Makefile t_cxxruntime.sh t_hello.sh
            t_static_destructor.sh
Added Files:
        src/tests/usr.bin/c++: t_call_once.sh t_call_once2.sh t_pthread_once.sh

Log Message:
Add new C++ ATF tests

Add new variations for existing C++ tests:
 - Static
 - Profile+32-bit
 - PIC+32-bit
 - PIC+Profile
 - PIC+Profile+32-bit

All tests pass for NetBSD/amd64:
 - t_cxxruntime
 - t_hello
 - t_static_destructor

+--------------------------------------------------------------+
| Options            | cxxruntime | hello  | static_destructor |
+--------------------------------------------------------------+
| None               | Passed     | Passed | Passed            |
| 32-bit             | Passed     | Passed | Passed            |
| PIC                | Passed     | Passed | Passed            |
| PIE                | Passed     | Passed | Passed            |
| Profile            | Passed     | Passed | Passed            |
| Static             | Passed     | Passed | Passed            |
| Profile+32-bit     | Passed     | Passed | Passed            |
| PIC+32-bit         | Passed     | Passed | Passed            |
| PIC+Profile        | Passed     | Passed | Passed            |
| PIC+Profile+32-bit | Passed     | Passed | Passed            |
+--------------------------------------------------------------+

Add new C++11 std::call_once tests:
 - t_call_once
 - t_call_once2

Add new C++11 test with pthread_once(3) and C++ lambda:
 - t_pthread_once

All tests with the profile option for std::call_once and
pthread_once(3) are marked as expected failure (NetBSD/amd64).

Results for *_once*:
+------------------------------------------------------------+
| Options            | call_once | call_once2 | pthread_once |
+------------------------------------------------------------+
| None               | Passed    | Passed     | Passed       |
| 32-bit             | Passed    |  Passed    | Passed       |
| PIC                | Passed    | Passed     | Passed       |
| PIE                | Passed    | Passed     | Passed       |
| Profile            |  Failed   |  Failed    |  Failed      |
| Static             | Passed    | Passed     | Passed       |
| Profile+32-bit     |  Failed   |  Failed    |  Failed      |
| PIC+32-bit         | Passed    | Passed     | Passed       |
| PIC+Profile        |  Failed   |  Failed    |  Failed      |
| PIC+Profile+32-bit |  Failed   |  Failed    |  Failed      |
+------------------------------------------------------------+

Long term there is an option to refacotr the framework for C and C++ tests,
in order to reduce code duplication.

Patches sent by Yang Zheng <tomsun....@gmail.com>


To generate a diff of this commit:
cvs rdiff -u -r1.777 -r1.778 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/c++/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/c++/t_call_once.sh \
    src/tests/usr.bin/c++/t_call_once2.sh \
    src/tests/usr.bin/c++/t_pthread_once.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/c++/t_cxxruntime.sh \
    src/tests/usr.bin/c++/t_hello.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/c++/t_static_destructor.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.777 src/distrib/sets/lists/tests/mi:1.778
--- src/distrib/sets/lists/tests/mi:1.777	Wed Mar 14 02:13:47 2018
+++ src/distrib/sets/lists/tests/mi	Sat Mar 24 00:26:51 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.777 2018/03/14 02:13:47 kamil Exp $
+# $NetBSD: mi,v 1.778 2018/03/24 00:26:51 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3638,6 +3638,9 @@
 ./usr/tests/usr.bin/c++/t_cxxruntime		tests-usr.bin-tests	compattestfile,atf,cxx
 ./usr/tests/usr.bin/c++/t_hello			tests-usr.bin-tests	compattestfile,atf,cxx
 ./usr/tests/usr.bin/c++/t_static_destructor	tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_call_once		tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_call_once2		tests-usr.bin-tests	compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_pthread_once		tests-usr.bin-tests	compattestfile,atf,cxx
 ./usr/tests/usr.bin/cc				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/cc/Atffile			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/cc/Kyuafile			tests-usr.bin-tests	compattestfile,atf,kyua

Index: src/tests/usr.bin/c++/Makefile
diff -u src/tests/usr.bin/c++/Makefile:1.3 src/tests/usr.bin/c++/Makefile:1.4
--- src/tests/usr.bin/c++/Makefile:1.3	Sun May 14 02:02:25 2017
+++ src/tests/usr.bin/c++/Makefile	Sat Mar 24 00:26:51 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2017/05/14 02:02:25 kamil Exp $
+# $NetBSD: Makefile,v 1.4 2018/03/24 00:26:51 kamil Exp $
 
 .include <bsd.own.mk>
 
@@ -7,5 +7,8 @@ TESTSDIR=	${TESTSBASE}/usr.bin/c++
 TESTS_SH=	t_cxxruntime
 TESTS_SH+=	t_hello
 TESTS_SH+=	t_static_destructor
+TESTS_SH+=	t_call_once
+TESTS_SH+=	t_call_once2
+TESTS_SH+=	t_pthread_once
 
 .include <bsd.test.mk>

Index: src/tests/usr.bin/c++/t_cxxruntime.sh
diff -u src/tests/usr.bin/c++/t_cxxruntime.sh:1.2 src/tests/usr.bin/c++/t_cxxruntime.sh:1.3
--- src/tests/usr.bin/c++/t_cxxruntime.sh:1.2	Sun May 14 01:13:44 2017
+++ src/tests/usr.bin/c++/t_cxxruntime.sh	Sat Mar 24 00:26:51 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_cxxruntime.sh,v 1.2 2017/05/14 01:13:44 kamil Exp $
+#	$NetBSD: t_cxxruntime.sh,v 1.3 2018/03/24 00:26:51 kamil Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -34,12 +34,48 @@ cxxruntime_head() {
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case cxxruntime_profile
+cxxruntime_profile_head() {
+	atf_set "descr" "compile and run \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case cxxruntime_profile_32
+cxxruntime_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case cxxruntime_static
+cxxruntime_static_head() {
+	atf_set "descr" "compile and run \"hello world\" with static flags"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case cxxruntime_pic
 cxxruntime_pic_head() {
 	atf_set "descr" "compile and run PIC \"hello world\""
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case cxxruntime_pic_32
+cxxruntime_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\""
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case cxxruntime_pic_profile
+cxxruntime_pic_profile_head() {
+	atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case cxxruntime_pic_profile_32
+cxxruntime_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case cxxruntime_pie
 cxxruntime_pie_head() {
 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
@@ -62,6 +98,48 @@ EOF
 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
 }
 
+cxxruntime_profile_body() {
+	cat > test.cpp << EOF
+#include <cstdlib>
+#include <iostream>
+int main(void) {std::cout << "hello world" << std::endl;exit(0);}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+cxxruntime_profile_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdlib>
+#include <iostream>
+int main(void) {std::cout << "hello world" << std::endl;exit(0);}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+cxxruntime_static_body() {
+	cat > test.cpp << EOF
+#include <cstdlib>
+#include <iostream>
+int main(void) {std::cout << "hello world" << std::endl;exit(0);}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
 cxxruntime_pic_body() {
 	cat > test.cpp << EOF
 #include <cstdlib>
@@ -82,6 +160,90 @@ EOF
 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
 }
 
+cxxruntime_pic_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+cxxruntime_pic_profile_body() {
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+cxxruntime_pic_profile_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+int callpic(void) {std::cout << "hello world" << std::endl;return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
 cxxruntime_pie_body() {
 	# check whether this arch supports -pie
 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
@@ -140,9 +302,14 @@ EOF
 
 atf_init_test_cases()
 {
-
 	atf_add_test_case cxxruntime
+	atf_add_test_case cxxruntime_profile
 	atf_add_test_case cxxruntime_pic
 	atf_add_test_case cxxruntime_pie
 	atf_add_test_case cxxruntime32
+	atf_add_test_case cxxruntime_static
+	atf_add_test_case cxxruntime_pic_32
+	atf_add_test_case cxxruntime_pic_profile
+	atf_add_test_case cxxruntime_pic_profile_32
+	atf_add_test_case cxxruntime_profile_32
 }
Index: src/tests/usr.bin/c++/t_hello.sh
diff -u src/tests/usr.bin/c++/t_hello.sh:1.2 src/tests/usr.bin/c++/t_hello.sh:1.3
--- src/tests/usr.bin/c++/t_hello.sh:1.2	Thu May 18 10:29:47 2017
+++ src/tests/usr.bin/c++/t_hello.sh	Sat Mar 24 00:26:51 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_hello.sh,v 1.2 2017/05/18 10:29:47 martin Exp $
+#	$NetBSD: t_hello.sh,v 1.3 2018/03/24 00:26:51 kamil Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -32,17 +32,47 @@ hello_head() {
 }
 
 atf_test_case hello_profile
-hello_head() {
+hello_profile_head() {
 	atf_set "descr" "compile and run \"hello world\" with profiling option"
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case hello_profile
+hello_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case hello_static
+hello_static_head() {
+	atf_set "descr" "compile and run \"hello world\" with static option"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case hello_pic
 hello_pic_head() {
 	atf_set "descr" "compile and run PIC \"hello world\""
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case hello_pic_32
+hello_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\""
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case hello_pic_profile
+hello_pic_profile_head() {
+	atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case hello_pic_profile_32
+hello_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case hello_pie
 hello_pie_head() {
 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
@@ -75,6 +105,38 @@ EOF
 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
 }
 
+hello_profile_32_body() {
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdio.h>
+#include <stdlib.h>
+int main(void) {printf("hello world\n");exit(0);}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+
+hello_static_body() {
+	cat > test.cpp << EOF
+#include <stdio.h>
+#include <stdlib.h>
+int main(void) {printf("hello world\n");exit(0);}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
 hello_pic_body() {
 	cat > test.cpp << EOF
 #include <stdlib.h>
@@ -95,6 +157,87 @@ EOF
 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
 }
 
+hello_pic_32_body() {
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <stdio.h>
+int callpic(void) {printf("hello world\n");return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+hello_pic_profile_body() {
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <stdio.h>
+int callpic(void) {printf("hello world\n");return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
+hello_pic_profile_32_body() {
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <stdio.h>
+int callpic(void) {printf("hello world\n");return 0;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello world\n" ./hello
+}
+
 hello_pie_body() {
 	# check whether this arch supports -pie
 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
@@ -159,4 +302,9 @@ atf_init_test_cases()
 	atf_add_test_case hello_pic
 	atf_add_test_case hello_pie
 	atf_add_test_case hello32
+	atf_add_test_case hello_static
+	atf_add_test_case hello_pic_32
+	atf_add_test_case hello_pic_profile
+	atf_add_test_case hello_pic_profile_32
+	atf_add_test_case hello_profile_32
 }

Index: src/tests/usr.bin/c++/t_static_destructor.sh
diff -u src/tests/usr.bin/c++/t_static_destructor.sh:1.1 src/tests/usr.bin/c++/t_static_destructor.sh:1.2
--- src/tests/usr.bin/c++/t_static_destructor.sh:1.1	Sun May 14 02:02:25 2017
+++ src/tests/usr.bin/c++/t_static_destructor.sh	Sat Mar 24 00:26:51 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_static_destructor.sh,v 1.1 2017/05/14 02:02:25 kamil Exp $
+#	$NetBSD: t_static_destructor.sh,v 1.2 2018/03/24 00:26:51 kamil Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -34,12 +34,48 @@ static_destructor_head() {
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case static_destructor_profile
+static_destructor_profile_head() {
+	atf_set "descr" "compile and run \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case static_destructor_static
+static_destructor_static_head() {
+	atf_set "descr" "compile and run \"hello world\" with static option"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case static_destructor_pic
 static_destructor_pic_head() {
 	atf_set "descr" "compile and run PIC \"hello world\""
 	atf_set "require.progs" "c++"
 }
 
+atf_test_case static_destructor_pic_32
+static_destructor_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\""
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case static_destructor_pic_profile
+static_destructor_pic_profile_head() {
+	atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case static_destructor_pic_profile_32
+static_destructor_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case static_destructor_profile_32
+static_destructor_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
+	atf_set "require.progs" "c++"
+}
+
 atf_test_case static_destructor_pie
 static_destructor_pie_head() {
 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
@@ -71,6 +107,76 @@ EOF
 	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
 }
 
+static_destructor_profile_body() {
+	cat > test.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int main(void) {struct B b;return 0;}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
+static_destructor_profile_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int main(void) {struct B b;return 0;}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o hello test.cpp
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
+
+static_destructor_static_body() {
+	cat > test.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int main(void) {struct B b;return 0;}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
 static_destructor_pic_body() {
 	cat > test.cpp << EOF
 #include <cstdlib>
@@ -101,6 +207,120 @@ EOF
 	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
 }
 
+static_destructor_pic_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int callpic(void) {struct B b;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
+static_destructor_pic_profile_body() {
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int callpic(void) {struct B b;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
+static_destructor_pic_profile_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdlib>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <iostream>
+struct A {
+	int i;
+	A(int i):i(i){std::cout << "CTOR A" << std::endl;}
+	~A() {std::cout << "DTOR A:" << i << std::endl;}
+};
+struct B {
+	A *m_a;
+	B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
+	~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
+};
+int callpic(void) {struct B b;}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o hello test.cpp -L. -ltest
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello
+}
+
 static_destructor_pie_body() {
 	# check whether this arch supports -pie
 	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
@@ -188,7 +408,13 @@ atf_init_test_cases()
 {
 
 	atf_add_test_case static_destructor
+	atf_add_test_case static_destructor_profile
 	atf_add_test_case static_destructor_pic
 	atf_add_test_case static_destructor_pie
 	atf_add_test_case static_destructor32
+	atf_add_test_case static_destructor_static
+	atf_add_test_case static_destructor_pic_32
+	atf_add_test_case static_destructor_pic_profile
+	atf_add_test_case static_destructor_pic_profile_32
+	atf_add_test_case static_destructor_profile_32
 }

Added files:

Index: src/tests/usr.bin/c++/t_call_once.sh
diff -u /dev/null src/tests/usr.bin/c++/t_call_once.sh:1.1
--- /dev/null	Sat Mar 24 00:26:51 2018
+++ src/tests/usr.bin/c++/t_call_once.sh	Sat Mar 24 00:26:51 2018
@@ -0,0 +1,377 @@
+#	$NetBSD: t_call_once.sh,v 1.1 2018/03/24 00:26:51 kamil Exp $
+#
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case call_once
+call_once_head() {
+	atf_set "descr" "compile and run std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_profile
+call_once_profile_head() {
+	atf_set "descr" "compile and run std::call_once with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_pic
+call_once_pic_head() {
+	atf_set "descr" "compile and run PIC std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_pic_32
+call_once_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_pic_profile
+call_once_pic_head() {
+	atf_set "descr" "compile and run PIC std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_pic_profile_32
+call_once_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_profile_32
+call_once_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_pie
+call_once_pie_head() {
+	atf_set "descr" "compile and run position independent (PIE) std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once_32
+call_once_32_head() {
+	atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation"
+	atf_set "require.progs" "c++ file diff cat"
+}
+
+atf_test_case call_once_static
+call_once_static_head() {
+	atf_set "descr" "compile and run std::call_once with static flag"
+	atf_set "require.progs" "c++"
+}
+
+call_once_body() {
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+	atf_expect_fail "The combination of 32-bit and profiling should be fail"
+}
+
+call_once_pic_body() {
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int callpic(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -o call_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_pic_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int callpic(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o call_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_pic_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int callpic(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o call_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_pic_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int callpic(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o call_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_pie_body() {
+	# check whether this arch supports -pie
+	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
+		atf_skip "c++ -pie not supported on this architecture"
+	fi
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_32 -m32 test.cpp -pthread
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once_64 test.cpp -pthread
+	file -b ./call_once_32 > ./ftype32
+	file -b ./call_once_64 > ./ftype64
+	if diff ./ftype32 ./ftype64 >/dev/null; then
+		atf_fail "generated binaries do not differ"
+	fi
+	echo "32bit binaries on this platform are:"
+	cat ./ftype32
+	echo "While native (64bit) binaries are:"
+	cat ./ftype64
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once_32
+
+	# do another test with static 32bit binaries
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once -m32 -pthread \
+	    -static test.cpp
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+call_once_static_body() {
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+#include <mutex>
+std::once_flag flag;
+int main(void) {
+        std::call_once(flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once
+}
+
+atf_init_test_cases()
+{
+
+	atf_add_test_case call_once
+	atf_add_test_case call_once_profile
+	atf_add_test_case call_once_pic
+	atf_add_test_case call_once_pie
+	atf_add_test_case call_once_32
+	atf_add_test_case call_once_static
+	atf_add_test_case call_once_pic_32
+	atf_add_test_case call_once_pic_profile
+	atf_add_test_case call_once_pic_profile_32
+	atf_add_test_case call_once_profile_32
+}
Index: src/tests/usr.bin/c++/t_call_once2.sh
diff -u /dev/null src/tests/usr.bin/c++/t_call_once2.sh:1.1
--- /dev/null	Sat Mar 24 00:26:51 2018
+++ src/tests/usr.bin/c++/t_call_once2.sh	Sat Mar 24 00:26:51 2018
@@ -0,0 +1,553 @@
+#	$NetBSD: t_call_once2.sh,v 1.1 2018/03/24 00:26:51 kamil Exp $
+#
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case call_once2
+call_once2_head() {
+	atf_set "descr" "compile and run std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_profile
+call_once2_profile_head() {
+	atf_set "descr" "compile and run std::call_once with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_pic
+call_once2_pic_head() {
+	atf_set "descr" "compile and run PIC std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_pic_32
+call_once2_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_pic_profile
+call_once2_pic_head() {
+	atf_set "descr" "compile and run PIC std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_pic_profile_32
+call_once2_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_profile_32
+call_once2_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit std::call_once with profiling flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_pie
+call_once2_pie_head() {
+	atf_set "descr" "compile and run position independent (PIE) std::call_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case call_once2_32
+call_once2_32_head() {
+	atf_set "descr" "compile and run std::call_once for/in netbsd32 emulation"
+	atf_set "require.progs" "c++ file diff cat"
+}
+
+atf_test_case call_once2_static
+call_once2_static_head() {
+	atf_set "descr" "compile and run std::call_once with static flag"
+	atf_set "require.progs" "c++"
+}
+
+call_once2_body() {
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o call_once2 test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o call_once2 test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+	atf_expect_fail "The combination of 32-bit and profiling should be fail"
+}
+
+call_once2_pic_body() {
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int callpic(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -o call_once2 test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_pic_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int callpic(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o call_once2 test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_pic_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int callpic(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o call_once2 test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_pic_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int callpic(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o call_once2 test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_pie_body() {
+	# check whether this arch supports -pie
+	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
+		atf_skip "c++ -pie not supported on this architecture"
+	fi
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o call_once2 test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_32 -m32 test.cpp -pthread
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2_64 test.cpp -pthread
+	file -b ./call_once2_32 > ./ftype32
+	file -b ./call_once2_64 > ./ftype64
+	if diff ./ftype32 ./ftype64 >/dev/null; then
+		atf_fail "generated binaries do not differ"
+	fi
+	echo "32bit binaries on this platform are:"
+	cat ./ftype32
+	echo "While native (64bit) binaries are:"
+	cat ./ftype64
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2_32
+
+	# do another test with static 32bit binaries
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o call_once2 -m32 -pthread \
+	    -static test.cpp
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+call_once2_static_body() {
+	cat > test.cpp << EOF
+#include <mutex>
+#include <thread>
+#include <iostream>
+std::once_flag flag, flag_throw;
+void print_once(void) { std::call_once(flag, [](){ std::cout << "hello, " << std::flush; }); }
+void throw_once(void) { throw std::exception(); }
+int main(void) {
+        static const int nr_threads(4);
+        std::thread threads[nr_threads];
+
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i] = std::thread(print_once);
+        }
+        for (int i = 0; i < nr_threads; ++i) {
+                threads[i].join();
+        }
+
+        try {
+                std::call_once(flag_throw, throw_once);
+        } catch (...) {
+                std::cout << "world!" << std::endl;
+        }
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o call_once2 test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./call_once2
+}
+
+atf_init_test_cases()
+{
+
+	atf_add_test_case call_once2
+	atf_add_test_case call_once2_profile
+	atf_add_test_case call_once2_pic
+	atf_add_test_case call_once2_pie
+	atf_add_test_case call_once2_32
+	atf_add_test_case call_once2_static
+	atf_add_test_case call_once2_pic_32
+	atf_add_test_case call_once2_pic_profile
+	atf_add_test_case call_once2_pic_profile_32
+	atf_add_test_case call_once2_profile_32
+}
Index: src/tests/usr.bin/c++/t_pthread_once.sh
diff -u /dev/null src/tests/usr.bin/c++/t_pthread_once.sh:1.1
--- /dev/null	Sat Mar 24 00:26:51 2018
+++ src/tests/usr.bin/c++/t_pthread_once.sh	Sat Mar 24 00:26:51 2018
@@ -0,0 +1,366 @@
+#	$NetBSD: t_pthread_once.sh,v 1.1 2018/03/24 00:26:51 kamil Exp $
+#
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case pthread_once
+pthread_once_head() {
+	atf_set "descr" "compile and run std::pthread_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_profile
+pthread_once_profile_head() {
+	atf_set "descr" "compile and run std::pthread_once with profiling option"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_pic
+pthread_once_pic_head() {
+	atf_set "descr" "compile and run PIC std::pthread_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_pic_32
+pthread_once_pic_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::pthread_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_pic_profile
+pthread_once_pic_head() {
+	atf_set "descr" "compile and run PIC std::pthread_once with profiling &flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_pic_profile_32
+pthread_once_pic_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit PIC std::pthread_once with profiling &flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_profile_32
+pthread_once_profile_32_head() {
+	atf_set "descr" "compile and run 32-bit std::pthread_once with profiling &flag"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_pie
+pthread_once_pie_head() {
+	atf_set "descr" "compile and run position independent (PIE) std::pthread_once"
+	atf_set "require.progs" "c++"
+}
+
+atf_test_case pthread_once_32
+pthread_once_32_head() {
+	atf_set "descr" "compile and run std::pthread_once for/in netbsd32 emulation"
+	atf_set "require.progs" "c++ file diff cat"
+}
+
+atf_test_case pthread_once_static
+pthread_once_static_head() {
+	atf_set "descr" "compile and run std::pthread_once with static &flag"
+	atf_set "require.progs" "c++"
+}
+
+pthread_once_body() {
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o pthread_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -m32 -pg -o pthread_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+	atf_expect_fail "The combination of 32-bit and profiling should be fail"
+}
+
+pthread_once_pic_body() {
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+int callpic(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -o pthread_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_pic_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+int callpic(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -o pthread_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_pic_profile_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+int callpic(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -pg -o pthread_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_pic_profile_32_body() {
+	atf_expect_fail "profiling option doesn't work now"
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <stdlib.h>
+int callpic(void);
+int main(void) {callpic();exit(0);}
+EOF
+	cat > pic.cpp << EOF
+#include <cstdio>
+#include <thread>
+int callpic(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
+	atf_check -s exit:0 -o ignore -e ignore \
+	    c++ -m32 -pg -o pthread_once test.cpp -L. -ltest -pthread
+
+	export LD_LIBRARY_PATH=.
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_pie_body() {
+	# check whether this arch supports -pie
+	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
+		atf_skip "c++ -pie not supported on this architecture"
+	fi
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o pthread_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_32_body() {
+	# check whether this arch is 64bit
+	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+	fi
+	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+		fi
+	fi
+
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_32 -m32 test.cpp -pthread
+	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once_64 test.cpp -pthread
+	file -b ./pthread_once_32 > ./ftype32
+	file -b ./pthread_once_64 > ./ftype64
+	if diff ./ftype32 ./ftype64 >/dev/null; then
+		atf_fail "generated binaries do not differ"
+	fi
+	echo "32bit binaries on this platform are:"
+	cat ./ftype32
+	echo "While native (64bit) binaries are:"
+	cat ./ftype64
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once_32
+
+	# do another test with static 32bit binaries
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -o pthread_once -m32 -pthread \
+	    -static test.cpp
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+pthread_once_static_body() {
+	cat > test.cpp << EOF
+#include <cstdio>
+#include <thread>
+int main(void) {
+        pthread_once_t flag = PTHREAD_ONCE_INIT;
+        pthread_once(&flag, [](){ printf("hello, world!\n"); });
+        return 0;
+}
+EOF
+	atf_check -s exit:0 -o ignore -e ignore c++ -static -o pthread_once test.cpp -pthread
+	atf_check -s exit:0 -o inline:"hello, world!\n" ./pthread_once
+}
+
+atf_init_test_cases()
+{
+
+	atf_add_test_case pthread_once
+	atf_add_test_case pthread_once_profile
+	atf_add_test_case pthread_once_pic
+	atf_add_test_case pthread_once_pie
+	atf_add_test_case pthread_once_32
+	atf_add_test_case pthread_once_static
+	atf_add_test_case pthread_once_pic_32
+	atf_add_test_case pthread_once_pic_profile
+	atf_add_test_case pthread_once_pic_profile_32
+	atf_add_test_case pthread_once_profile_32
+}

Reply via email to