Skip to content

Commit 6d4189b

Browse files
committed
extract get pruner and runner to a function
Signed-off-by: Javan Lacerda <[email protected]>
1 parent f94468c commit 6d4189b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/clusterfuzz/_internal/bot/tasks/utasks/corpus_pruning_task.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,18 @@ def _record_cross_pollination_stats(output):
615615
dataset_id='main', table_id='cross_pollination_statistics')
616616
client.insert([big_query.Insert(row=bigquery_row, insert_id=None)])
617617

618+
def _get_pruner_and_runner(context):
619+
build_directory = environment.get_value('BUILD_DIR')
620+
match context.fuzz_target.engine:
621+
case 'libFuzzer':
622+
runner = LibFuzzerRunner(build_directory, context)
623+
pruner = LibFuzzerPruner(runner)
624+
case 'centipede':
625+
runner = CentipedeRunner(build_directory, context)
626+
pruner = CentipedePruner(runner)
627+
case _:
628+
raise Exception('Corpus pruner task does not support the given engine.')
629+
return pruner, runner
618630

619631
def do_corpus_pruning(uworker_input, context, revision) -> CorpusPruningResult:
620632
"""Run corpus pruning."""
@@ -630,18 +642,8 @@ def do_corpus_pruning(uworker_input, context, revision) -> CorpusPruningResult:
630642
revision=revision, fuzz_target=context.fuzz_target.binary):
631643
raise CorpusPruningError('Failed to setup build.')
632644

633-
build_directory = environment.get_value('BUILD_DIR')
634645
start_time = datetime.datetime.utcnow()
635-
match context.fuzz_target.engine:
636-
case 'libFuzzer':
637-
runner = LibFuzzerRunner(build_directory, context)
638-
pruner = LibFuzzerPruner(runner)
639-
case 'centipede':
640-
runner = CentipedeRunner(build_directory, context)
641-
pruner = CentipedePruner(runner)
642-
case _:
643-
raise Exception('Corpus pruner task does not support the given engine.')
644-
646+
pruner, runner = _get_pruner_and_runner(context)
645647
fuzzer_binary_name = os.path.basename(runner.target_path)
646648

647649
# Get initial corpus to process from GCS.
@@ -1059,7 +1061,6 @@ def utask_main(uworker_input):
10591061
logs.error(f'Corpus pruning failed: {e}')
10601062
uworker_output = uworker_msg_pb2.Output( # pylint: disable=no-member
10611063
error_type=uworker_msg_pb2.CORPUS_PRUNING_ERROR) # pylint: disable=no-member
1062-
raise e
10631064
finally:
10641065
context.cleanup()
10651066

0 commit comments

Comments
 (0)