1 //===- CoverageFilters.cpp - 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 #include "CoverageFilters.h" 15 #include "CoverageSummaryInfo.h" 16 #include "llvm/Support/Regex.h" 17 18 using namespace llvm; 19 20 bool NameCoverageFilter::matches(const coverage::FunctionRecord &Function) { 21 StringRef FuncName = Function.Name; 22 return FuncName.find(Name) != StringRef::npos; 23 } 24 25 bool 26 NameRegexCoverageFilter::matches(const coverage::FunctionRecord &Function) { 27 return llvm::Regex(Regex).match(Function.Name); 28 } 29 30 bool NameWhitelistCoverageFilter::matches( 31 const coverage::FunctionRecord &Function) { 32 return Whitelist.inSection("whitelist_fun", Function.Name); 33 } 34 35 bool RegionCoverageFilter::matches(const coverage::FunctionRecord &Function) { 36 return PassesThreshold(FunctionCoverageSummary::get(Function) 37 .RegionCoverage.getPercentCovered()); 38 } 39 40 bool LineCoverageFilter::matches(const coverage::FunctionRecord &Function) { 41 return PassesThreshold( 42 FunctionCoverageSummary::get(Function).LineCoverage.getPercentCovered()); 43 } 44 45 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) { 46 Filters.push_back(std::move(Filter)); 47 } 48 49 bool CoverageFilters::matches(const coverage::FunctionRecord &Function) { 50 for (const auto &Filter : Filters) { 51 if (Filter->matches(Function)) 52 return true; 53 } 54 return false; 55 } 56 57 bool 58 CoverageFiltersMatchAll::matches(const coverage::FunctionRecord &Function) { 59 for (const auto &Filter : Filters) { 60 if (!Filter->matches(Function)) 61 return false; 62 } 63 return true; 64 } 65