-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathgenerate_coverage_report.py
More file actions
57 lines (49 loc) · 2.15 KB
/
generate_coverage_report.py
File metadata and controls
57 lines (49 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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 logging
import os
import base_runner_utils
import fuzz_target
import utils
def run_coverage_command(config, workspace):
"""Runs the coverage command in base-runner to generate a coverage report."""
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'
stdout, stderr, return_code = utils.execute(command, env=env)
if stdout:
logging.info('coverage stdout:\n%s', stdout)
if stderr:
logging.info('coverage stderr:\n%s', stderr)
if return_code:
logging.error('coverage command exited with code %d.', return_code)
return stdout, stderr, return_code
def download_corpora(fuzz_target_paths, clusterfuzz_deployment):
"""Downloads corpora for fuzz targets in |fuzz_target_paths| using
|clusterfuzz_deployment| to download corpora from ClusterFuzz/OSS-Fuzz."""
for target_path in fuzz_target_paths:
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)
def generate_coverage_report(fuzz_target_paths, workspace,
clusterfuzz_deployment, config):
"""Generates a coverage report using Clang's source based coverage."""
download_corpora(fuzz_target_paths, clusterfuzz_deployment)
run_coverage_command(config, workspace)
clusterfuzz_deployment.upload_coverage()