From cdd78c464bfc5b45ed661f4f51eb62d3b8ec2efa Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Thu, 22 Jul 2021 08:09:49 -0700 Subject: [PATCH] [cifuzz] Fix corpus usage in coverage reports (#6093) Fixes #6089 --- infra/base-images/base-runner/coverage | 8 +++++--- infra/cifuzz/generate_coverage_report.py | 4 ++-- infra/cifuzz/generate_coverage_report_test.py | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/infra/base-images/base-runner/coverage b/infra/base-images/base-runner/coverage index ea6acc34d..54154212d 100755 --- a/infra/base-images/base-runner/coverage +++ b/infra/base-images/base-runner/coverage @@ -61,6 +61,8 @@ objects="" # Number of CPUs available, this is needed for running tests in parallel. NPROC=$(nproc) +CORPUS_DIR=${CORPUS_DIR:-"/corpus"} + function run_fuzz_target { local target=$1 @@ -69,7 +71,7 @@ function run_fuzz_target { local profraw_file="$DUMPS_DIR/$target.%1m.profraw" local profraw_file_mask="$DUMPS_DIR/$target.*.profraw" local profdata_file="$DUMPS_DIR/$target.profdata" - local corpus_real="/corpus/${target}" + local corpus_real="$CORPUS_DIR/${target}" # -merge=1 requires an output directory, create a new, empty dir for that. local corpus_dummy="$OUT/dummy_corpus_dir_for_${target}" @@ -122,7 +124,7 @@ function run_go_fuzz_target { local target=$1 echo "Running go target $target" - export FUZZ_CORPUS_DIR="/corpus/${target}/" + export FUZZ_CORPUS_DIR="$CORPUS_DIR/${target}/" export FUZZ_PROFILE_NAME="$DUMPS_DIR/$target.perf" $OUT/$target -test.coverprofile $DUMPS_DIR/$target.profdata &> $LOGS_DIR/$target.log # translate from golangish paths to current absolute paths @@ -138,7 +140,7 @@ function run_java_fuzz_target { local exec_file="$DUMPS_DIR/$target.exec" local class_dump_dir="$DUMPS_DIR/${target}_classes/" mkdir "$class_dump_dir" - local corpus_real="/corpus/${target}" + local corpus_real="$CORPUS_DIR/${target}" # -merge=1 requires an output directory, create a new, empty dir for that. local corpus_dummy="$OUT/dummy_corpus_dir_for_${target}" diff --git a/infra/cifuzz/generate_coverage_report.py b/infra/cifuzz/generate_coverage_report.py index 7e427ab6d..fa4fc8339 100644 --- a/infra/cifuzz/generate_coverage_report.py +++ b/infra/cifuzz/generate_coverage_report.py @@ -24,6 +24,7 @@ def run_coverage_command(workspace, config): config.language) docker_args += [ '-e', 'COVERAGE_EXTRA_ARGS=', '-e', 'HTTP_PORT=', '-e', + f'CORPUS_DIR={workspace.corpora}', '-e', f'COVERAGE_OUTPUT_DIR={workspace.coverage_report}', '-t', docker.BASE_RUNNER_TAG, 'coverage' ] @@ -32,8 +33,7 @@ def run_coverage_command(workspace, config): 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.""" - # TODO(metzman): Download to /corpus dir. + |clusterfuzz_deployment| to download corpora from ClusterFuzz/OSS-Fuzz.""" for target_path in fuzz_target_paths: target = os.path.basename(target_path) clusterfuzz_deployment.download_corpus(target) diff --git a/infra/cifuzz/generate_coverage_report_test.py b/infra/cifuzz/generate_coverage_report_test.py index b5f2b489a..c34939f0f 100644 --- a/infra/cifuzz/generate_coverage_report_test.py +++ b/infra/cifuzz/generate_coverage_report_test.py @@ -40,6 +40,7 @@ class TestRunCoverageCommand(unittest.TestCase): 'OUT=/workspace/build-out', '-v', f'{workspace.workspace}:{workspace.workspace}', '-e', 'COVERAGE_EXTRA_ARGS=', '-e', 'HTTP_PORT=', '-e', + f'CORPUS_DIR={workspace.corpora}', '-e', f'COVERAGE_OUTPUT_DIR={workspace.coverage_report}', '-t', 'gcr.io/oss-fuzz-base/base-runner', 'coverage' ]