1*0a6a1f1dSLionel Sambuc //===- CoverageSummary.cpp - Code coverage summary ------------------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc //
10*0a6a1f1dSLionel Sambuc // This class implements data management and rendering for the code coverage
11*0a6a1f1dSLionel Sambuc // summaries of all files and functions.
12*0a6a1f1dSLionel Sambuc //
13*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
14*0a6a1f1dSLionel Sambuc
15*0a6a1f1dSLionel Sambuc #include "CoverageSummary.h"
16*0a6a1f1dSLionel Sambuc #include "llvm/Support/FileSystem.h"
17*0a6a1f1dSLionel Sambuc #include "llvm/Support/Format.h"
18*0a6a1f1dSLionel Sambuc
19*0a6a1f1dSLionel Sambuc using namespace llvm;
20*0a6a1f1dSLionel Sambuc
getFileID(StringRef Filename)21*0a6a1f1dSLionel Sambuc unsigned CoverageSummary::getFileID(StringRef Filename) {
22*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = Filenames.size(); I < E; ++I) {
23*0a6a1f1dSLionel Sambuc if (sys::fs::equivalent(Filenames[I], Filename))
24*0a6a1f1dSLionel Sambuc return I;
25*0a6a1f1dSLionel Sambuc }
26*0a6a1f1dSLionel Sambuc Filenames.push_back(Filename);
27*0a6a1f1dSLionel Sambuc return Filenames.size() - 1;
28*0a6a1f1dSLionel Sambuc }
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc void
createSummaries(const coverage::CoverageMapping & Coverage)31*0a6a1f1dSLionel Sambuc CoverageSummary::createSummaries(const coverage::CoverageMapping &Coverage) {
32*0a6a1f1dSLionel Sambuc for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
33*0a6a1f1dSLionel Sambuc size_t PrevSize = FunctionSummaries.size();
34*0a6a1f1dSLionel Sambuc for (const auto &F : Coverage.getCoveredFunctions(Filename))
35*0a6a1f1dSLionel Sambuc FunctionSummaries.push_back(FunctionCoverageSummary::get(F));
36*0a6a1f1dSLionel Sambuc size_t Count = FunctionSummaries.size() - PrevSize;
37*0a6a1f1dSLionel Sambuc if (Count == 0)
38*0a6a1f1dSLionel Sambuc continue;
39*0a6a1f1dSLionel Sambuc FileSummaries.push_back(FileCoverageSummary::get(
40*0a6a1f1dSLionel Sambuc Filename, makeArrayRef(FunctionSummaries.data() + PrevSize, Count)));
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc
getCombinedFileSummaries()44*0a6a1f1dSLionel Sambuc FileCoverageSummary CoverageSummary::getCombinedFileSummaries() {
45*0a6a1f1dSLionel Sambuc size_t NumRegions = 0, CoveredRegions = 0;
46*0a6a1f1dSLionel Sambuc size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0;
47*0a6a1f1dSLionel Sambuc size_t NumFunctionsExecuted = 0, NumFunctions = 0;
48*0a6a1f1dSLionel Sambuc for (const auto &File : FileSummaries) {
49*0a6a1f1dSLionel Sambuc NumRegions += File.RegionCoverage.NumRegions;
50*0a6a1f1dSLionel Sambuc CoveredRegions += File.RegionCoverage.Covered;
51*0a6a1f1dSLionel Sambuc
52*0a6a1f1dSLionel Sambuc NumLines += File.LineCoverage.NumLines;
53*0a6a1f1dSLionel Sambuc NonCodeLines += File.LineCoverage.NonCodeLines;
54*0a6a1f1dSLionel Sambuc CoveredLines += File.LineCoverage.Covered;
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc NumFunctionsExecuted += File.FunctionCoverage.Executed;
57*0a6a1f1dSLionel Sambuc NumFunctions += File.FunctionCoverage.NumFunctions;
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc return FileCoverageSummary(
60*0a6a1f1dSLionel Sambuc "TOTAL", RegionCoverageInfo(CoveredRegions, NumRegions),
61*0a6a1f1dSLionel Sambuc LineCoverageInfo(CoveredLines, NonCodeLines, NumLines),
62*0a6a1f1dSLionel Sambuc FunctionCoverageInfo(NumFunctionsExecuted, NumFunctions),
63*0a6a1f1dSLionel Sambuc None);
64*0a6a1f1dSLionel Sambuc }
65