summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Lettner <jlettner@apple.com>2019-01-31 01:24:01 +0000
committerJulian Lettner <jlettner@apple.com>2019-01-31 01:24:01 +0000
commit15df273eb45dc53669739bb33388a12c1dfce962 (patch)
treea5b70c3815b4d1f07763e37580bf461e19ccae70
parent46138cdb0d9cef9aef3573914c8ec35ea39d28f8 (diff)
downloadbcm5719-llvm-15df273eb45dc53669739bb33388a12c1dfce962.tar.gz
bcm5719-llvm-15df273eb45dc53669739bb33388a12c1dfce962.zip
[libFuzzer] Set default sanitizer options in fuzzer tests
Summary: Set default `ASAN_OPTIONS` when running libFuzzer tests. This allows us to remove special casing in code for Darwin where we usually pass `abort_on_error=0` to override platform defaults for tests. A previous commit changed the code to make the tests pass: https://github.com/llvm/llvm-project/commit/7764a04af007eca68eafcf5caaea560ed05e35a9 Adapted a few tests to use `%env_asan_opts=` instead of directly setting the environment variable. rdar://problem/47515276 Reviewers: kcc, george.karpenkov Differential Revision: https://reviews.llvm.org/D57465 llvm-svn: 352711
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerLoop.cpp5
-rw-r--r--compiler-rt/test/fuzzer/fuzzer-segv.test4
-rw-r--r--compiler-rt/test/fuzzer/large.test2
-rw-r--r--compiler-rt/test/fuzzer/lit.cfg7
-rw-r--r--compiler-rt/test/fuzzer/minimize_two_crashes.test2
-rw-r--r--compiler-rt/test/fuzzer/strncmp-oob.test2
6 files changed, 15 insertions, 7 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
index 959d5a23559..bf600169c4c 100644
--- a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
@@ -232,8 +232,9 @@ void Fuzzer::StaticFileSizeExceedCallback() {
}
void Fuzzer::CrashCallback() {
- if (EF->__sanitizer_acquire_crash_state)
- EF->__sanitizer_acquire_crash_state();
+ if (EF->__sanitizer_acquire_crash_state &&
+ !EF->__sanitizer_acquire_crash_state())
+ return;
Printf("==%lu== ERROR: libFuzzer: deadly signal\n", GetPid());
PrintStackTrace();
Printf("NOTE: libFuzzer has rudimentary signal handlers.\n"
diff --git a/compiler-rt/test/fuzzer/fuzzer-segv.test b/compiler-rt/test/fuzzer/fuzzer-segv.test
index 0c4fafe0807..7ae9049e15a 100644
--- a/compiler-rt/test/fuzzer/fuzzer-segv.test
+++ b/compiler-rt/test/fuzzer/fuzzer-segv.test
@@ -1,8 +1,8 @@
RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest
-RUN: env ASAN_OPTIONS=handle_segv=0 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER
+RUN: %env_asan_opts=handle_segv=0 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER
LIBFUZZER_OWN_SEGV_HANDLER: == ERROR: libFuzzer: deadly signal
LIBFUZZER_OWN_SEGV_HANDLER: SUMMARY: libFuzzer: deadly signal
LIBFUZZER_OWN_SEGV_HANDLER: Test unit written to ./crash-
-RUN: env ASAN_OPTIONS=handle_segv=1 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_ASAN_SEGV_HANDLER
+RUN: %env_asan_opts=handle_segv=1 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_ASAN_SEGV_HANDLER
LIBFUZZER_ASAN_SEGV_HANDLER: ERROR: AddressSanitizer: {{SEGV|access-violation}} on unknown address
diff --git a/compiler-rt/test/fuzzer/large.test b/compiler-rt/test/fuzzer/large.test
index a2e0ac036ea..91d279bc07d 100644
--- a/compiler-rt/test/fuzzer/large.test
+++ b/compiler-rt/test/fuzzer/large.test
@@ -1,6 +1,6 @@
REQUIRES: linux
RUN: %cpp_compiler %S/LargeTest.cpp -o %t-LargeTest
RUN: %run %t-LargeTest -runs=10000
-RUN: ASAN_OPTIONS=handle_segv=0 %run %t-LargeTest -runs=10000 -lazy_counters=1 2>&1 | FileCheck %s
+RUN: %env_asan_opts=handle_segv=0 %run %t-LargeTest -runs=10000 -lazy_counters=1 2>&1 | FileCheck %s
CHECK: pages of counters where protected; libFuzzer's SEGV handler must be installed
diff --git a/compiler-rt/test/fuzzer/lit.cfg b/compiler-rt/test/fuzzer/lit.cfg
index 608991c0764..2ce347356da 100644
--- a/compiler-rt/test/fuzzer/lit.cfg
+++ b/compiler-rt/test/fuzzer/lit.cfg
@@ -119,6 +119,13 @@ config.substitutions.append(('%msan_compiler',
generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True, msan_enabled=True)
))
+default_asan_opts_str = ':'.join(config.default_sanitizer_opts)
+if default_asan_opts_str:
+ config.environment['ASAN_OPTIONS'] = default_asan_opts_str
+ default_asan_opts_str += ':'
+config.substitutions.append(('%env_asan_opts=',
+ 'env ASAN_OPTIONS=' + default_asan_opts_str))
+
if config.host_os == 'Darwin':
if config.target_arch in ["x86_64", "x86_64h"]:
config.parallelism_group = "darwin-64bit-sanitizer"
diff --git a/compiler-rt/test/fuzzer/minimize_two_crashes.test b/compiler-rt/test/fuzzer/minimize_two_crashes.test
index cba88eed12e..e101094d648 100644
--- a/compiler-rt/test/fuzzer/minimize_two_crashes.test
+++ b/compiler-rt/test/fuzzer/minimize_two_crashes.test
@@ -6,7 +6,7 @@ RUN: %cpp_compiler -O0 %S/TwoDifferentBugsTest.cpp -o %t-TwoDifferentBugsTest
RUN: rm -rf %t && mkdir %t
RUN: echo H12345678901234667888090 > %t/long_crash
-RUN: env ASAN_OPTIONS=dedup_token_length=3 %run %t-TwoDifferentBugsTest -seed=1 -minimize_crash=1 %t/long_crash -exact_artifact_path=%t/result 2>&1 | FileCheck %s
+RUN: %env_asan_opts=dedup_token_length=3 %run %t-TwoDifferentBugsTest -seed=1 -minimize_crash=1 %t/long_crash -exact_artifact_path=%t/result 2>&1 | FileCheck %s
CHECK: DedupToken1: DEDUP_TOKEN: Bar
CHECK: DedupToken2: DEDUP_TOKEN: Bar
diff --git a/compiler-rt/test/fuzzer/strncmp-oob.test b/compiler-rt/test/fuzzer/strncmp-oob.test
index a0365d96183..3d1f19789d3 100644
--- a/compiler-rt/test/fuzzer/strncmp-oob.test
+++ b/compiler-rt/test/fuzzer/strncmp-oob.test
@@ -1,6 +1,6 @@
RUN: %cpp_compiler %S/StrncmpOOBTest.cpp -o %t-StrncmpOOBTest
-RUN: env ASAN_OPTIONS=strict_string_checks=1 not %run %t-StrncmpOOBTest -seed=1 -runs=1000000 2>&1 | FileCheck %s --check-prefix=STRNCMP
+RUN: %env_asan_opts=strict_string_checks=1 not %run %t-StrncmpOOBTest -seed=1 -runs=1000000 2>&1 | FileCheck %s --check-prefix=STRNCMP
STRNCMP: AddressSanitizer: heap-buffer-overflow
STRNCMP-NOT: __sanitizer_weak_hook_strncmp
STRNCMP: in LLVMFuzzerTestOneInput
OpenPOWER on IntegriCloud