summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-05-26 22:17:32 +0000
committerKostya Serebryany <kcc@google.com>2016-05-26 22:17:32 +0000
commitd8384122a30642cd44a4871132b5562f125399b2 (patch)
tree19d49e197e93eedaf54ff9f723da93770475eb81 /llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp
parent274cb1d2247933ce6a04b1e6d303d8f592f47f43 (diff)
downloadbcm5719-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/SimpleThreadedTest.cpp')
-rw-r--r--llvm/lib/Fuzzer/test/SimpleThreadedTest.cpp25
1 files changed, 25 insertions, 0 deletions
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;
+}
+
OpenPOWER on IntegriCloud