llvm.org GIT mirror llvm / 10edef1
[llvm-cov] Read in function names for filtering from a text file. Summary: Add a -name-whitelist option, which behaves in the same way as -name, but it reads in multiple function names from the given input file(s). Reviewers: vsk Reviewed By: vsk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37111 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312227 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Eveson 2 years ago
10 changed file(s) with 147 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
234234
235235 Show code coverage only for functions with the given name.
236236
237 .. option:: -name-whitelist=
238
239 Show code coverage only for functions listed in the given file. Each line in
240 the file should start with `whitelist_fun:`, immediately followed by the name
241 of the function to accept. This name can be a wildcard expression.
242
237243 .. option:: -name-regex=
238244
239245 Show code coverage only for functions that match the given regular expression.
0 int func1() {
1 return 1;
2 }
3 int func2() {
4 return 1;
5 }
6 int func3() {
7 return 1;
8 }
9 int func4() {
10 return 1;
11 }
12 int func5() {
13 return 1;
14 }
15 int func6() {
16 return 1;
17 }
0 _Z5func1v
1 # Func Hash:
2 0
3 # Num Counters:
4 1
5 # Counter Values:
6 0
7
8 _Z5func2v
9 # Func Hash:
10 0
11 # Num Counters:
12 1
13 # Counter Values:
14 0
15
16 _Z5func3v
17 # Func Hash:
18 0
19 # Num Counters:
20 1
21 # Counter Values:
22 0
23
24 _Z5func4v
25 # Func Hash:
26 0
27 # Num Counters:
28 1
29 # Counter Values:
30 0
31
32 main
33 # Func Hash:
34 0
35 # Num Counters:
36 1
37 # Counter Values:
38 1
39
40 _Z5func5v
41 # Func Hash:
42 0
43 # Num Counters:
44 1
45 # Counter Values:
46 0
47
48 _Z5func6v
49 # Func Hash:
50 0
51 # Num Counters:
52 1
53 # Counter Values:
54 0
55
0 # Comment
1
2 whitelist_fun:*func1*
3 whitelist_fun:*func2*
0 whitelist_fun:*func3*
1 whitelist_fun:*func4*
0 RUN: llvm-profdata merge %S/Inputs/name_whitelist.proftext -o %t.profdata
1
2 RUN: llvm-cov show %S/Inputs/name_whitelist.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S/Inputs -name-whitelist=%S/Inputs/whitelist1.txt %S/Inputs/name_whitelist.cpp > %t.one_list
3 RUN: FileCheck -input-file=%t.one_list -check-prefix=ONE_WHITELIST %s
4 RUN: FileCheck -input-file=%t.one_list -check-prefix=ONE_WHITELIST_NEG %s
5 ONE_WHITELIST: _Z5func1v:
6 ONE_WHITELIST: _Z5func2v:
7 ONE_WHITELIST_NEG-NOT: _Z5func3v:
8 ONE_WHITELIST_NEG-NOT: _Z5func4v:
9 ONE_WHITELIST_NEG-NOT: _Z5func5v:
10 ONE_WHITELIST_NEG-NOT: _Z5func6v:
11
12 RUN: llvm-cov show %S/Inputs/name_whitelist.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S/Inputs -name-whitelist=%S/Inputs/whitelist1.txt -name-whitelist=%S/Inputs/whitelist2.txt %S/Inputs/name_whitelist.cpp > %t.two_list
13 RUN: FileCheck -input-file=%t.two_list -check-prefix=TWO_WHITELIST %s
14 RUN: FileCheck -input-file=%t.two_list -check-prefix=TWO_WHITELIST_NEG %s
15 TWO_WHITELIST: _Z5func1v:
16 TWO_WHITELIST: _Z5func2v:
17 TWO_WHITELIST: _Z5func3v:
18 TWO_WHITELIST: _Z5func4v:
19 TWO_WHITELIST_NEG-NOT: _Z5func5v:
20 TWO_WHITELIST_NEG-NOT: _Z5func6v:
149149 std::mutex LoadedSourceFilesLock;
150150 std::vector>>
151151 LoadedSourceFiles;
152
153 /// Whitelist from -name-whitelist to be used for filtering.
154 std::unique_ptr NameWhitelist;
152155 };
153156 }
154157
560563 cl::desc("Show code coverage only for functions with the given name"),
561564 cl::ZeroOrMore, cl::cat(FilteringCategory));
562565
566 cl::list NameFilterFiles(
567 "name-whitelist", cl::Optional,
568 cl::desc("Show code coverage only for functions listed in the given "
569 "file"),
570 cl::ZeroOrMore, cl::cat(FilteringCategory));
571
563572 cl::list NameRegexFilters(
564573 "name-regex", cl::Optional,
565574 cl::desc("Show code coverage only for functions that match the given "
642651 ViewOpts.DemanglerOpts.swap(DemanglerOpts);
643652 }
644653
654 // Read in -name-whitelist files.
655 if (!NameFilterFiles.empty()) {
656 std::string SpecialCaseListErr;
657 NameWhitelist =
658 SpecialCaseList::create(NameFilterFiles, SpecialCaseListErr);
659 if (!NameWhitelist)
660 error(SpecialCaseListErr);
661 }
662
645663 // Create the function filters
646 if (!NameFilters.empty() || !NameRegexFilters.empty()) {
664 if (!NameFilters.empty() || NameWhitelist || !NameRegexFilters.empty()) {
647665 auto NameFilterer = llvm::make_unique();
648666 for (const auto &Name : NameFilters)
649667 NameFilterer->push_back(llvm::make_unique(Name));
668 if (NameWhitelist)
669 NameFilterer->push_back(
670 llvm::make_unique(*NameWhitelist));
650671 for (const auto &Regex : NameRegexFilters)
651672 NameFilterer->push_back(
652673 llvm::make_unique(Regex));
2424 bool
2525 NameRegexCoverageFilter::matches(const coverage::FunctionRecord &Function) {
2626 return llvm::Regex(Regex).match(Function.Name);
27 }
28
29 bool NameWhitelistCoverageFilter::matches(
30 const coverage::FunctionRecord &Function) {
31 return Whitelist.inSection("whitelist_fun", Function.Name);
2732 }
2833
2934 bool RegionCoverageFilter::matches(const coverage::FunctionRecord &Function) {
1414 #define LLVM_COV_COVERAGEFILTERS_H
1515
1616 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
17 #include "llvm/Support/SpecialCaseList.h"
1718 #include
1819 #include
1920
4647
4748 public:
4849 NameRegexCoverageFilter(StringRef Regex) : Regex(Regex) {}
50
51 bool matches(const coverage::FunctionRecord &Function) override;
52 };
53
54 /// \brief Matches functions whose name appears in a SpecialCaseList in the
55 /// whitelist_fun section.
56 class NameWhitelistCoverageFilter : public CoverageFilter {
57 const SpecialCaseList &Whitelist;
58
59 public:
60 NameWhitelistCoverageFilter(const SpecialCaseList &Whitelist)
61 : Whitelist(Whitelist) {}
4962
5063 bool matches(const coverage::FunctionRecord &Function) override;
5164 };