[llvm] r263773 - [libFuzzer] read corpus dirs recursively
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 18:36:00 PDT 2016
Author: kcc
Date: Thu Mar 17 20:36:00 2016
New Revision: 263773
URL: http://llvm.org/viewvc/llvm-project?rev=263773&view=rev
Log:
[libFuzzer] read corpus dirs recursively
Modified:
llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
llvm/trunk/lib/Fuzzer/test/fuzzer.test
Modified: llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIO.cpp?rev=263773&r1=263772&r2=263773&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIO.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIO.cpp Thu Mar 17 20:36:00 2016
@@ -34,25 +34,27 @@ static long GetEpoch(const std::string &
return St.st_mtime;
}
-static std::vector<std::string> ListFilesInDir(const std::string &Dir,
- long *Epoch) {
- std::vector<std::string> V;
- if (Epoch) {
- auto E = GetEpoch(Dir);
- if (E && *Epoch >= E) return V;
- *Epoch = E;
- }
+static void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
+ std::vector<std::string> *V, bool TopDir) {
+ auto E = GetEpoch(Dir);
+ if (Epoch)
+ if (E && *Epoch >= E) return;
+
DIR *D = opendir(Dir.c_str());
if (!D) {
Printf("No such directory: %s; exiting\n", Dir.c_str());
exit(1);
}
while (auto E = readdir(D)) {
+ std::string Path = DirPlusFile(Dir, E->d_name);
if (E->d_type == DT_REG || E->d_type == DT_LNK)
- V.push_back(E->d_name);
+ V->push_back(Path);
+ else if (E->d_type == DT_DIR && *E->d_name != '.')
+ ListFilesInDirRecursive(Path, Epoch, V, false);
}
closedir(D);
- return V;
+ if (Epoch && TopDir)
+ *Epoch = E;
}
Unit FileToVector(const std::string &Path, size_t MaxSize) {
@@ -94,16 +96,16 @@ void WriteToFile(const Unit &U, const st
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
long *Epoch, size_t MaxSize) {
long E = Epoch ? *Epoch : 0;
- auto Files = ListFilesInDir(Path, Epoch);
+ std::vector<std::string> Files;
+ ListFilesInDirRecursive(Path, Epoch, &Files, /*TopDir*/true);
size_t NumLoaded = 0;
for (size_t i = 0; i < Files.size(); i++) {
auto &X = Files[i];
- auto FilePath = DirPlusFile(Path, X);
- if (Epoch && GetEpoch(FilePath) < E) continue;
+ if (Epoch && GetEpoch(X) < E) continue;
NumLoaded++;
if ((NumLoaded & (NumLoaded - 1)) == 0 && NumLoaded >= 1024)
Printf("Loaded %zd/%zd files from %s\n", NumLoaded, Files.size(), Path);
- V->push_back(FileToVector(FilePath, MaxSize));
+ V->push_back(FileToVector(X, MaxSize));
}
}
Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=263773&r1=263772&r2=263773&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Thu Mar 17 20:36:00 2016
@@ -60,6 +60,15 @@ SINGLE_INPUTS: LLVMFuzzer-SimpleTest: Ru
SINGLE_INPUTS: aaa:
SINGLE_INPUTS: bbb:
+RUN: rm -rf %t/SUB1
+RUN: mkdir -p %t/SUB1/SUB2/SUB3
+RUN: echo a > %t/SUB1/a
+RUN: echo b > %t/SUB1/SUB2/b
+RUN: echo c > %t/SUB1/SUB2/SUB3/c
+RUN: LLVMFuzzer-SimpleTest %t/SUB1 -runs=0 2>&1 | FileCheck %s --check-prefix=SUBDIRS
+SUBDIRS: READ units: 3
+RUN: rm -rf %t/SUB1
+
RUN: not LLVMFuzzer-LeakTest -runs=10 2>&1 | FileCheck %s --check-prefix=LEAK
LEAK: ERROR: LeakSanitizer: detected memory leaks
LEAK-NOT: DEATH:
More information about the llvm-commits
mailing list