def test_invalid_project_json(self): """Tests an invalid project JSON results in None being returned.""" with mock.patch('coverage._get_latest_cov_report_info', return_value=None): coverage_getter = coverage.OssFuzzCoverageGetter( PROJECT_NAME, REPO_PATH) self.assertIsNone( coverage_getter.get_target_coverage_report(FUZZ_TARGET))
def remove_unaffected_fuzz_targets(project_name, 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. 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. This function will not delete fuzz targets unless it knows that the fuzz 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.') return logging.info('Files changed in PR: %s', files_changed) fuzz_target_paths = utils.get_fuzz_targets(out_dir) if not fuzz_target_paths: # Nothing to remove. 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: # 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, files_changed) if not affected_fuzz_targets: logging.info( 'No affected fuzz targets detected, keeping all as fallback.') return logging.info('Using affected fuzz targets: %s.', affected_fuzz_targets) unaffected_fuzz_targets = set(fuzz_target_paths) - affected_fuzz_targets logging.info('Removing unaffected fuzz targets: %s.', unaffected_fuzz_targets) # Remove all the targets that are not affected. for fuzz_target_path in unaffected_fuzz_targets: try: os.remove(fuzz_target_path) except OSError as error: logging.error('%s occurred while removing file %s', error, fuzz_target_path)
def setUp(self): with mock.patch('coverage._get_latest_cov_report_info', return_value=PROJECT_COV_INFO): self.coverage_getter = coverage.OssFuzzCoverageGetter( PROJECT_NAME, REPO_PATH)
def test_invalid_project_json(self, _): """Tests an invalid project JSON results in None being returned.""" coverage_getter = coverage.OssFuzzCoverageGetter(PROJECT_NAME, REPO_PATH) self.assertIsNone(coverage_getter.get_target_coverage_report(FUZZ_TARGET))