From fd9cb1a5c565c224897bd49abc5f8c186ba6aaa0 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 8 Jun 2016 01:46:13 +0000 Subject: [PATCH] [libFuzzer] add a test that is built w/o coverage instrumentation but has the coverage rt (it should now fail with a descriptive message) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272090 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/FuzzerLoop.cpp | 5 +++++ lib/Fuzzer/test/CMakeLists.txt | 1 + lib/Fuzzer/test/fuzzer.test | 3 +++ lib/Fuzzer/test/no-coverage/CMakeLists.txt | 16 ++++++++++++++++ lib/Fuzzer/test/uninstrumented/CMakeLists.txt | 3 ++- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 lib/Fuzzer/test/no-coverage/CMakeLists.txt diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 5cfbad4c327..e397645782e 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -391,6 +391,11 @@ void Fuzzer::ShuffleAndMinimize() { for (auto &X : Corpus) UnitHashesAddedToCorpus.insert(Hash(X)); PrintStats("INITED"); + if (Corpus.empty()) { + Printf("ERROR: no interesting inputs were found. " + "Is the code instrumented for coverage? Exiting.\n"); + exit(1); + } } bool Fuzzer::UpdateMaxCoverage() { diff --git a/lib/Fuzzer/test/CMakeLists.txt b/lib/Fuzzer/test/CMakeLists.txt index 85fb62e3345..9421606aec0 100644 --- a/lib/Fuzzer/test/CMakeLists.txt +++ b/lib/Fuzzer/test/CMakeLists.txt @@ -149,6 +149,7 @@ else() endif() add_subdirectory(uninstrumented) +add_subdirectory(no-coverage) add_subdirectory(ubsan) add_subdirectory(trace-bb) add_subdirectory(trace-pc) diff --git a/lib/Fuzzer/test/fuzzer.test b/lib/Fuzzer/test/fuzzer.test index 25ca5ff5bd2..11343ae3834 100644 --- a/lib/Fuzzer/test/fuzzer.test +++ b/lib/Fuzzer/test/fuzzer.test @@ -32,6 +32,9 @@ RUN: not LLVMFuzzer-CallerCalleeTest -cross_over=0 -max_len= RUN: not LLVMFuzzer-UninstrumentedTest-Uninstrumented 2>&1 | FileCheck %s --check-prefix=UNINSTRUMENTED UNINSTRUMENTED: ERROR: __sanitizer_set_death_callback is not defined. Exiting. +RUN: not LLVMFuzzer-UninstrumentedTest-NoCoverage 2>&1 | FileCheck %s --check-prefix=NO_COVERAGE +NO_COVERAGE: ERROR: no interesting inputs were found. Is the code instrumented for coverage? Exiting + RUN: not LLVMFuzzer-BufferOverflowOnInput 2>&1 | FileCheck %s --check-prefix=OOB OOB: AddressSanitizer: heap-buffer-overflow OOB: is located 0 bytes to the right of 3-byte region diff --git a/lib/Fuzzer/test/no-coverage/CMakeLists.txt b/lib/Fuzzer/test/no-coverage/CMakeLists.txt new file mode 100644 index 00000000000..1dc7d15926c --- /dev/null +++ b/lib/Fuzzer/test/no-coverage/CMakeLists.txt @@ -0,0 +1,16 @@ +# These tests are not instrumented with coverage, +# but have coverage rt in the binary. + +set(CMAKE_CXX_FLAGS + "${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters") + +set(NoCoverageTests + UninstrumentedTest + ) + +foreach(Test ${NoCoverageTests}) + add_libfuzzer_test(${Test}-NoCoverage SOURCES ../${Test}.cpp) +endforeach() + +# Propagate value into parent directory +set(TestBinaries ${TestBinaries} PARENT_SCOPE) diff --git a/lib/Fuzzer/test/uninstrumented/CMakeLists.txt b/lib/Fuzzer/test/uninstrumented/CMakeLists.txt index 35c96481af3..06e48985e7e 100644 --- a/lib/Fuzzer/test/uninstrumented/CMakeLists.txt +++ b/lib/Fuzzer/test/uninstrumented/CMakeLists.txt @@ -1,4 +1,5 @@ -# These tests are not instrumented with coverage. +# These tests are not instrumented with coverage and don't +# have coverage rt in the binary. set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters") -- 2.11.0