[cifuzz] Fix corpus usage in coverage reports (#6093)

Fixes #6089
This commit is contained in:
jonathanmetzman 2021-07-22 08:09:49 -07:00 committed by GitHub
parent fdb9c9a0fd
commit cdd78c464b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -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}"

View File

@ -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)

View File

@ -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'
]