1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
//===- CoverageSummaryInfo.h - Coverage summary for function/file ---------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These structures are used to represent code coverage metrics
// for functions/files.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
#define LLVM_COV_COVERAGESUMMARYINFO_H
#include "llvm/ProfileData/CoverageMapping.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
/// \brief Provides information about region coverage for a function/file.
struct RegionCoverageInfo {
/// \brief The number of regions that were executed at least once.
size_t Covered;
/// \brief The number of regions that weren't executed.
size_t NotCovered;
/// \brief The total number of regions in a function/file.
size_t NumRegions;
RegionCoverageInfo() : Covered(0), NotCovered(0), NumRegions(0) {}
RegionCoverageInfo(size_t Covered, size_t NumRegions)
: Covered(Covered), NotCovered(NumRegions - Covered),
NumRegions(NumRegions) {}
RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
Covered += RHS.Covered;
NotCovered += RHS.NotCovered;
NumRegions += RHS.NumRegions;
return *this;
}
bool isFullyCovered() const { return Covered == NumRegions; }
double getPercentCovered() const {
return double(Covered) / double(NumRegions) * 100.0;
}
};
/// \brief Provides information about line coverage for a function/file.
struct LineCoverageInfo {
/// \brief The number of lines that were executed at least once.
size_t Covered;
/// \brief The number of lines that weren't executed.
size_t NotCovered;
/// \brief The number of lines that aren't code.
size_t NonCodeLines;
/// \brief The total number of lines in a function/file.
size_t NumLines;
LineCoverageInfo()
: Covered(0), NotCovered(0), NonCodeLines(0), NumLines(0) {}
LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
: Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
Covered += RHS.Covered;
NotCovered += RHS.NotCovered;
NonCodeLines += RHS.NonCodeLines;
NumLines += RHS.NumLines;
return *this;
}
bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
double getPercentCovered() const {
return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
}
};
/// \brief Provides information about function coverage for a file.
struct FunctionCoverageInfo {
/// \brief The number of functions that were executed.
size_t Executed;
/// \brief The total number of functions in this file.
size_t NumFunctions;
FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
: Executed(Executed), NumFunctions(NumFunctions) {}
void addFunction(bool Covered) {
if (Covered)
++Executed;
++NumFunctions;
}
bool isFullyCovered() const { return Executed == NumFunctions; }
double getPercentCovered() const {
return double(Executed) / double(NumFunctions) * 100.0;
}
};
/// \brief A summary of function's code coverage.
struct FunctionCoverageSummary {
StringRef Name;
uint64_t ExecutionCount;
RegionCoverageInfo RegionCoverage;
LineCoverageInfo LineCoverage;
FunctionCoverageSummary(StringRef Name) : Name(Name), ExecutionCount(0) {}
FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
const RegionCoverageInfo &RegionCoverage,
const LineCoverageInfo &LineCoverage)
: Name(Name), ExecutionCount(ExecutionCount),
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
}
/// \brief Compute the code coverage summary for the given function coverage
/// mapping record.
static FunctionCoverageSummary
get(const coverage::FunctionRecord &Function);
};
/// \brief A summary of file's code coverage.
struct FileCoverageSummary {
StringRef Name;
RegionCoverageInfo RegionCoverage;
LineCoverageInfo LineCoverage;
FunctionCoverageInfo FunctionCoverage;
FileCoverageSummary(StringRef Name) : Name(Name) {}
void addFunction(const FunctionCoverageSummary &Function) {
RegionCoverage += Function.RegionCoverage;
LineCoverage += Function.LineCoverage;
FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
}
};
} // namespace llvm
#endif // LLVM_COV_COVERAGESUMMARYINFO_H
|