summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-11-30 21:53:32 +0000
committerKostya Serebryany <kcc@google.com>2016-11-30 21:53:32 +0000
commit1cba0a96e7def030a89bd1bf10c355e515b0957b (patch)
tree38fb4bd954f2db20c97d0484c8a9939c7052eccb /llvm
parent5abac1769f36e4f7d9d6c3a408a1356490fc76e0 (diff)
downloadbcm5719-llvm-1cba0a96e7def030a89bd1bf10c355e515b0957b.tar.gz
bcm5719-llvm-1cba0a96e7def030a89bd1bf10c355e515b0957b.zip
[libFuzzer] extend -print_coverage to print the comma-separated list of covered dirs. Note: the Windows stub for DirName is left unimplemented
llvm-svn: 288276
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Fuzzer/FuzzerIO.h3
-rw-r--r--llvm/lib/Fuzzer/FuzzerIOPosix.cpp11
-rw-r--r--llvm/lib/Fuzzer/FuzzerIOWindows.cpp4
-rw-r--r--llvm/lib/Fuzzer/FuzzerTracePC.cpp12
-rw-r--r--llvm/lib/Fuzzer/test/coverage.test1
5 files changed, 29 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.h b/llvm/lib/Fuzzer/FuzzerIO.h
index b1ac69c8088..39634f93fec 100644
--- a/llvm/lib/Fuzzer/FuzzerIO.h
+++ b/llvm/lib/Fuzzer/FuzzerIO.h
@@ -33,6 +33,9 @@ void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
std::string DirPlusFile(const std::string &DirPath,
const std::string &FileName);
+// Returns the name of the dir, similar to the 'dirname' utility.
+std::string DirName(const std::string &FileName);
+
void DupAndCloseStderr();
void CloseStdout();
diff --git a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
index 740d52d0b1d..a4290face97 100644
--- a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
@@ -18,8 +18,9 @@
#include <dirent.h>
#include <fstream>
#include <iterator>
-#include <sys/types.h>
+#include <libgen.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
namespace fuzzer {
@@ -74,5 +75,13 @@ void DeleteFile(const std::string &Path) {
unlink(Path.c_str());
}
+std::string DirName(const std::string &FileName) {
+ char *Tmp = new char[FileName.size() + 1];
+ memcpy(Tmp, FileName.c_str(), FileName.size() + 1);
+ std::string Res = dirname(Tmp);
+ delete [] Tmp;
+ return Res;
+}
+
} // namespace fuzzer
#endif // LIBFUZZER_POSIX
diff --git a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
index f19353c96cb..aaa2e34fb35 100644
--- a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
@@ -139,5 +139,9 @@ void DeleteFile(const std::string &Path) {
_unlink(Path.c_str());
}
+std::string DirName(const std::string &FileName) {
+ assert(0 && "Unimplemented");
+}
+
} // namespace fuzzer
#endif // LIBFUZZER_WINDOWS
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
index eabf0d087f4..8d58a6d3a91 100644
--- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp
+++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
@@ -131,7 +131,8 @@ void TracePC::PrintCoverage() {
}
std::map<std::string, std::vector<uintptr_t>> CoveredPCsPerModule;
std::map<std::string, uintptr_t> ModuleOffsets;
- std::set<std::string> CoveredFiles, CoveredFunctions, CoveredLines;
+ std::set<std::string> CoveredDirs, CoveredFiles, CoveredFunctions,
+ CoveredLines;
Printf("COVERAGE:\n");
for (size_t i = 1; i < GetNumPCs(); i++) {
if (!PCs[i]) continue;
@@ -150,12 +151,21 @@ void TracePC::PrintCoverage() {
CoveredPCsPerModule[Module].push_back(PcOffset);
CoveredFunctions.insert(FunctionStr);
CoveredFiles.insert(FileStr);
+ CoveredDirs.insert(DirName(FileStr));
if (!CoveredLines.insert(FileStr + ":" + LineStr).second)
continue;
Printf("COVERED: %s %s:%s\n", FunctionStr.c_str(),
FileStr.c_str(), LineStr.c_str());
}
+ std::string CoveredDirsStr;
+ for (auto &Dir : CoveredDirs) {
+ if (!CoveredDirsStr.empty())
+ CoveredDirsStr += ",";
+ CoveredDirsStr += Dir;
+ }
+ Printf("COVERED_DIRS: %s\n", CoveredDirsStr.c_str());
+
for (auto &M : CoveredPCsPerModule) {
std::set<std::string> UncoveredFiles, UncoveredFunctions;
std::map<std::string, std::set<int> > UncoveredLines; // Func+File => lines
diff --git a/llvm/lib/Fuzzer/test/coverage.test b/llvm/lib/Fuzzer/test/coverage.test
index b41a262c462..a5420bba23b 100644
--- a/llvm/lib/Fuzzer/test/coverage.test
+++ b/llvm/lib/Fuzzer/test/coverage.test
@@ -3,6 +3,7 @@ CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:13
CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:14
CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:16
CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:19
+CHECK: COVERED_DIRS: {{.*}}lib/Fuzzer/test
RUN: not LLVMFuzzer-NullDerefTest-TracePC -print_coverage=1 2>&1 | FileCheck %s
RUN: LLVMFuzzer-DSOTest -print_coverage=1 -runs=0 2>&1 | FileCheck %s --check-prefix=DSO
OpenPOWER on IntegriCloud