[lib/Fuzzer] more efficient reload logic; also don't spam git too much
authorKostya Serebryany <kcc@google.com>
Tue, 19 May 2015 01:06:07 +0000 (01:06 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 19 May 2015 01:06:07 +0000 (01:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237649 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp
lib/Fuzzer/pull_and_push_fuzz_corpus.sh

index 8d6193e..80a2fc3 100644 (file)
@@ -16,7 +16,6 @@
 #include <string>
 #include <vector>
 #include <unordered_set>
-#include <set>
 
 #include "FuzzerInterface.h"
 
@@ -132,7 +131,7 @@ class Fuzzer {
   size_t TotalNumberOfRuns = 0;
 
   std::vector<Unit> Corpus;
-  std::set<Unit> UnitsAddedAfterInitialLoad;
+  std::unordered_set<std::string> UnitHashesAddedToCorpus;
   std::unordered_set<uintptr_t> FullCoverageSets;
   std::unordered_set<uint64_t>  CoveragePairs;
 
index 3a80d0d..be1e973 100644 (file)
@@ -99,13 +99,15 @@ void Fuzzer::RereadOutputCorpus() {
   for (auto &X : AdditionalCorpus) {
     if (X.size() > (size_t)Options.MaxLen)
       X.resize(Options.MaxLen);
-    if (UnitsAddedAfterInitialLoad.insert(X).second) {
-      Corpus.push_back(X);
+    if (UnitHashesAddedToCorpus.insert(Hash(X)).second) {
       CurrentUnit.clear();
       CurrentUnit.insert(CurrentUnit.begin(), X.begin(), X.end());
       size_t NewCoverage = RunOne(CurrentUnit);
-      if (NewCoverage && Options.Verbosity >= 1)
-        PrintStats("RELOAD", NewCoverage);
+      if (NewCoverage) {
+        Corpus.push_back(X);
+        if (Options.Verbosity >= 1)
+          PrintStats("RELOAD", NewCoverage);
+      }
     }
   }
 }
@@ -142,6 +144,8 @@ void Fuzzer::ShuffleAndMinimize() {
     }
   }
   Corpus = NewCorpus;
+  for (auto &X : Corpus)
+    UnitHashesAddedToCorpus.insert(Hash(X));
   PrintStats("INITED", MaxCov);
 }
 
@@ -292,7 +296,7 @@ void Fuzzer::SaveCorpus() {
 void Fuzzer::ReportNewCoverage(size_t NewCoverage, const Unit &U) {
   if (!NewCoverage) return;
   Corpus.push_back(U);
-  UnitsAddedAfterInitialLoad.insert(U);
+  UnitHashesAddedToCorpus.insert(Hash(U));
   PrintStats("NEW   ", NewCoverage, "");
   if (Options.Verbosity) {
     std::cerr << " L: " << U.size();
index 6c67cf0..bd564e3 100755 (executable)
@@ -9,7 +9,7 @@ cd $1
 git add *
 git commit -m "fuzz test corpus"
 git pull --no-edit
-for((attempt=0; attempt<100; attempt++)); do
+for((attempt=0; attempt<5; attempt++)); do
   echo GIT PUSH $1 ATTEMPT $attempt
   if $(git push); then break; fi
   git pull --no-edit