From 037fee594b7c7a4d5e49337b0d48cc316cb4f136 Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Fri, 11 Mar 2016 23:28:28 +0000 Subject: [PATCH] [sancov] using md5 for anchors in attempt to reduce file size. Differential Revision: http://reviews.llvm.org/D18102 llvm-svn: 263308 --- llvm/test/tools/sancov/html-report.test | 2 +- llvm/tools/sancov/sancov.cc | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/llvm/test/tools/sancov/html-report.test b/llvm/test/tools/sancov/html-report.test index ebee289..a50c8fb 100644 --- a/llvm/test/tools/sancov/html-report.test +++ b/llvm/test/tools/sancov/html-report.test @@ -2,5 +2,5 @@ REQUIRES: x86_64-linux RUN: sancov -html-report %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s // It's very difficult to test html report. Do basic smoke check. -CHECK: {{}} +CHECK: {{.*/Inputs/test.cpp}} diff --git a/llvm/tools/sancov/sancov.cc b/llvm/tools/sancov/sancov.cc index 07b092e..2000276 100644 --- a/llvm/tools/sancov/sancov.cc +++ b/llvm/tools/sancov/sancov.cc @@ -33,6 +33,7 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/LineIterator.h" +#include "llvm/Support/MD5.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" @@ -487,6 +488,17 @@ static std::string escapeHtml(const std::string &S) { return Result; } +static std::string anchorName(std::string Anchor) { + llvm::MD5 Hasher; + llvm::MD5::MD5Result Hash; + Hasher.update(Anchor); + Hasher.final(Hash); + + SmallString<32> HexString; + llvm::MD5::stringifyResult(Hash, HexString); + return HexString.str().str(); +} + static ErrorOr isCoverageFile(std::string FileName) { ErrorOr> BufOrErr = MemoryBuffer::getFile(FileName); @@ -826,7 +838,7 @@ public: } size_t CovPct = FC.second == 0 ? 100 : 100 * FC.first / FC.second; - OS << "" + OS << "" << stripPathPrefix(FileName) << "" << "" << CovPct << "%" << "" << FC.first << " (" << FC.second << ")" @@ -855,7 +867,7 @@ public: std::pair FC = FileFnCoverage[FileName]; if (FC.first == 0) continue; - OS << "\n"; + OS << "\n"; OS << "

" << stripPathPrefix(FileName) << "

\n"; auto NotCoveredFns = NotCoveredFnMap.find(FileName); @@ -865,7 +877,7 @@ public: for (auto FileFn : NotCoveredFns->second) { OS << ""; OS << ""; + << anchorName(FileName + "::" + FileFn.FunctionName) << "\">"; OS << escapeHtml(FileFn.FunctionName) << ""; OS << "\n"; } @@ -891,7 +903,7 @@ public: auto It = NotCoveredFnByLoc.find(Loc); if (It != NotCoveredFnByLoc.end()) { for (std::string Fn : It->second) { - OS << ""; }; } @@ -1040,7 +1052,7 @@ public: // Modules TOC. if (Coverage.size() > 1) { for (const auto &CovData : Coverage) { - OS << "
  • object_file()) + OS << "
  • object_file()) << "\">" << llvm::sys::path::filename(CovData->object_file()) << "
  • \n"; } @@ -1051,7 +1063,7 @@ public: OS << "

    " << llvm::sys::path::filename(CovData->object_file()) << "

    \n"; } - OS << "object_file()) + OS << "object_file()) << "\">\n"; CovData->printReport(OS); } -- 2.7.4