Coverage Report

Created: 2017-09-21 03:39

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/llvm-cov/CoverageFilters.h
Line
Count
Source (jump to first uncovered line)
1
//===- CoverageFilters.h - Function coverage mapping filters --------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// These classes provide filtering for function coverage mapping records.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_COV_COVERAGEFILTERS_H
15
#define LLVM_COV_COVERAGEFILTERS_H
16
17
#include "CoverageSummaryInfo.h"
18
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
19
#include "llvm/Support/SpecialCaseList.h"
20
#include <memory>
21
#include <vector>
22
23
namespace llvm {
24
25
/// \brief Matches specific functions that pass the requirement of this filter.
26
class CoverageFilter {
27
public:
28
114
  virtual ~CoverageFilter() {}
29
30
  /// \brief Return true if the function passes the requirements of this filter.
31
  virtual bool matches(const coverage::CoverageMapping &CM,
32
0
                       const coverage::FunctionRecord &Function) {
33
0
    return true;
34
0
  }
35
};
36
37
/// \brief Matches functions that contain a specific string in their name.
38
class NameCoverageFilter : public CoverageFilter {
39
  StringRef Name;
40
41
public:
42
10
  NameCoverageFilter(StringRef Name) : Name(Name) {}
43
44
  bool matches(const coverage::CoverageMapping &CM,
45
               const coverage::FunctionRecord &Function) override;
46
};
47
48
/// \brief Matches functions whose name matches a certain regular expression.
49
class NameRegexCoverageFilter : public CoverageFilter {
50
  StringRef Regex;
51
52
public:
53
2
  NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
54
55
  bool matches(const coverage::CoverageMapping &CM,
56
               const coverage::FunctionRecord &Function) override;
57
};
58
59
/// \brief Matches functions whose name appears in a SpecialCaseList in the
60
/// whitelist_fun section.
61
class NameWhitelistCoverageFilter : public CoverageFilter {
62
  const SpecialCaseList &Whitelist;
63
64
public:
65
  NameWhitelistCoverageFilter(const SpecialCaseList &Whitelist)
66
2
      : Whitelist(Whitelist) {}
67
68
  bool matches(const coverage::CoverageMapping &CM,
69
               const coverage::FunctionRecord &Function) override;
70
};
71
72
/// \brief Matches numbers that pass a certain threshold.
73
template <typename T> class StatisticThresholdFilter {
74
public:
75
  enum Operation { LessThan, GreaterThan };
76
77
protected:
78
  Operation Op;
79
  T Threshold;
80
81
  StatisticThresholdFilter(Operation Op, T Threshold)
82
0
      : Op(Op), Threshold(Threshold) {}
83
84
  /// \brief Return true if the given number is less than
85
  /// or greater than the certain threshold.
86
0
  bool PassesThreshold(T Value) const {
87
0
    switch (Op) {
88
0
    case LessThan:
89
0
      return Value < Threshold;
90
0
    case GreaterThan:
91
0
      return Value > Threshold;
92
0
    }
93
0
    return false;
94
0
  }
95
};
96
97
/// \brief Matches functions whose region coverage percentage
98
/// is above/below a certain percentage.
99
class RegionCoverageFilter : public CoverageFilter,
100
                             public StatisticThresholdFilter<double> {
101
public:
102
  RegionCoverageFilter(Operation Op, double Threshold)
103
0
      : StatisticThresholdFilter(Op, Threshold) {}
104
105
  bool matches(const coverage::CoverageMapping &CM,
106
               const coverage::FunctionRecord &Function) override;
107
};
108
109
/// \brief Matches functions whose line coverage percentage
110
/// is above/below a certain percentage.
111
class LineCoverageFilter : public CoverageFilter,
112
                           public StatisticThresholdFilter<double> {
113
public:
114
  LineCoverageFilter(Operation Op, double Threshold)
115
0
      : StatisticThresholdFilter(Op, Threshold) {}
116
117
  bool matches(const coverage::CoverageMapping &CM,
118
               const coverage::FunctionRecord &Function) override;
119
};
120
121
/// \brief A collection of filters.
122
/// Matches functions that match any filters contained
123
/// in an instance of this class.
124
class CoverageFilters : public CoverageFilter {
125
protected:
126
  std::vector<std::unique_ptr<CoverageFilter>> Filters;
127
128
public:
129
  /// \brief Append a filter to this collection.
130
  void push_back(std::unique_ptr<CoverageFilter> Filter);
131
132
59
  bool empty() const { return Filters.empty(); }
133
134
  bool matches(const coverage::CoverageMapping &CM,
135
               const coverage::FunctionRecord &Function) override;
136
};
137
138
/// \brief A collection of filters.
139
/// Matches functions that match all of the filters contained
140
/// in an instance of this class.
141
class CoverageFiltersMatchAll : public CoverageFilters {
142
public:
143
  bool matches(const coverage::CoverageMapping &CM,
144
               const coverage::FunctionRecord &Function) override;
145
};
146
147
} // namespace llvm
148
149
#endif // LLVM_COV_COVERAGEFILTERS_H