Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/cc Add ATF c and c++ tests for TSan, MSan, lib...



details:   https://anonhg.NetBSD.org/src/rev/414d0afe3218
branches:  trunk
changeset: 964824:414d0afe3218
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Aug 18 20:15:58 2019 +0000

description:
Add ATF c and c++ tests for TSan, MSan, libFuzzer

These tests require Clang/LLVM 7 or newer on NetBSD.

Contributed by Yang Zheng during GSoC 2018.

diffstat:

 distrib/sets/lists/tests/mi                      |   41 ++++-
 tests/usr.bin/c++/Makefile                       |   25 ++-
 tests/usr.bin/c++/t_fuzzer_oom.sh                |  166 ++++++++++++++++
 tests/usr.bin/c++/t_fuzzer_simple.sh             |  182 ++++++++++++++++++
 tests/usr.bin/c++/t_fuzzer_timeout.sh            |  162 ++++++++++++++++
 tests/usr.bin/c++/t_msan_allocated_memory.sh     |  163 ++++++++++++++++
 tests/usr.bin/c++/t_msan_check_mem.sh            |  167 ++++++++++++++++
 tests/usr.bin/c++/t_msan_free.sh                 |  159 ++++++++++++++++
 tests/usr.bin/c++/t_msan_heap.sh                 |  139 ++++++++++++++
 tests/usr.bin/c++/t_msan_partial_poison.sh       |  171 +++++++++++++++++
 tests/usr.bin/c++/t_msan_poison.sh               |  167 ++++++++++++++++
 tests/usr.bin/c++/t_msan_realloc.sh              |  163 ++++++++++++++++
 tests/usr.bin/c++/t_msan_shadow.sh               |  183 ++++++++++++++++++
 tests/usr.bin/c++/t_msan_stack.sh                |  159 ++++++++++++++++
 tests/usr.bin/c++/t_msan_unpoison.sh             |  183 ++++++++++++++++++
 tests/usr.bin/c++/t_tsan_data_race.sh            |  180 ++++++++++++++++++
 tests/usr.bin/c++/t_tsan_heap_use_after_free.sh  |  216 +++++++++++++++++++++
 tests/usr.bin/c++/t_tsan_lock_order_inversion.sh |  200 ++++++++++++++++++++
 tests/usr.bin/c++/t_tsan_locked_mutex_destroy.sh |  216 +++++++++++++++++++++
 tests/usr.bin/c++/t_tsan_signal_errno.sh         |  204 ++++++++++++++++++++
 tests/usr.bin/c++/t_tsan_thread_leak.sh          |  204 ++++++++++++++++++++
 tests/usr.bin/c++/t_tsan_vptr_race.sh            |  228 +++++++++++++++++++++++
 tests/usr.bin/cc/Makefile                        |   24 ++-
 tests/usr.bin/cc/t_fuzzer_oom.sh                 |  166 ++++++++++++++++
 tests/usr.bin/cc/t_fuzzer_simple.sh              |  182 ++++++++++++++++++
 tests/usr.bin/cc/t_fuzzer_timeout.sh             |  162 ++++++++++++++++
 tests/usr.bin/cc/t_msan_allocated_memory.sh      |  164 ++++++++++++++++
 tests/usr.bin/cc/t_msan_check_mem.sh             |  168 ++++++++++++++++
 tests/usr.bin/cc/t_msan_free.sh                  |  159 ++++++++++++++++
 tests/usr.bin/cc/t_msan_heap.sh                  |  139 ++++++++++++++
 tests/usr.bin/cc/t_msan_partial_poison.sh        |  171 +++++++++++++++++
 tests/usr.bin/cc/t_msan_poison.sh                |  167 ++++++++++++++++
 tests/usr.bin/cc/t_msan_realloc.sh               |  163 ++++++++++++++++
 tests/usr.bin/cc/t_msan_shadow.sh                |  183 ++++++++++++++++++
 tests/usr.bin/cc/t_msan_stack.sh                 |  159 ++++++++++++++++
 tests/usr.bin/cc/t_msan_unpoison.sh              |  183 ++++++++++++++++++
 tests/usr.bin/cc/t_tsan_data_race.sh             |  180 ++++++++++++++++++
 tests/usr.bin/cc/t_tsan_heap_use_after_free.sh   |  216 +++++++++++++++++++++
 tests/usr.bin/cc/t_tsan_lock_order_inversion.sh  |  200 ++++++++++++++++++++
 tests/usr.bin/cc/t_tsan_locked_mutex_destroy.sh  |  216 +++++++++++++++++++++
 tests/usr.bin/cc/t_tsan_signal_errno.sh          |  204 ++++++++++++++++++++
 tests/usr.bin/cc/t_tsan_thread_leak.sh           |  204 ++++++++++++++++++++
 42 files changed, 7085 insertions(+), 3 deletions(-)

diffs (truncated from 7293 to 300 lines):

diff -r 3266fefd5c2b -r 414d0afe3218 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 18 16:49:30 2019 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 18 20:15:58 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.818 2019/07/28 13:49:23 christos Exp $
+# $NetBSD: mi,v 1.819 2019/08/18 20:15:59 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3840,6 +3840,26 @@
 ./usr/tests/usr.bin/c++/t_ubsan_int_neg_overflow       tests-usr.bin-tests     compattestfile,atf,cxx
 ./usr/tests/usr.bin/c++/t_ubsan_int_sub_overflow       tests-usr.bin-tests     compattestfile,atf,cxx
 ./usr/tests/usr.bin/c++/t_ubsan_vla_out_of_bounds      tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_allocated_memory        tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_check_mem       tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_free            tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_heap            tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_partial_poison  tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_poison          tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_realloc         tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_shadow          tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_stack           tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_msan_unpoison                tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_data_race       tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_heap_use_after_free     tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_lock_order_inversion    tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_locked_mutex_destroy    tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_signal_errno    tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_thread_leak     tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_tsan_vptr_race       tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_fuzzer_oom           tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_fuzzer_simple                tests-usr.bin-tests     compattestfile,atf,cxx
+./usr/tests/usr.bin/c++/t_fuzzer_timeout       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
@@ -3856,6 +3876,25 @@
 ./usr/tests/usr.bin/cc/t_ubsan_int_neg_overflow                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/cc/t_ubsan_int_sub_overflow                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/cc/t_ubsan_vla_out_of_bounds       tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_allocated_memory         tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_check_mem                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_free             tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_heap             tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_partial_poison    tests-usr.bin-tests    compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_poison           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_realloc          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_shadow           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_stack            tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_msan_unpoison         tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_data_race                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_heap_use_after_free      tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_lock_order_inversion     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_locked_mutex_destroy     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_signal_errno     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_tsan_thread_leak      tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_fuzzer_oom            tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_fuzzer_simple         tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/cc/t_fuzzer_timeout                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/cmp                                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/cmp/Atffile                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/cmp/Kyuafile               tests-usr.bin-tests     compattestfile,atf,kyua
diff -r 3266fefd5c2b -r 414d0afe3218 tests/usr.bin/c++/Makefile
--- a/tests/usr.bin/c++/Makefile        Sun Aug 18 16:49:30 2019 +0000
+++ b/tests/usr.bin/c++/Makefile        Sun Aug 18 20:15:58 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.11 2019/01/29 20:07:03 mgorny Exp $
+# $NetBSD: Makefile,v 1.12 2019/08/18 20:15:58 kamil Exp $
 
 .include <bsd.own.mk>
 
@@ -29,6 +29,29 @@
 TESTS_SH+=     t_pthread_once
 TESTS_SH+=     t_static_destructor
 
+TESTS_SH+=     t_fuzzer_oom
+TESTS_SH+=     t_fuzzer_simple
+TESTS_SH+=     t_fuzzer_timeout
+
+TESTS_SH+=     t_msan_allocated_memory
+TESTS_SH+=     t_msan_check_mem
+TESTS_SH+=     t_msan_free
+TESTS_SH+=     t_msan_heap
+TESTS_SH+=     t_msan_partial_poison
+TESTS_SH+=     t_msan_poison
+TESTS_SH+=     t_msan_realloc
+TESTS_SH+=     t_msan_shadow
+TESTS_SH+=     t_msan_stack
+TESTS_SH+=     t_msan_unpoison
+
+TESTS_SH+=     t_tsan_data_race
+TESTS_SH+=     t_tsan_heap_use_after_free
+TESTS_SH+=     t_tsan_lock_order_inversion
+TESTS_SH+=     t_tsan_locked_mutex_destroy
+TESTS_SH+=     t_tsan_signal_errno
+TESTS_SH+=     t_tsan_thread_leak
+TESTS_SH+=     t_tsan_vptr_race
+
 .for test in ${ASAN_TESTS}
 TESTS_SH_SRC_${test}=  asan_common.subr ${test}.sh
 .endfor
diff -r 3266fefd5c2b -r 414d0afe3218 tests/usr.bin/c++/t_fuzzer_oom.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/c++/t_fuzzer_oom.sh Sun Aug 18 20:15:58 2019 +0000
@@ -0,0 +1,166 @@
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Yang Zheng.
+#
+# 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.
+#
+
+test_target()
+{
+       SUPPORT='n'
+       if uname -m | grep -q "amd64" && command -v c++ >/dev/null 2>&1 && \
+                  ! echo __clang__ | c++ -E - | grep -q __clang__; then
+               # only clang with major version newer than 7 is supported
+               CLANG_MAJOR=`echo __clang_major__ | c++ -E - | grep -o '^[[:digit:]]'`
+               if [ "$CLANG_MAJOR" -ge "7" ]; then
+                       SUPPORT='y'
+               fi
+       fi
+}
+
+atf_test_case oom
+oom_head() {
+       atf_set "descr" "Test thread sanitizer for out-of-memory condition"
+       atf_set "require.progs" "c++ paxctl"
+}
+
+atf_test_case oom_profile
+oom_profile_head() {
+       atf_set "descr" "Test thread sanitizer for out-of-memory with profiling option"
+       atf_set "require.progs" "c++ paxctl"
+}
+atf_test_case oom_pic
+oom_pic_head() {
+       atf_set "descr" "Test thread sanitizer for out-of-memory with position independent code (PIC) flag"
+       atf_set "require.progs" "c++ paxctl"
+}
+atf_test_case oom_pie
+oom_pie_head() {
+       atf_set "descr" "Test thread sanitizer for out-of-memory with position independent execution (PIE) flag"
+       atf_set "require.progs" "c++ paxctl"
+}
+
+oom_body(){
+       cat > test.cc << EOF
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  if (size > 0 && data[0] == 'b') while (1) malloc(16*1024*1024);
+  return 0;
+}
+EOF
+
+       c++ -fsanitize=fuzzer -o test test.cc
+       paxctl +a test
+       atf_check -s ignore -o ignore -e match:"ERROR: libFuzzer: out-of-memory" ./test -rss_limit_mb=30
+}
+
+oom_profile_body(){
+       cat > test.cc << EOF
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  if (size > 0 && data[0] == 'b') while (1) malloc(16*1024*1024);
+  return 0;
+}
+EOF
+
+       c++ -fsanitize=fuzzer -o test -pg test.cc
+       paxctl +a test
+       atf_check -s ignore -o ignore -e match:"ERROR: libFuzzer: out-of-memory" ./test -rss_limit_mb=30
+}
+
+oom_pic_body(){
+       cat > test.cc << EOF
+#include <stddef.h>
+#include <stdint.h>
+int help(const uint8_t *data, size_t size);
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    return help(data, size);
+}
+EOF
+
+       cat > pic.cc << EOF
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+int help(const uint8_t *data, size_t size) {
+  if (size > 0 && data[0] == 'b') while (1) malloc(16*1024*1024);
+  return 0;
+}
+EOF
+
+       c++ -fsanitize=fuzzer -fPIC -shared -o libtest.so pic.cc
+       c++ -o test test.cc -fsanitize=fuzzer -L. -ltest
+       paxctl +a test
+
+       export LD_LIBRARY_PATH=.
+       atf_check -s ignore -o ignore -e match:"ERROR: libFuzzer: out-of-memory" ./test -rss_limit_mb=30
+}
+oom_pie_body(){
+       
+       #check whether -pie flag is supported on this architecture
+       if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 
+               atf_set_skip "c++ -pie not supported on this architecture"
+       fi
+       cat > test.cc << EOF
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  if (size > 0 && data[0] == 'b') while (1) malloc(16*1024*1024);
+  return 0;
+}
+EOF
+
+       c++ -fsanitize=fuzzer -o test -fpie -pie test.cc
+       paxctl +a test
+       atf_check -s ignore -o ignore -e match:"ERROR: libFuzzer: out-of-memory" ./test -rss_limit_mb=30
+}
+
+
+atf_test_case target_not_supported
+target_not_supported_head()
+{
+       atf_set "descr" "Test forced skip"
+}
+
+atf_init_test_cases()
+{
+       test_target
+       test $SUPPORT = 'n' && {
+               atf_add_test_case target_not_supported
+               return 0
+       }
+       atf_add_test_case oom
+       atf_add_test_case oom_profile
+       atf_add_test_case oom_pie
+       atf_add_test_case oom_pic
+}
diff -r 3266fefd5c2b -r 414d0afe3218 tests/usr.bin/c++/t_fuzzer_simple.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/c++/t_fuzzer_simple.sh      Sun Aug 18 20:15:58 2019 +0000
@@ -0,0 +1,182 @@
+# Copyright (c) 2018 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Yang Zheng.
+#
+# 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



Home | Main Index | Thread Index | Old Index