[llvm] r288276 - [libFuzzer] extend -print_coverage to print the comma-separated list of covered dirs. Note: the Windows stub for DirName is left unimplemented
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 30 13:53:33 PST 2016
Author: kcc
Date: Wed Nov 30 15:53:32 2016
New Revision: 288276
URL: http://llvm.org/viewvc/llvm-project?rev=288276&view=rev
Log:
[libFuzzer] extend -print_coverage to print the comma-separated list of covered dirs. Note: the Windows stub for DirName is left unimplemented
Modified:
llvm/trunk/lib/Fuzzer/FuzzerIO.h
llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp
llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/test/coverage.test
Modified: llvm/trunk/lib/Fuzzer/FuzzerIO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIO.h?rev=288276&r1=288275&r2=288276&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIO.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIO.h Wed Nov 30 15:53:32 2016
@@ -33,6 +33,9 @@ void ReadDirToVectorOfUnits(const char *
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();
Modified: llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp?rev=288276&r1=288275&r2=288276&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIOPosix.cpp Wed Nov 30 15:53:32 2016
@@ -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
Modified: llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp?rev=288276&r1=288275&r2=288276&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIOWindows.cpp Wed Nov 30 15:53:32 2016
@@ -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
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=288276&r1=288275&r2=288276&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Wed Nov 30 15:53:32 2016
@@ -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
Modified: llvm/trunk/lib/Fuzzer/test/coverage.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/coverage.test?rev=288276&r1=288275&r2=288276&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/coverage.test (original)
+++ llvm/trunk/lib/Fuzzer/test/coverage.test Wed Nov 30 15:53:32 2016
@@ -3,6 +3,7 @@ CHECK-DAG: COVERED: {{.*}}in LLVMFuzzerT
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
More information about the llvm-commits
mailing list