From 226b734d73d23aa05984e350a6f3d96767e1736c Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 6 Jan 2016 00:03:35 +0000 Subject: [libFuzzer] make trace-based fuzzing not crash in presence of threads llvm-svn: 256876 --- llvm/lib/Fuzzer/test/ThreadedTest.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 llvm/lib/Fuzzer/test/ThreadedTest.cpp (limited to 'llvm/lib/Fuzzer/test/ThreadedTest.cpp') 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 +#include +#include +#include +#include + +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; +} + -- cgit v1.2.3