Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 2 problems in target_experiment.py #13170

Merged
merged 3 commits into from
Mar 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 5 additions & 42 deletions infra/build/functions/target_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import build_lib
import build_project

# 12 hours, allowing more than enough waiting time before cloud build starts.
build_lib.BUILD_TIMEOUT = 12 * 60 * 60


def run_experiment(project_name,
target_name,
args,
output_path,
errlog_path,
build_output_path,
upload_corpus_path,
upload_coverage_path,
Expand Down Expand Up @@ -72,16 +74,11 @@ def run_experiment(project_name,
# OSS-Fuzz-Gen generated benchmark), record the real one here.
project.real_name = real_project_name

jcc_env = [
f'CC=clang-jcc',
f'CXX=clang++-jcc',
]
steps = build_project.get_build_steps_for_project(
project, config, additional_env=jcc_env, use_caching=use_cached_image)
project, config, use_caching=use_cached_image)

build = build_project.Build('libfuzzer', 'address', 'x86_64')
local_output_path = '/workspace/output.log'
local_jcc_err_path = '/workspace/err.log' # From jcc.go:360.
local_corpus_path_base = '/workspace/corpus'
local_corpus_path = os.path.join(local_corpus_path_base, target_name)
default_target_path = os.path.join(build.out, target_name)
Expand All @@ -91,33 +88,6 @@ def run_experiment(project_name,
local_stacktrace_path = os.path.join(build.out, 'stacktrace/')
fuzzer_args = ' '.join(args + [f'-artifact_prefix={local_artifact_path}'])

# Upload JCC's err.log.
if errlog_path:
compile_step_index = -1
for i, step in enumerate(steps):
step_args = step.get('args', [])
if '&& compile' in ' '.join(step_args):
compile_step_index = i
break
if compile_step_index == -1:
print('Cannot find compile step.')
else:
# Insert the upload step right after compile step.
upload_jcc_err_step = {
'name':
'gcr.io/cloud-builders/gsutil',
'entrypoint':
'/bin/bash',
'args': [
'-c',
(f'test -f {local_jcc_err_path} || '
f'echo "Failed to generate JCC error log." | '
f'tee -a {local_jcc_err_path} && '
f'gsutil cp {local_jcc_err_path} {errlog_path}'),
]
}
steps.insert(compile_step_index + 1, upload_jcc_err_step)

env = build_project.get_env(project_yaml['language'], build)
env.append('RUN_FUZZER_MODE=batch')
env.append('CORPUS_DIR=' + local_corpus_path)
Expand Down Expand Up @@ -216,7 +186,6 @@ def run_experiment(project_name,
# Build for coverage.
build = build_project.Build('libfuzzer', 'coverage', 'x86_64')
env = build_project.get_env(project_yaml['language'], build)
env.extend(jcc_env)

if use_cached_image:
project.cached_sanitizer = 'coverage'
Expand Down Expand Up @@ -298,8 +267,6 @@ def run_experiment(project_name,
})

credentials, _ = google.auth.default()
# Empirically, 3 hours is more than enough for 30-minute fuzzing cloud builds.
build_lib.BUILD_TIMEOUT = 3 * 60 * 60
build_id = build_project.run_build(
project_name,
steps,
Expand Down Expand Up @@ -327,10 +294,6 @@ def main():
parser.add_argument('--upload_build_log',
required=True,
help='GCS build log location.')
parser.add_argument('--upload_err_log',
required=False,
default='',
help='GCS JCC error log location.')
parser.add_argument('--upload_output_log',
required=True,
help='GCS log location.')
Expand Down Expand Up @@ -363,7 +326,7 @@ def main():
args = parser.parse_args()

run_experiment(args.project, args.target, args.args, args.upload_output_log,
args.upload_err_log, args.upload_build_log, args.upload_corpus,
args.upload_build_log, args.upload_corpus,
args.upload_coverage, args.experiment_name,
args.upload_reproducer, args.tags, args.use_cached_image,
args.real_project)
Expand Down
Loading