2021-06-23 14:30:11 +00:00
|
|
|
# Copyright 2021 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
"""Module for generating coverage reports."""
|
|
|
|
import os
|
|
|
|
|
2021-08-05 20:27:24 +00:00
|
|
|
import base_runner_utils
|
2021-08-10 18:10:10 +00:00
|
|
|
import fuzz_target
|
2021-08-05 20:27:24 +00:00
|
|
|
import utils
|
2021-06-23 14:30:11 +00:00
|
|
|
|
|
|
|
|
2021-08-05 20:27:24 +00:00
|
|
|
def run_coverage_command(config, workspace):
|
2021-06-23 14:30:11 +00:00
|
|
|
"""Runs the coverage command in base-runner to generate a coverage report."""
|
2021-08-05 20:27:24 +00:00
|
|
|
env = base_runner_utils.get_env(config, workspace)
|
|
|
|
env['HTTP_PORT'] = ''
|
|
|
|
env['COVERAGE_EXTRA_ARGS'] = ''
|
|
|
|
env['CORPUS_DIR'] = workspace.corpora
|
|
|
|
env['COVERAGE_OUTPUT_DIR'] = workspace.coverage_report
|
|
|
|
command = 'coverage'
|
|
|
|
return utils.execute(command, env=env)
|
2021-06-23 14:30:11 +00:00
|
|
|
|
|
|
|
|
2021-06-30 14:34:42 +00:00
|
|
|
def download_corpora(fuzz_target_paths, clusterfuzz_deployment):
|
|
|
|
"""Downloads corpora for fuzz targets in |fuzz_target_paths| using
|
2021-07-22 15:09:49 +00:00
|
|
|
|clusterfuzz_deployment| to download corpora from ClusterFuzz/OSS-Fuzz."""
|
2021-06-23 14:30:11 +00:00
|
|
|
for target_path in fuzz_target_paths:
|
2021-08-10 18:10:10 +00:00
|
|
|
target_name = os.path.basename(target_path)
|
|
|
|
corpus_dir = fuzz_target.get_fuzz_target_corpus_dir(
|
|
|
|
clusterfuzz_deployment.workspace, target_name)
|
|
|
|
clusterfuzz_deployment.download_corpus(target_name, corpus_dir)
|
2021-06-23 14:30:11 +00:00
|
|
|
|
|
|
|
|
2021-06-30 14:34:42 +00:00
|
|
|
def generate_coverage_report(fuzz_target_paths, workspace,
|
|
|
|
clusterfuzz_deployment, config):
|
2021-06-23 14:30:11 +00:00
|
|
|
"""Generates a coverage report using Clang's source based coverage."""
|
2021-06-30 14:34:42 +00:00
|
|
|
download_corpora(fuzz_target_paths, clusterfuzz_deployment)
|
2021-08-05 20:27:24 +00:00
|
|
|
run_coverage_command(config, workspace)
|
2021-07-21 16:19:47 +00:00
|
|
|
clusterfuzz_deployment.upload_coverage()
|