Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit f1c37d8

Browse files
authored
Factor out build_job
1 parent b1ef14f commit f1c37d8

File tree

1 file changed

+77
-61
lines changed

1 file changed

+77
-61
lines changed

src/integration-tests/integration-test.py

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def launch(
538538
) -> List[UUID]:
539539
"""Launch all of the fuzzing templates"""
540540

541-
pools = {}
541+
pools: dict[OS, Pool] = {}
542542
if unmanaged_pool is not None:
543543
pools[unmanaged_pool.the_os] = self.of.pools.get(unmanaged_pool.pool_name)
544544
else:
@@ -559,12 +559,14 @@ def launch(
559559

560560
self.logger.info("launching: %s", target)
561561

562+
setup: Directory | str | None
562563
if config.setup_dir is None:
563-
setup = (
564-
Directory(os.path.join(path, target)) if config.use_setup else None
565-
)
564+
if config.use_setup:
565+
setup = Directory(os.path.join(path, target))
566+
else:
567+
setup = None
566568
else:
567-
setup = config.setup_dir
569+
setup = Directory(config.setup_dir)
568570

569571
target_exe = File(os.path.join(path, target, config.target_exe))
570572
inputs = (
@@ -577,10 +579,31 @@ def launch(
577579
setup = Directory(os.path.join(setup, config.nested_setup_dir))
578580

579581
job: Optional[Job] = None
580-
if config.template == TemplateType.libfuzzer:
581-
# building the extra_setup container to test this variable substitution
582-
extra_setup_container = self.of.containers.create("extra-setup")
583-
job = self.of.template.libfuzzer.basic(
582+
job = self.build_job(duration, pools, target, config, setup, target_exe, inputs)
583+
584+
if config.inject_fake_regression and job is not None:
585+
self.of.debug.notification.job(job.job_id)
586+
587+
if not job:
588+
raise Exception("missing job")
589+
590+
job_ids.append(job.job_id)
591+
592+
return job_ids
593+
594+
def build_job(
595+
self,
596+
duration: int,
597+
pools: dict[OS, Pool],
598+
target: str,
599+
config: Integration,
600+
setup: Optional[Directory],
601+
target_exe: File,
602+
inputs: Optional[Directory]) -> Optional[Job]:
603+
if config.template == TemplateType.libfuzzer:
604+
# building the extra_setup container to test this variable substitution
605+
extra_setup_container = self.of.containers.create("extra-setup")
606+
return self.of.template.libfuzzer.basic(
584607
self.project,
585608
target,
586609
BUILD,
@@ -595,20 +618,20 @@ def launch(
595618
fuzzing_target_options=config.fuzzing_target_options,
596619
extra_setup_container=Container(extra_setup_container.name),
597620
)
598-
elif config.template == TemplateType.libfuzzer_dotnet:
599-
if setup is None:
600-
raise Exception("setup required for libfuzzer_dotnet")
601-
if config.target_class is None:
602-
raise Exception("target_class required for libfuzzer_dotnet")
603-
if config.target_method is None:
604-
raise Exception("target_method required for libfuzzer_dotnet")
605-
606-
job = self.of.template.libfuzzer.dotnet(
621+
elif config.template == TemplateType.libfuzzer_dotnet:
622+
if setup is None:
623+
raise Exception("setup required for libfuzzer_dotnet")
624+
if config.target_class is None:
625+
raise Exception("target_class required for libfuzzer_dotnet")
626+
if config.target_method is None:
627+
raise Exception("target_method required for libfuzzer_dotnet")
628+
629+
return self.of.template.libfuzzer.dotnet(
607630
self.project,
608631
target,
609632
BUILD,
610633
pools[config.os].name,
611-
target_dll=config.target_exe,
634+
target_dll=File(config.target_exe),
612635
inputs=inputs,
613636
setup_dir=setup,
614637
duration=duration,
@@ -617,8 +640,8 @@ def launch(
617640
target_class=config.target_class,
618641
target_method=config.target_method,
619642
)
620-
elif config.template == TemplateType.libfuzzer_qemu_user:
621-
job = self.of.template.libfuzzer.qemu_user(
643+
elif config.template == TemplateType.libfuzzer_qemu_user:
644+
return self.of.template.libfuzzer.qemu_user(
622645
self.project,
623646
target,
624647
BUILD,
@@ -629,8 +652,8 @@ def launch(
629652
vm_count=1,
630653
target_options=config.target_options,
631654
)
632-
elif config.template == TemplateType.radamsa:
633-
job = self.of.template.radamsa.basic(
655+
elif config.template == TemplateType.radamsa:
656+
return self.of.template.radamsa.basic(
634657
self.project,
635658
target,
636659
BUILD,
@@ -643,8 +666,8 @@ def launch(
643666
duration=duration,
644667
vm_count=1,
645668
)
646-
elif config.template == TemplateType.afl:
647-
job = self.of.template.afl.basic(
669+
elif config.template == TemplateType.afl:
670+
return self.of.template.afl.basic(
648671
self.project,
649672
target,
650673
BUILD,
@@ -656,18 +679,8 @@ def launch(
656679
vm_count=1,
657680
target_options=config.target_options,
658681
)
659-
else:
660-
raise NotImplementedError
661-
662-
if config.inject_fake_regression and job is not None:
663-
self.of.debug.notification.job(job.job_id)
664-
665-
if not job:
666-
raise Exception("missing job")
667-
668-
job_ids.append(job.job_id)
669-
670-
return job_ids
682+
else:
683+
raise NotImplementedError
671684

672685
def check_task(
673686
self, job: Job, task: Task, scalesets: List[Scaleset]
@@ -736,15 +749,16 @@ def check_jobs(
736749
job_tasks[job.job_id] = tasks
737750
check_containers[job.job_id] = {}
738751
for task in tasks:
739-
for container in task.config.containers:
740-
if container.type in TARGETS[job.config.name].wait_for_files:
741-
count = TARGETS[job.config.name].wait_for_files[container.type]
742-
check_containers[job.job_id][container.name] = (
743-
ContainerWrapper(
744-
self.of.containers.get(container.name).sas_url
745-
),
746-
count,
747-
)
752+
if task.config.containers:
753+
for container in task.config.containers:
754+
if container.type in TARGETS[job.config.name].wait_for_files:
755+
count = TARGETS[job.config.name].wait_for_files[container.type]
756+
check_containers[job.job_id][container.name] = (
757+
ContainerWrapper(
758+
self.of.containers.get(container.name).sas_url
759+
),
760+
count,
761+
)
748762

749763
self.success = True
750764
self.logger.info("checking %d jobs", len(jobs))
@@ -861,16 +875,17 @@ def check_jobs_impl() -> Tuple[bool, str, bool]:
861875

862876
def get_job_crash_report(self, job_id: UUID) -> Optional[Tuple[Container, str]]:
863877
for task in self.of.tasks.list(job_id=job_id, state=None):
864-
for container in task.config.containers:
865-
if container.type not in [
866-
ContainerType.unique_reports,
867-
ContainerType.reports,
868-
]:
869-
continue
878+
if task.config.containers:
879+
for container in task.config.containers:
880+
if container.type not in [
881+
ContainerType.unique_reports,
882+
ContainerType.reports,
883+
]:
884+
continue
870885

871-
files = self.of.containers.files.list(container.name)
872-
if len(files.files) > 0:
873-
return (container.name, files.files[0])
886+
files = self.of.containers.files.list(container.name)
887+
if len(files.files) > 0:
888+
return (container.name, files.files[0])
874889
return None
875890

876891
def launch_repro(
@@ -1044,12 +1059,13 @@ def cleanup(self) -> None:
10441059
container_names = set()
10451060
for job in jobs:
10461061
for task in self.of.tasks.list(job_id=job.job_id, state=None):
1047-
for container in task.config.containers:
1048-
if container.type in [
1049-
ContainerType.reports,
1050-
ContainerType.unique_reports,
1051-
]:
1052-
container_names.add(container.name)
1062+
if task.config.containers:
1063+
for container in task.config.containers:
1064+
if container.type in [
1065+
ContainerType.reports,
1066+
ContainerType.unique_reports,
1067+
]:
1068+
container_names.add(container.name)
10531069

10541070
for repro in self.of.repro.list():
10551071
if repro.config.container in container_names:

0 commit comments

Comments
 (0)