]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/fuzzer/ThreadedTest.cpp
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / fuzzer / ThreadedTest.cpp
1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3
4 // Threaded test for a fuzzer. The fuzzer should not crash.
5 #include <assert.h>
6 #include <cstddef>
7 #include <cstdint>
8 #include <cstring>
9 #include <thread>
10
11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
12   if (Size < 8) return 0;
13   assert(Data);
14   auto C = [&] {
15     size_t Res = 0;
16     for (size_t i = 0; i < Size / 2; i++)
17       Res += memcmp(Data, Data + Size / 2, 4);
18     return Res;
19   };
20   std::thread T[] = {std::thread(C), std::thread(C), std::thread(C),
21                      std::thread(C), std::thread(C), std::thread(C)};
22   for (auto &X : T)
23     X.join();
24   return 0;
25 }
26