Skip to content

Commit c58e4bb

Browse files
committed
fixes
Signed-off-by: Javan Lacerda <javanlacerda@google.com>
1 parent 3348931 commit c58e4bb

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

src/clusterfuzz/_internal/cron/schedule_fuzz.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616
import collections
1717
import random
1818
import time
19-
from typing import Dict
20-
from typing import List
2119

2220
from google.cloud import monitoring_v3
2321

2422
from clusterfuzz._internal.base import feature_flags
2523
from clusterfuzz._internal.base import tasks
2624
from clusterfuzz._internal.base import utils
27-
from clusterfuzz._internal.config import local_config
2825
from clusterfuzz._internal.datastore import data_types
2926
from clusterfuzz._internal.datastore import ndb_utils
3027
from clusterfuzz._internal.google_cloud_utils import credentials
3128
from clusterfuzz._internal.metrics import logs
3229

33-
# TODO(metzman): Actually implement this.
34-
CPUS_PER_FUZZ_JOB = 2
30+
PREPROCESS_TARGET_SIZE_DEFAULT = 10000
3531

3632

3733
def get_queue_size(creds, project_id, subscription_id):
@@ -103,7 +99,7 @@ def copy(self):
10399
class OssfuzzFuzzTaskScheduler(BaseFuzzTaskScheduler):
104100
"""Fuzz task scheduler for OSS-Fuzz."""
105101

106-
def get_fuzz_tasks(self) -> Dict[str, tasks.Task]:
102+
def get_fuzz_tasks(self) -> list[tasks.Task]:
107103
# TODO(metzman): Handle high end.
108104
# A job's weight is determined by its own weight and the weight of the
109105
# project is a part of. First get project weights.
@@ -166,12 +162,11 @@ def get_fuzz_tasks(self) -> Dict[str, tasks.Task]:
166162
for fuzz_task_candidate in fuzz_task_candidates:
167163
weights.append(fuzz_task_candidate.weight)
168164

169-
# TODO(metzman): Handle high-end jobs correctly.
170-
num_instances = self.num_tasks
171-
logs.info(f'Scheduling {num_instances} fuzz tasks for OSS-Fuzz.')
165+
fuzz_tasks_count = self.num_tasks
166+
logs.info(f'Scheduling {fuzz_tasks_count} fuzz tasks for OSS-Fuzz.')
172167

173168
choices = random.choices(
174-
fuzz_task_candidates, weights=weights, k=num_instances)
169+
fuzz_task_candidates, weights=weights, k=fuzz_tasks_count)
175170
fuzz_tasks = [
176171
tasks.Task(
177172
'fuzz',
@@ -189,20 +184,10 @@ def get_fuzz_tasks(self) -> Dict[str, tasks.Task]:
189184
class ChromeFuzzTaskScheduler(BaseFuzzTaskScheduler):
190185
"""Fuzz task scheduler for Chrome."""
191186

192-
def __init__(self, *args, **kwargs):
193-
super().__init__(*args, **kwargs)
194-
self._apply_project_limit()
195-
196-
def _apply_project_limit(self):
197-
conf = local_config.ProjectConfig()
198-
max_cpus_per_schedule = conf.get('max_cpus_per_schedule')
199-
if max_cpus_per_schedule:
200-
max_tasks = int(max_cpus_per_schedule / CPUS_PER_FUZZ_JOB)
201-
self.num_tasks = min(self.num_tasks, max_tasks)
202-
203-
def get_fuzz_tasks(self) -> List[tasks.Task]:
187+
def get_fuzz_tasks(self) -> list[tasks.Task]:
204188
"""Returns fuzz tasks for chrome, weighted by job weight."""
205189
logs.info('Getting jobs for Chrome.')
190+
206191
candidates_by_job = {}
207192
# Only consider linux jobs for chrome fuzzing.
208193
job_query = data_types.Job.query(data_types.Job.platform == 'LINUX')
@@ -227,14 +212,14 @@ def get_fuzz_tasks(self) -> List[tasks.Task]:
227212
fuzz_task_candidates.append(fuzz_task_candidate)
228213

229214
weights = [candidate.weight for candidate in fuzz_task_candidates]
230-
num_instances = self.num_tasks
231-
logs.info(f'Scheduling {num_instances} fuzz tasks for Chrome.')
215+
fuzz_tasks_count = self.num_tasks
216+
logs.info(f'Scheduling {fuzz_tasks_count} fuzz tasks for Chrome.')
232217

233218
if not fuzz_task_candidates:
234219
return []
235220

236221
choices = random.choices(
237-
fuzz_task_candidates, weights=weights, k=num_instances)
222+
fuzz_task_candidates, weights=weights, k=fuzz_tasks_count)
238223
fuzz_tasks = [
239224
tasks.Task(
240225
'fuzz',
@@ -246,7 +231,7 @@ def get_fuzz_tasks(self) -> List[tasks.Task]:
246231
return fuzz_tasks
247232

248233

249-
def get_fuzz_tasks(num_tasks: int) -> [tasks.Task]:
234+
def get_fuzz_tasks(num_tasks: int) -> list[tasks.Task]:
250235
if utils.is_oss_fuzz():
251236
scheduler = OssfuzzFuzzTaskScheduler(num_tasks)
252237
else:
@@ -255,9 +240,6 @@ def get_fuzz_tasks(num_tasks: int) -> [tasks.Task]:
255240
return fuzz_tasks
256241

257242

258-
PREPROCESS_TARGET_SIZE_DEFAULT = 10000
259-
260-
261243
def schedule_fuzz_tasks() -> bool:
262244
"""Schedules fuzz tasks."""
263245

0 commit comments

Comments
 (0)