[compiler-rt] r312689 - [libFuzzer] simplify and re-enable CustomCrossOverTest
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 19:04:06 PDT 2017
Author: kcc
Date: Wed Sep 6 19:04:06 2017
New Revision: 312689
URL: http://llvm.org/viewvc/llvm-project?rev=312689&view=rev
Log:
[libFuzzer] simplify and re-enable CustomCrossOverTest
Modified:
compiler-rt/trunk/test/fuzzer/CustomCrossOverTest.cpp
compiler-rt/trunk/test/fuzzer/fuzzer-customcrossover.test
Modified: compiler-rt/trunk/test/fuzzer/CustomCrossOverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/CustomCrossOverTest.cpp?rev=312689&r1=312688&r2=312689&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/CustomCrossOverTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/CustomCrossOverTest.cpp Wed Sep 6 19:04:06 2017
@@ -1,7 +1,7 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
-// Simple test for a cutom mutator.
+// Simple test for a cutom crossover.
#include <assert.h>
#include <cstddef>
#include <cstdint>
@@ -10,23 +10,18 @@
#include <ostream>
#include <random>
#include <string.h>
+#include <functional>
-#include "FuzzerInterface.h"
-
-static const char *Separator = "-_^_-";
-static const char *Target = "012-_^_-abc";
-
-static volatile int sink;
+static const char *Separator = "-########-";
+static const char *Target = "A-########-B";
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 that two different elements exist in the corpus.
- if (Size && Data[0] == '0') sink++;
- if (Size && Data[0] == 'a') sink--;
-
- if (Str.find(Target) != std::string::npos) {
+ if (TargetHash == StrHash) {
std::cout << "BINGO; Found the target, exiting\n" << std::flush;
exit(1);
}
@@ -37,28 +32,20 @@ extern "C" size_t LLVMFuzzerCustomCrossO
const uint8_t *Data2, size_t Size2,
uint8_t *Out, size_t MaxOutSize,
unsigned int Seed) {
- static bool Printed;
+ static size_t Printed;
static size_t SeparatorLen = strlen(Separator);
- if (!Printed) {
- std::cerr << "In LLVMFuzzerCustomCrossover\n";
- Printed = true;
- }
-
- std::mt19937 R(Seed);
+ if (Printed++ < 32)
+ std::cerr << "In LLVMFuzzerCustomCrossover " << Size1 << " " << Size2 << "\n";
- size_t Offset1 = 0;
- size_t Len1 = R() % (Size1 - Offset1);
- size_t Offset2 = 0;
- size_t Len2 = R() % (Size2 - Offset2);
- size_t Size = Len1 + Len2 + SeparatorLen;
+ size_t Size = Size1 + Size2 + SeparatorLen;
if (Size > MaxOutSize)
return 0;
- memcpy(Out, Data1 + Offset1, Len1);
- memcpy(Out + Len1, Separator, SeparatorLen);
- memcpy(Out + Len1 + SeparatorLen, Data2 + Offset2, Len2);
+ memcpy(Out, Data1, Size1);
+ memcpy(Out + Size1, Separator, SeparatorLen);
+ memcpy(Out + Size1 + SeparatorLen, Data2, Size2);
- return Len1 + Len2 + SeparatorLen;
+ return Size;
}
Modified: compiler-rt/trunk/test/fuzzer/fuzzer-customcrossover.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/fuzzer-customcrossover.test?rev=312689&r1=312688&r2=312689&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/fuzzer-customcrossover.test (original)
+++ compiler-rt/trunk/test/fuzzer/fuzzer-customcrossover.test Wed Sep 6 19:04:06 2017
@@ -2,14 +2,16 @@ RUN: %cpp_compiler %S/CustomCrossOverTes
RUN: rm -rf %t/CustomCrossover
RUN: mkdir -p %t/CustomCrossover
-RUN: echo "0123456789" > %t/CustomCrossover/digits
-RUN: echo "abcdefghij" > %t/CustomCrossover/chars
-TODO: make this test more stable (currently, the target can be found by usual strcmp magic)
-DISABLED: not %t-CustomCrossOverTest -seed=1 -runs=1000000 %t/CustomCrossover 2>&1 | FileCheck %s --check-prefix=LLVMFuzzerCustomCrossover
-RUN: echo In LLVMFuzzerCustomCrossover
-RUN: echo BINGO
+RUN: echo "A" > %t/CustomCrossover/digits
+RUN: echo "B" > %t/CustomCrossover/chars
+RUN: not %t-CustomCrossOverTest -seed=1 -runs=100000 %t/CustomCrossover 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
-LLVMFuzzerCustomCrossover: In LLVMFuzzerCustomCrossover
-LLVMFuzzerCustomCrossover: BINGO
+CHECK_CO: In LLVMFuzzerCustomCrossover
+CHECK_CO: BINGO
+
+CHECK_NO_CO-NO: LLVMFuzzerCustomCrossover
+CHECK_NO_CO: DONE
More information about the llvm-commits
mailing list