diff options
-rw-r--r-- | test/fuzzer/CustomCrossOverTest.cpp | 8 | ||||
-rw-r--r-- | test/fuzzer/fuzzer-customcrossover.test | 9 |
2 files changed, 10 insertions, 7 deletions
diff --git a/test/fuzzer/CustomCrossOverTest.cpp b/test/fuzzer/CustomCrossOverTest.cpp index b47a63e1d..bd9afe774 100644 --- a/test/fuzzer/CustomCrossOverTest.cpp +++ b/test/fuzzer/CustomCrossOverTest.cpp @@ -15,12 +15,20 @@ static const char *Separator = "-########-"; static const char *Target = "A-########-B"; +static volatile int sink; + extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { assert(Data); std::string Str(reinterpret_cast<const char *>(Data), Size); static const size_t TargetHash = std::hash<std::string>{}(std::string(Target)); size_t StrHash = std::hash<std::string>{}(Str); + // Ensure we have 'A' and 'B' in the corpus. + if (Size == 1 && *Data == 'A') + sink++; + if (Size == 1 && *Data == 'B') + sink--; + if (TargetHash == StrHash) { std::cout << "BINGO; Found the target, exiting\n" << std::flush; exit(1); diff --git a/test/fuzzer/fuzzer-customcrossover.test b/test/fuzzer/fuzzer-customcrossover.test index d0537a054..c32079f45 100644 --- a/test/fuzzer/fuzzer-customcrossover.test +++ b/test/fuzzer/fuzzer-customcrossover.test @@ -1,13 +1,8 @@ RUN: %cpp_compiler %S/CustomCrossOverTest.cpp -o %t-CustomCrossOverTest -RUN: rm -rf %t/CustomCrossover -RUN: mkdir -p %t/CustomCrossover -RUN: echo -n A > %t/CustomCrossover/digits -RUN: echo -n B > %t/CustomCrossover/chars -RUN: not %t-CustomCrossOverTest -seed=1 -runs=100000 %t/CustomCrossover 2>&1 | FileCheck %s --check-prefix=CHECK_CO +RUN: not %t-CustomCrossOverTest -seed=1 -runs=100000 2>&1 | FileCheck %s --check-prefix=CHECK_CO Disable cross_over, verify that we can't find the target w/o it. -RUN: %t-CustomCrossOverTest -seed=1 -runs=1000000 %t/CustomCrossover -cross_over=0 2>&1 | FileCheck %s --check-prefix=CHECK_NO_CO -RUN: rm -rf %t/CustomCrossover +RUN: %t-CustomCrossOverTest -seed=1 -runs=1000000 -cross_over=0 2>&1 | FileCheck %s --check-prefix=CHECK_NO_CO CHECK_CO: In LLVMFuzzerCustomCrossover CHECK_CO: BINGO |