Skip to content

Commit 2c733ba

Browse files
authored
Make target_experiment with with OSS-Fuzz-Gen. (google#12691)
OSS-Fuzz-Gen creates fake project names, but for cached images to work we need the real name.
1 parent 51e01dc commit 2c733ba

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Diff for: infra/build/functions/build_project.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,15 @@ def __init__(self, name, project_yaml, dockerfile):
167167
else:
168168
self.main_repo = ''
169169

170+
# This is set to enable build infra to use cached images (which are
171+
# specific to a sanitizer).
172+
# TODO: find a better way to handle this.
170173
self.cached_sanitizer = None
171174

175+
# This is used by OSS-Fuzz-Gen, which generates fake project names for each
176+
# benchmark. We still need access to the real project name in some cases.
177+
self.real_name = self.name
178+
172179
@property
173180
def sanitizers(self):
174181
"""Returns processed sanitizers."""
@@ -184,7 +191,7 @@ def image(self):
184191
return f'gcr.io/{build_lib.IMAGE_PROJECT}/{self.name}'
185192

186193
def cached_image(self, sanitizer):
187-
return _CACHED_IMAGE.format(name=self.name, sanitizer=sanitizer)
194+
return _CACHED_IMAGE.format(name=self.real_name, sanitizer=sanitizer)
188195

189196

190197
def get_last_step_id(steps):

Diff for: infra/build/functions/target_experiment.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@
2626
import build_project
2727

2828

29-
def run_experiment(project_name, target_name, args, output_path, errlog_path,
30-
build_output_path, upload_corpus_path, upload_coverage_path,
31-
experiment_name, upload_reproducer_path, tags,
32-
use_cached_image):
29+
def run_experiment(project_name,
30+
target_name,
31+
args,
32+
output_path,
33+
errlog_path,
34+
build_output_path,
35+
upload_corpus_path,
36+
upload_coverage_path,
37+
experiment_name,
38+
upload_reproducer_path,
39+
tags,
40+
use_cached_image,
41+
real_project_name=None):
3342
config = build_project.Config(testing=True,
3443
test_image_suffix='',
3544
repo=build_project.DEFAULT_OSS_FUZZ_REPO,
@@ -49,6 +58,11 @@ def run_experiment(project_name, target_name, args, output_path, errlog_path,
4958
project = build_project.Project(project_name, project_yaml,
5059
dockerfile_contents)
5160

61+
if real_project_name:
62+
# If the passed project name is not the actual OSS-Fuzz project name (e.g.
63+
# OSS-Fuzz-Gen generated benchmark), record the real one here.
64+
project.real_name = real_project_name
65+
5266
# Override sanitizers and engine because we only care about libFuzzer+ASan
5367
# for benchmarking purposes.
5468
build_project.set_yaml_defaults(project_yaml)
@@ -336,12 +350,19 @@ def main():
336350
parser.add_argument('--use_cached_image',
337351
action='store_true',
338352
help='Use cached images post build.')
353+
parser.add_argument(
354+
'--real_project',
355+
required=False,
356+
default='',
357+
help=('The real OSS-Fuzz project name (e.g. if `--project` '
358+
'is an autogenerated project name).'))
339359
args = parser.parse_args()
340360

341361
run_experiment(args.project, args.target, args.args, args.upload_output_log,
342362
args.upload_err_log, args.upload_build_log, args.upload_corpus,
343363
args.upload_coverage, args.experiment_name,
344-
args.upload_reproducer, args.tags, args.use_cached_image)
364+
args.upload_reproducer, args.tags, args.use_cached_image,
365+
args.real_project)
345366

346367

347368
if __name__ == '__main__':

0 commit comments

Comments
 (0)