1*3f39123dSKostya Serebryany // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2*3f39123dSKostya Serebryany // See https://llvm.org/LICENSE.txt for license information.
3*3f39123dSKostya Serebryany // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4*3f39123dSKostya Serebryany 
5*3f39123dSKostya Serebryany // Simple test for a fuzzer.
6*3f39123dSKostya Serebryany // Needs to find a string "FUZZxxxxxxxxxxxxMxxE", where 'x' is any byte.
7*3f39123dSKostya Serebryany #include <assert.h>
8*3f39123dSKostya Serebryany #include <cstddef>
9*3f39123dSKostya Serebryany #include <cstdint>
10*3f39123dSKostya Serebryany #include <cstdlib>
11*3f39123dSKostya Serebryany #include <cstdio>
12*3f39123dSKostya Serebryany 
13*3f39123dSKostya Serebryany extern "C" bool Func1(const uint8_t *Data, size_t Size);
14*3f39123dSKostya Serebryany extern "C" bool Func2(const uint8_t *Data, size_t Size);
15*3f39123dSKostya Serebryany 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)16*3f39123dSKostya Serebryany extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
17*3f39123dSKostya Serebryany   if (Size >= 20
18*3f39123dSKostya Serebryany       && Data[0] == 'F'
19*3f39123dSKostya Serebryany       && Data[1] == 'U'
20*3f39123dSKostya Serebryany       && Data[2] == 'Z'
21*3f39123dSKostya Serebryany       && Data[3] == 'Z'
22*3f39123dSKostya Serebryany       && Func1(Data, Size)
23*3f39123dSKostya Serebryany       && Func2(Data, Size)) {
24*3f39123dSKostya Serebryany         fprintf(stderr, "BINGO\n");
25*3f39123dSKostya Serebryany         abort();
26*3f39123dSKostya Serebryany   }
27*3f39123dSKostya Serebryany   return 0;
28*3f39123dSKostya Serebryany }
29*3f39123dSKostya Serebryany 
30*3f39123dSKostya Serebryany extern "C"
31*3f39123dSKostya Serebryany __attribute__((noinline))
Func1(const uint8_t * Data,size_t Size)32*3f39123dSKostya Serebryany bool Func1(const uint8_t *Data, size_t Size) {
33*3f39123dSKostya Serebryany   // assumes Size >= 5, doesn't check it.
34*3f39123dSKostya Serebryany   return Data[16] == 'M';
35*3f39123dSKostya Serebryany }
36*3f39123dSKostya Serebryany 
37*3f39123dSKostya Serebryany extern "C"
38*3f39123dSKostya Serebryany __attribute__((noinline))
Func2(const uint8_t * Data,size_t Size)39*3f39123dSKostya Serebryany bool Func2(const uint8_t *Data, size_t Size) {
40*3f39123dSKostya Serebryany   return Size >= 20 && Data[19] == 'E';
41*3f39123dSKostya Serebryany }
42