diff options
author | Kostya Serebryany <kcc@google.com> | 2016-05-26 22:17:32 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-05-26 22:17:32 +0000 |
commit | d8384122a30642cd44a4871132b5562f125399b2 (patch) | |
tree | 19d49e197e93eedaf54ff9f723da93770475eb81 /llvm/lib/Fuzzer/test | |
parent | 274cb1d2247933ce6a04b1e6d303d8f592f47f43 (diff) | |
download | bcm5719-llvm-d8384122a30642cd44a4871132b5562f125399b2.tar.gz bcm5719-llvm-d8384122a30642cd44a4871132b5562f125399b2.zip |
[libFuzzer] more refactoring around CurrentUnit. Also add a threading test on which we currently have a race (when reporting bugs from multiple threads)
llvm-svn: 270929
Diffstat (limited to 'llvm/lib/Fuzzer/test')
-rw-r--r-- | llvm/lib/Fuzzer/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/fuzzer-leak.test | 2 |
3 files changed, 26 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/test/CMakeLists.txt b/llvm/lib/Fuzzer/test/CMakeLists.txt index 5703de804cf..5ff11b0669e 100644 --- a/llvm/lib/Fuzzer/test/CMakeLists.txt +++ b/llvm/lib/Fuzzer/test/CMakeLists.txt @@ -58,6 +58,7 @@ set(Tests SimpleFnAdapterTest SimpleHashTest SimpleTest + SimpleThreadedTest SpamyTest StrcmpTest StrncmpTest diff --git a/llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp b/llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp new file mode 100644 index 00000000000..5f02d3f8457 --- /dev/null +++ b/llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp @@ -0,0 +1,25 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Threaded test for a fuzzer. The fuzzer should find "H" +#include <assert.h> +#include <cstdint> +#include <cstddef> +#include <cstring> +#include <iostream> +#include <thread> + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + auto C = [&] { + if (Size >= 2 && Data[0] == 'H') { + std::cout << "BINGO; Found the target, exiting\n"; + abort(); + } + }; + std::thread T[] = {std::thread(C), std::thread(C), std::thread(C), + std::thread(C), std::thread(C), std::thread(C)}; + for (auto &X : T) + X.join(); + return 0; +} + diff --git a/llvm/lib/Fuzzer/test/fuzzer-leak.test b/llvm/lib/Fuzzer/test/fuzzer-leak.test index 184e199ff14..61410aae401 100644 --- a/llvm/lib/Fuzzer/test/fuzzer-leak.test +++ b/llvm/lib/Fuzzer/test/fuzzer-leak.test @@ -3,7 +3,6 @@ LEAK_DURING: ERROR: LeakSanitizer: detected memory leaks LEAK_DURING: Direct leak of 4 byte(s) in 1 object(s) allocated from: LEAK_DURING-NOT: DONE LEAK_DURING-NOT: Done -LEAK_DURING-NOT: DEATH: RUN: not LLVMFuzzer-LeakTest -runs=0 -detect_leaks=1 %S 2>&1 | FileCheck %s --check-prefix=LEAK_IN_CORPUS LEAK_IN_CORPUS: ERROR: LeakSanitizer: detected memory leaks @@ -14,7 +13,6 @@ RUN: not LLVMFuzzer-LeakTest -runs=100000 -detect_leaks=0 2>&1 | FileCheck %s -- RUN: not LLVMFuzzer-LeakTest -runs=100000 2>&1 | FileCheck %s --check-prefix=LEAK_DURING LEAK_AFTER: Done 100000 runs in LEAK_AFTER: ERROR: LeakSanitizer: detected memory leaks -LEAK_AFTER-NOT: DEATH: RUN: not LLVMFuzzer-LeakTimeoutTest -timeout=1 2>&1 | FileCheck %s --check-prefix=LEAK_TIMEOUT LEAK_TIMEOUT: ERROR: libFuzzer: timeout after |