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// Simple test for a fuzzer.
5c5f01b2fSopenharmony_ci// The fuzzer must find a string based on dictionary words:
6c5f01b2fSopenharmony_ci//   "Elvis"
7c5f01b2fSopenharmony_ci//   "Presley"
8c5f01b2fSopenharmony_ci#include <cstdint>
9c5f01b2fSopenharmony_ci#include <cstdlib>
10c5f01b2fSopenharmony_ci#include <cstddef>
11c5f01b2fSopenharmony_ci#include <cstring>
12c5f01b2fSopenharmony_ci#include <iostream>
13c5f01b2fSopenharmony_ci
14c5f01b2fSopenharmony_cistatic volatile int Zero = 0;
15c5f01b2fSopenharmony_ci
16c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
17c5f01b2fSopenharmony_ci  const char *Expected = "ElvisPresley";
18c5f01b2fSopenharmony_ci  if (Size < strlen(Expected)) return 0;
19c5f01b2fSopenharmony_ci  size_t Match = 0;
20c5f01b2fSopenharmony_ci  for (size_t i = 0; Expected[i]; i++)
21c5f01b2fSopenharmony_ci    if (Expected[i] + Zero == Data[i])
22c5f01b2fSopenharmony_ci      Match++;
23c5f01b2fSopenharmony_ci  if (Match == strlen(Expected)) {
24c5f01b2fSopenharmony_ci    std::cout << "BINGO; Found the target, exiting\n";
25c5f01b2fSopenharmony_ci    exit(1);
26c5f01b2fSopenharmony_ci  }
27c5f01b2fSopenharmony_ci  return 0;
28c5f01b2fSopenharmony_ci}
29c5f01b2fSopenharmony_ci
30