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