summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/test
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-01-06 00:03:35 +0000
committerKostya Serebryany <kcc@google.com>2016-01-06 00:03:35 +0000
commit226b734d73d23aa05984e350a6f3d96767e1736c (patch)
tree82925667fb8b57773a7e89b774ba2db981000843 /llvm/lib/Fuzzer/test
parent3eedd113291fa604adae3c898406e9efa2471701 (diff)
downloadbcm5719-llvm-226b734d73d23aa05984e350a6f3d96767e1736c.tar.gz
bcm5719-llvm-226b734d73d23aa05984e350a6f3d96767e1736c.zip
[libFuzzer] make trace-based fuzzing not crash in presence of threads
llvm-svn: 256876
Diffstat (limited to 'llvm/lib/Fuzzer/test')
-rw-r--r--llvm/lib/Fuzzer/test/CMakeLists.txt1
-rw-r--r--llvm/lib/Fuzzer/test/ThreadedTest.cpp23
-rw-r--r--llvm/lib/Fuzzer/test/fuzzer-threaded.test7
3 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/CMakeLists.txt b/llvm/lib/Fuzzer/test/CMakeLists.txt
index 674fcc3c9f8..cd0b167eb38 100644
--- a/llvm/lib/Fuzzer/test/CMakeLists.txt
+++ b/llvm/lib/Fuzzer/test/CMakeLists.txt
@@ -26,6 +26,7 @@ set(Tests
StrcmpTest
StrncmpTest
SwitchTest
+ ThreadedTest
TimeoutTest
)
diff --git a/llvm/lib/Fuzzer/test/ThreadedTest.cpp b/llvm/lib/Fuzzer/test/ThreadedTest.cpp
new file mode 100644
index 00000000000..7aa114a41f3
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/ThreadedTest.cpp
@@ -0,0 +1,23 @@
+// Threaded test for a fuzzer. The fuzzer should not crash.
+#include <assert.h>
+#include <cstdint>
+#include <cstddef>
+#include <cstring>
+#include <thread>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < 8) return 0;
+ assert(Data);
+ auto C = [&] {
+ size_t Res = 0;
+ for (size_t i = 0; i < Size / 2; i++)
+ Res += memcmp(Data, Data + Size / 2, 4);
+ return Res;
+ };
+ 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-threaded.test b/llvm/lib/Fuzzer/test/fuzzer-threaded.test
new file mode 100644
index 00000000000..c58a33456cc
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/fuzzer-threaded.test
@@ -0,0 +1,7 @@
+CHECK: Done 1000 runs in
+
+RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s
+RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s
+RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s
+RUN: LLVMFuzzer-ThreadedTest -use_traces=1 -runs=1000 2>&1 | FileCheck %s
+
OpenPOWER on IntegriCloud