[compiler-rt] r313081 - [libFuzzer] factor out some code into GetSizedFilesFromDir; NFC
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 14:58:07 PDT 2017
Author: kcc
Date: Tue Sep 12 14:58:07 2017
New Revision: 313081
URL: http://llvm.org/viewvc/llvm-project?rev=313081&view=rev
Log:
[libFuzzer] factor out some code into GetSizedFilesFromDir; NFC
Modified:
compiler-rt/trunk/lib/fuzzer/FuzzerIO.cpp
compiler-rt/trunk/lib/fuzzer/FuzzerIO.h
compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerIO.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerIO.cpp?rev=313081&r1=313080&r2=313081&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerIO.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerIO.cpp Tue Sep 12 14:58:07 2017
@@ -86,6 +86,15 @@ void ReadDirToVectorOfUnits(const char *
}
}
+
+void GetSizedFilesFromDir(const std::string &Dir, Vector<SizedFile> *V) {
+ Vector<std::string> Files;
+ ListFilesInDirRecursive(Dir, 0, &Files, /*TopDir*/true);
+ for (auto &File : Files)
+ if (size_t Size = FileSize(File))
+ V->push_back({File, Size});
+}
+
std::string DirPlusFile(const std::string &DirPath,
const std::string &FileName) {
return DirPath + GetSeparator() + FileName;
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerIO.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerIO.h?rev=313081&r1=313080&r2=313081&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerIO.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerIO.h Tue Sep 12 14:58:07 2017
@@ -58,6 +58,14 @@ size_t FileSize(const std::string &Path)
void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
Vector<std::string> *V, bool TopDir);
+struct SizedFile {
+ std::string File;
+ size_t Size;
+ bool operator<(const SizedFile &B) const { return Size < B.Size; }
+};
+
+void GetSizedFilesFromDir(const std::string &Dir, Vector<SizedFile> *V);
+
char GetSeparator();
FILE* OpenFile(int Fd, const char *Mode);
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp?rev=313081&r1=313080&r2=313081&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerLoop.cpp Tue Sep 12 14:58:07 2017
@@ -597,26 +597,21 @@ void Fuzzer::MutateAndTestOne() {
void Fuzzer::ReadAndExecuteSeedCorpora(const Vector<std::string> &CorpusDirs) {
const size_t kMaxSaneLen = 1 << 20;
const size_t kMinDefaultLen = 4096;
- struct SizedFile {
- std::string File;
- size_t Size;
- };
Vector<SizedFile> SizedFiles;
size_t MaxSize = 0;
size_t MinSize = -1;
size_t TotalSize = 0;
+ size_t LastNumFiles = 0;
for (auto &Dir : CorpusDirs) {
- Vector<std::string> Files;
- ListFilesInDirRecursive(Dir, 0, &Files, /*TopDir*/true);
- Printf("INFO: % 8zd files found in %s\n", Files.size(), Dir.c_str());
- for (auto &File : Files) {
- if (size_t Size = FileSize(File)) {
- MaxSize = Max(Size, MaxSize);
- MinSize = Min(Size, MinSize);
- TotalSize += Size;
- SizedFiles.push_back({File, Size});
- }
- }
+ GetSizedFilesFromDir(Dir, &SizedFiles);
+ Printf("INFO: % 8zd files found in %s\n", SizedFiles.size() - LastNumFiles,
+ Dir.c_str());
+ LastNumFiles = SizedFiles.size();
+ }
+ for (auto &File : SizedFiles) {
+ MaxSize = Max(File.Size, MaxSize);
+ MinSize = Min(File.Size, MinSize);
+ TotalSize += File.Size;
}
if (Options.MaxLen == 0)
SetMaxInputLen(std::min(std::max(kMinDefaultLen, MaxSize), kMaxSaneLen));
@@ -633,10 +628,10 @@ void Fuzzer::ReadAndExecuteSeedCorpora(c
if (Options.ShuffleAtStartUp)
std::shuffle(SizedFiles.begin(), SizedFiles.end(), MD.GetRand());
- if (Options.PreferSmall)
- std::stable_sort(
- SizedFiles.begin(), SizedFiles.end(),
- [](const SizedFile &A, const SizedFile &B) { return A.Size < B.Size; });
+ if (Options.PreferSmall) {
+ std::stable_sort(SizedFiles.begin(), SizedFiles.end());
+ assert(SizedFiles.front().Size <= SizedFiles.back().Size);
+ }
// Load and execute inputs one by one.
for (auto &SF : SizedFiles) {
More information about the llvm-commits
mailing list