CoverageFilters.cpp 2.4 KB

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