CoverageFilters.cpp 2.7 KB

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