Skip to content

Commit

Permalink
Make target_experiment with with OSS-Fuzz-Gen. (#12691)
Browse files Browse the repository at this point in the history
OSS-Fuzz-Gen creates fake project names, but for cached images to work
we need the real name.
  • Loading branch information
oliverchang authored Nov 6, 2024
1 parent 51e01dc commit 2c733ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion infra/build/functions/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,15 @@ def __init__(self, name, project_yaml, dockerfile):
else:
self.main_repo = ''

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

# This is used by OSS-Fuzz-Gen, which generates fake project names for each
# benchmark. We still need access to the real project name in some cases.
self.real_name = self.name

@property
def sanitizers(self):
"""Returns processed sanitizers."""
Expand All @@ -184,7 +191,7 @@ def image(self):
return f'gcr.io/{build_lib.IMAGE_PROJECT}/{self.name}'

def cached_image(self, sanitizer):
return _CACHED_IMAGE.format(name=self.name, sanitizer=sanitizer)
return _CACHED_IMAGE.format(name=self.real_name, sanitizer=sanitizer)


def get_last_step_id(steps):
Expand Down
31 changes: 26 additions & 5 deletions infra/build/functions/target_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@
import build_project


def run_experiment(project_name, target_name, args, output_path, errlog_path,
build_output_path, upload_corpus_path, upload_coverage_path,
experiment_name, upload_reproducer_path, tags,
use_cached_image):
def run_experiment(project_name,
target_name,
args,
output_path,
errlog_path,
build_output_path,
upload_corpus_path,
upload_coverage_path,
experiment_name,
upload_reproducer_path,
tags,
use_cached_image,
real_project_name=None):
config = build_project.Config(testing=True,
test_image_suffix='',
repo=build_project.DEFAULT_OSS_FUZZ_REPO,
Expand All @@ -49,6 +58,11 @@ def run_experiment(project_name, target_name, args, output_path, errlog_path,
project = build_project.Project(project_name, project_yaml,
dockerfile_contents)

if real_project_name:
# If the passed project name is not the actual OSS-Fuzz project name (e.g.
# OSS-Fuzz-Gen generated benchmark), record the real one here.
project.real_name = real_project_name

# Override sanitizers and engine because we only care about libFuzzer+ASan
# for benchmarking purposes.
build_project.set_yaml_defaults(project_yaml)
Expand Down Expand Up @@ -336,12 +350,19 @@ def main():
parser.add_argument('--use_cached_image',
action='store_true',
help='Use cached images post build.')
parser.add_argument(
'--real_project',
required=False,
default='',
help=('The real OSS-Fuzz project name (e.g. if `--project` '
'is an autogenerated project name).'))
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_coverage, args.experiment_name,
args.upload_reproducer, args.tags, args.use_cached_image)
args.upload_reproducer, args.tags, args.use_cached_image,
args.real_project)


if __name__ == '__main__':
Expand Down

0 comments on commit 2c733ba

Please sign in to comment.