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( 21 const coverage::CoverageMapping &, 22 const coverage::FunctionRecord &Function) const { 23 StringRef FuncName = Function.Name; 24 return FuncName.find(Name) != StringRef::npos; 25 } 26 27 bool NameRegexCoverageFilter::matches( 28 const coverage::CoverageMapping &, 29 const coverage::FunctionRecord &Function) const { 30 return llvm::Regex(Regex).match(Function.Name); 31 } 32 33 bool NameWhitelistCoverageFilter::matches( 34 const coverage::CoverageMapping &, 35 const coverage::FunctionRecord &Function) const { 36 return Whitelist.inSection("llvmcov", "whitelist_fun", Function.Name); 37 } 38 39 bool RegionCoverageFilter::matches( 40 const coverage::CoverageMapping &CM, 41 const coverage::FunctionRecord &Function) const { 42 return PassesThreshold(FunctionCoverageSummary::get(CM, Function) 43 .RegionCoverage.getPercentCovered()); 44 } 45 46 bool LineCoverageFilter::matches( 47 const coverage::CoverageMapping &CM, 48 const coverage::FunctionRecord &Function) const { 49 return PassesThreshold(FunctionCoverageSummary::get(CM, Function) 50 .LineCoverage.getPercentCovered()); 51 } 52 53 void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) { 54 Filters.push_back(std::move(Filter)); 55 } 56 57 bool CoverageFilters::matches(const coverage::CoverageMapping &CM, 58 const coverage::FunctionRecord &Function) const { 59 for (const auto &Filter : Filters) { 60 if (Filter->matches(CM, Function)) 61 return true; 62 } 63 return false; 64 } 65 66 bool CoverageFiltersMatchAll::matches( 67 const coverage::CoverageMapping &CM, 68 const coverage::FunctionRecord &Function) const { 69 for (const auto &Filter : Filters) { 70 if (!Filter->matches(CM, Function)) 71 return false; 72 } 73 return true; 74 } 75