diff options
author | Kostya Serebryany <kcc@google.com> | 2019-05-10 01:34:26 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2019-05-10 01:34:26 +0000 |
commit | 4c7353c53bdd9a98134bca5d71d9d642440de01b (patch) | |
tree | d7bfc0c49545dd1433b386c2a158eb9ecfe385f4 /compiler-rt/lib/fuzzer/FuzzerLoop.cpp | |
parent | da96d92175f716ba2dd219f937bb26bdea126cbc (diff) | |
download | bcm5719-llvm-4c7353c53bdd9a98134bca5d71d9d642440de01b.tar.gz bcm5719-llvm-4c7353c53bdd9a98134bca5d71d9d642440de01b.zip |
[libFuzzer] code refactoring; NFC
llvm-svn: 360400
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerLoop.cpp')
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerLoop.cpp | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp index cb3d8214c0c..d7adc90c996 100644 --- a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp @@ -723,28 +723,13 @@ void Fuzzer::PurgeAllocator() { LastAllocatorPurgeAttemptTime = system_clock::now(); } -void Fuzzer::ReadAndExecuteSeedCorpora( - const Vector<std::string> &CorpusDirs, - const Vector<std::string> &ExtraSeedFiles) { +void Fuzzer::ReadAndExecuteSeedCorpora(Vector<SizedFile> &CorporaFiles) { const size_t kMaxSaneLen = 1 << 20; const size_t kMinDefaultLen = 4096; - Vector<SizedFile> SizedFiles; size_t MaxSize = 0; size_t MinSize = -1; size_t TotalSize = 0; - size_t LastNumFiles = 0; - for (auto &Dir : CorpusDirs) { - GetSizedFilesFromDir(Dir, &SizedFiles); - Printf("INFO: % 8zd files found in %s\n", SizedFiles.size() - LastNumFiles, - Dir.c_str()); - LastNumFiles = SizedFiles.size(); - } - // Add files from -seed_inputs. - for (auto &File : ExtraSeedFiles) - if (auto Size = FileSize(File)) - SizedFiles.push_back({File, Size}); - - for (auto &File : SizedFiles) { + for (auto &File : CorporaFiles) { MaxSize = Max(File.Size, MaxSize); MinSize = Min(File.Size, MinSize); TotalSize += File.Size; @@ -761,24 +746,24 @@ void Fuzzer::ReadAndExecuteSeedCorpora( if (Options.LazyCounters) TPC.ProtectLazyCounters(); - if (SizedFiles.empty()) { + if (CorporaFiles.empty()) { Printf("INFO: A corpus is not provided, starting from an empty corpus\n"); Unit U({'\n'}); // Valid ASCII input. RunOne(U.data(), U.size()); } else { Printf("INFO: seed corpus: files: %zd min: %zdb max: %zdb total: %zdb" " rss: %zdMb\n", - SizedFiles.size(), MinSize, MaxSize, TotalSize, GetPeakRSSMb()); + CorporaFiles.size(), MinSize, MaxSize, TotalSize, GetPeakRSSMb()); if (Options.ShuffleAtStartUp) - std::shuffle(SizedFiles.begin(), SizedFiles.end(), MD.GetRand()); + std::shuffle(CorporaFiles.begin(), CorporaFiles.end(), MD.GetRand()); if (Options.PreferSmall) { - std::stable_sort(SizedFiles.begin(), SizedFiles.end()); - assert(SizedFiles.front().Size <= SizedFiles.back().Size); + std::stable_sort(CorporaFiles.begin(), CorporaFiles.end()); + assert(CorporaFiles.front().Size <= CorporaFiles.back().Size); } // Load and execute inputs one by one. - for (auto &SF : SizedFiles) { + for (auto &SF : CorporaFiles) { auto U = FileToVector(SF.File, MaxInputLen, /*ExitOnError=*/false); assert(U.size() <= MaxInputLen); RunOne(U.data(), U.size()); @@ -803,9 +788,8 @@ void Fuzzer::ReadAndExecuteSeedCorpora( } } -void Fuzzer::Loop(const Vector<std::string> &CorpusDirs, - const Vector<std::string> &ExtraSeedFiles) { - ReadAndExecuteSeedCorpora(CorpusDirs, ExtraSeedFiles); +void Fuzzer::Loop(Vector<SizedFile> &CorporaFiles) { + ReadAndExecuteSeedCorpora(CorporaFiles); DFT.Clear(); // No need for DFT any more. TPC.SetPrintNewPCs(Options.PrintNewCovPcs); TPC.SetPrintNewFuncs(Options.PrintNewCovFuncs); |