Skip to content

Commit

Permalink
Allow integers in parallel-fuzzing to force the number of cores
Browse files Browse the repository at this point in the history
  • Loading branch information
JarLob committed Feb 25, 2025
1 parent 8a0c23f commit 2ec479f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion infra/cifuzz/actions/run_fuzzers/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inputs:
required: false
default: False
parallel-fuzzing:
description: "Whether to use all available cores for fuzzing."
description: "How many cores to use cores for fuzzing. A specific number, True - all available cores or False to run single threaded on a single core."
required: false
default: false
output-sarif:
Expand Down
2 changes: 1 addition & 1 deletion infra/cifuzz/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self):
self.build_integration_path = (
constants.DEFAULT_EXTERNAL_BUILD_INTEGRATION_PATH)

self.parallel_fuzzing = environment.get_bool('PARALLEL_FUZZING', False)
self.parallel_fuzzing = environment.get('PARALLEL_FUZZING', False)
self.extra_environment_variables = _get_extra_environment_variables()
self.output_sarif = environment.get_bool('OUTPUT_SARIF', False)

Expand Down
2 changes: 1 addition & 1 deletion infra/cifuzz/external-actions/run_fuzzers/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ inputs:
required: false
default: False
parallel-fuzzing:
description: "Whether to use all available cores for fuzzing."
description: "How many cores to use cores for fuzzing. A specific number, True - all available cores or False to run single threaded on a single core."
required: false
default: false
output-sarif:
Expand Down
18 changes: 13 additions & 5 deletions infra/cifuzz/fuzz_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@
['testcase', 'stacktrace', 'corpus_path'])


def get_libfuzzer_parallel_options():
def get_libfuzzer_parallel_options(option):
"""Returns a list containing options to pass to libFuzzer to fuzz using all
available cores."""
cpu_count = str(multiprocessing.cpu_count())
available or the specified number of cores."""
if option == 'true' or (isinstance(option, bool) and option == True):
cpu_count = str(multiprocessing.cpu_count())
else:
cpu_count = option
return [f'-jobs={cpu_count}', f'-workers={cpu_count}']


Expand Down Expand Up @@ -190,13 +193,18 @@ def fuzz(self, batch=False) -> Optional[FuzzResult]:
if not self.config.report_ooms:
options.arguments.extend(LIBFUZZER_OPTIONS_NO_REPORT_OOM)

if self.config.parallel_fuzzing:
if (self.config.parallel_fuzzing == 'true' or
(isinstance(self.config.parallel_fuzzing, int) and
not isinstance(self.config.parallel_fuzzing, bool)) or
(isinstance(self.config.parallel_fuzzing, bool) and
self.config.parallel_fuzzing == True)):
if self.config.sanitizer == 'memory':
# TODO(https://github.com/google/oss-fuzz/issues/11915): Don't gate
# this after jobs is fixed for MSAN.
logging.info('Not using jobs because it breaks MSAN.')
else:
options.arguments.extend(get_libfuzzer_parallel_options())
options.arguments.extend(
get_libfuzzer_parallel_options(self.config.parallel_fuzzing))

result = engine_impl.fuzz(self.target_path, options, artifacts_dir,
self.duration)
Expand Down

0 comments on commit 2ec479f

Please sign in to comment.