[libFuzzer] more refactoring the code that checks the coverage. NFC
authorKostya Serebryany <kcc@google.com>
Thu, 22 Oct 2015 22:56:45 +0000 (22:56 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 22 Oct 2015 22:56:45 +0000 (22:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251075 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 85f86158373f7fae02bd4dc205a0616add9f2c10..919516a703c7a53a8288c4d16d8351f3e2a279f2 100644 (file)
@@ -128,7 +128,7 @@ class Fuzzer {
   void RunOneAndUpdateCorpus(Unit &U);
   void WriteToOutputCorpus(const Unit &U);
   void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
   void RunOneAndUpdateCorpus(Unit &U);
   void WriteToOutputCorpus(const Unit &U);
   void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
-  void PrintStats(const char *Where, size_t Cov, const char *End = "\n");
+  void PrintStats(const char *Where, const char *End = "\n");
   void PrintUnitInASCII(const Unit &U, const char *PrintAfter = "");
 
   void SyncCorpus();
   void PrintUnitInASCII(const Unit &U, const char *PrintAfter = "");
 
   void SyncCorpus();
index 9347831119d106b2e417caa4ccbad381671999d1..6ac8997df78109f784d90261b3accced807b51ae 100644 (file)
@@ -83,12 +83,13 @@ void Fuzzer::AlarmCallback() {
   }
 }
 
   }
 }
 
-void Fuzzer::PrintStats(const char *Where, size_t Cov, const char *End) {
+void Fuzzer::PrintStats(const char *Where, const char *End) {
   if (!Options.Verbosity) return;
   size_t Seconds = secondsSinceProcessStartUp();
   size_t ExecPerSec = (Seconds ? TotalNumberOfRuns / Seconds : 0);
   Printf("#%zd\t%s", TotalNumberOfRuns, Where);
   if (!Options.Verbosity) return;
   size_t Seconds = secondsSinceProcessStartUp();
   size_t ExecPerSec = (Seconds ? TotalNumberOfRuns / Seconds : 0);
   Printf("#%zd\t%s", TotalNumberOfRuns, Where);
-  Printf(" cov: %zd", Cov);
+  if (LastRecordedBlockCoverage)
+    Printf(" cov: %zd", LastRecordedBlockCoverage);
   if (auto TB = TotalBits())
     Printf(" bits: %zd", TB);
   Printf(" units: %zd exec/s: %zd", Corpus.size(), ExecPerSec);
   if (auto TB = TotalBits())
     Printf(" bits: %zd", TB);
   Printf(" units: %zd exec/s: %zd", Corpus.size(), ExecPerSec);
@@ -118,7 +119,7 @@ void Fuzzer::RereadOutputCorpus() {
       if (RunOne(CurrentUnit)) {
         Corpus.push_back(X);
         if (Options.Verbosity >= 1)
       if (RunOne(CurrentUnit)) {
         Corpus.push_back(X);
         if (Options.Verbosity >= 1)
-          PrintStats("RELOAD", LastRecordedBlockCoverage);
+          PrintStats("RELOAD");
       }
     }
   }
       }
     }
   }
@@ -130,7 +131,7 @@ void Fuzzer::ShuffleAndMinimize() {
                        USF.GetRand().RandBool()));
   if (Options.Verbosity)
     Printf("PreferSmall: %d\n", PreferSmall);
                        USF.GetRand().RandBool()));
   if (Options.Verbosity)
     Printf("PreferSmall: %d\n", PreferSmall);
-  PrintStats("READ  ", 0);
+  PrintStats("READ  ");
   std::vector<Unit> NewCorpus;
   if (Options.ShuffleAtStartUp) {
     std::random_shuffle(Corpus.begin(), Corpus.end(), USF.GetRand());
   std::vector<Unit> NewCorpus;
   if (Options.ShuffleAtStartUp) {
     std::random_shuffle(Corpus.begin(), Corpus.end(), USF.GetRand());
@@ -157,7 +158,7 @@ void Fuzzer::ShuffleAndMinimize() {
   Corpus = NewCorpus;
   for (auto &X : Corpus)
     UnitHashesAddedToCorpus.insert(Hash(X));
   Corpus = NewCorpus;
   for (auto &X : Corpus)
     UnitHashesAddedToCorpus.insert(Hash(X));
-  PrintStats("INITED", LastRecordedBlockCoverage);
+  PrintStats("INITED");
 }
 
 bool Fuzzer::RunOne(const Unit &U) {
 }
 
 bool Fuzzer::RunOne(const Unit &U) {
@@ -172,7 +173,7 @@ bool Fuzzer::RunOne(const Unit &U) {
   auto TimeOfUnit =
       duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
   if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) && Options.Verbosity)
   auto TimeOfUnit =
       duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
   if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) && Options.Verbosity)
-    PrintStats("pulse ", LastRecordedBlockCoverage);
+    PrintStats("pulse ");
   if (TimeOfUnit > TimeOfLongestUnitInSeconds &&
       TimeOfUnit >= Options.ReportSlowUnits) {
     TimeOfLongestUnitInSeconds = TimeOfUnit;
   if (TimeOfUnit > TimeOfLongestUnitInSeconds &&
       TimeOfUnit >= Options.ReportSlowUnits) {
     TimeOfLongestUnitInSeconds = TimeOfUnit;
@@ -254,7 +255,7 @@ void Fuzzer::SaveCorpus() {
 void Fuzzer::ReportNewCoverage(const Unit &U) {
   Corpus.push_back(U);
   UnitHashesAddedToCorpus.insert(Hash(U));
 void Fuzzer::ReportNewCoverage(const Unit &U) {
   Corpus.push_back(U);
   UnitHashesAddedToCorpus.insert(Hash(U));
-  PrintStats("NEW   ", LastRecordedBlockCoverage, "");
+  PrintStats("NEW   ", "");
   if (Options.Verbosity) {
     Printf(" L: %zd", U.size());
     if (U.size() < 30) {
   if (Options.Verbosity) {
     Printf(" L: %zd", U.size());
     if (U.size() < 30) {