diff options
Diffstat (limited to 'infra/cifuzz/affected_fuzz_targets.py')
-rw-r--r-- | infra/cifuzz/affected_fuzz_targets.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/infra/cifuzz/affected_fuzz_targets.py b/infra/cifuzz/affected_fuzz_targets.py index f9f2242a3..be35c5cc5 100644 --- a/infra/cifuzz/affected_fuzz_targets.py +++ b/infra/cifuzz/affected_fuzz_targets.py @@ -17,19 +17,17 @@ import logging import os import sys -import coverage - # pylint: disable=wrong-import-position,import-error sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import utils -def remove_unaffected_fuzz_targets(project_name, out_dir, files_changed, - repo_path): +def remove_unaffected_fuzz_targets(clusterfuzz_deployment, out_dir, + files_changed, repo_path): """Removes all non affected fuzz targets in the out directory. Args: - project_name: The name of the relevant OSS-Fuzz project. + clusterfuzz_deployment: The ClusterFuzz deployment object. out_dir: The location of the fuzz target binaries. files_changed: A list of files changed compared to HEAD. repo_path: The location of the OSS-Fuzz repo in the docker image. @@ -38,7 +36,6 @@ def remove_unaffected_fuzz_targets(project_name, out_dir, files_changed, targets are unaffected. For example, this means that fuzz targets which don't have coverage data on will not be deleted. """ - # TODO(metzman): Make this use clusterfuzz deployment. if not files_changed: # Don't remove any fuzz targets if there is no difference from HEAD. logging.info('No files changed compared to HEAD.') @@ -52,14 +49,13 @@ def remove_unaffected_fuzz_targets(project_name, out_dir, files_changed, logging.error('No fuzz targets found in out dir.') return - coverage_getter = coverage.OssFuzzCoverageGetter(project_name, repo_path) - if not coverage_getter.fuzzer_stats_url: + coverage = clusterfuzz_deployment.get_coverage(repo_path) + if not coverage: # Don't remove any fuzz targets unless we have data. logging.error('Could not find latest coverage report.') return - affected_fuzz_targets = get_affected_fuzz_targets(coverage_getter, - fuzz_target_paths, + affected_fuzz_targets = get_affected_fuzz_targets(coverage, fuzz_target_paths, files_changed) if not affected_fuzz_targets: @@ -79,11 +75,11 @@ def remove_unaffected_fuzz_targets(project_name, out_dir, files_changed, fuzz_target_path) -def is_fuzz_target_affected(coverage_getter, fuzz_target_path, files_changed): +def is_fuzz_target_affected(coverage, fuzz_target_path, files_changed): """Returns True if a fuzz target (|fuzz_target_path|) is affected by |files_changed|.""" fuzz_target = os.path.basename(fuzz_target_path) - covered_files = coverage_getter.get_files_covered_by_target(fuzz_target) + covered_files = coverage.get_files_covered_by_target(fuzz_target) if not covered_files: # Assume a fuzz target is affected if we can't get its coverage from # OSS-Fuzz. @@ -104,13 +100,11 @@ def is_fuzz_target_affected(coverage_getter, fuzz_target_path, files_changed): return False -def get_affected_fuzz_targets(coverage_getter, fuzz_target_paths, - files_changed): +def get_affected_fuzz_targets(coverage, fuzz_target_paths, files_changed): """Returns a list of paths of affected targets.""" affected_fuzz_targets = set() for fuzz_target_path in fuzz_target_paths: - if is_fuzz_target_affected(coverage_getter, fuzz_target_path, - files_changed): + if is_fuzz_target_affected(coverage, fuzz_target_path, files_changed): affected_fuzz_targets.add(fuzz_target_path) return affected_fuzz_targets |