Skip to content

Commit f4c82ac

Browse files
Prepare to make analyze task in oss-fuzz run on uworkers. (#4368)
I'm going to migrate tasks in OSS-Fuzz one by one.
1 parent 0447e89 commit f4c82ac

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

configs/test/project.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ firebase:
5050
- google.com
5151
# - github.com
5252

53+
uworker_tasks:
54+
- analyze
55+
5356

5457
stacktrace:
5558
# Stack frames to ignore when determining the crash signature.

src/clusterfuzz/_internal/base/task_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
any other module in tasks to prevent circular imports and issues with
1616
appengine."""
1717

18+
from clusterfuzz._internal.config import local_config
1819
from clusterfuzz._internal.system import environment
1920

2021

@@ -25,11 +26,21 @@ def get_command_from_module(full_module_name: str) -> str:
2526
return module_name[:-len('_task')]
2627

2728

28-
def is_remotely_executing_utasks() -> bool:
29+
def is_remotely_executing_utasks(task=None) -> bool:
2930
"""Returns True if the utask_main portions of utasks are being remotely
3031
executed on Google cloud batch."""
31-
return bool(environment.is_production() and
32-
environment.get_value('REMOTE_UTASK_EXECUTION'))
32+
if bool(environment.is_production() and
33+
environment.get_value('REMOTE_UTASK_EXECUTION')):
34+
return True
35+
if task is None:
36+
return False
37+
return is_task_opted_into_uworker_execution(task)
38+
39+
40+
def is_task_opted_into_uworker_execution(task):
41+
# TODO(metzman): Remove this after OSS-Fuzz and Chrome are at parity.
42+
uworker_tasks = local_config.ProjectConfig().get('uworker_tasks', [])
43+
return task in uworker_tasks
3344

3445

3546
class UworkerMsgParseError(RuntimeError):

src/clusterfuzz/_internal/bot/tasks/task_types.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class BaseTask:
2727
"""Base module for tasks."""
2828

2929
@staticmethod
30-
def is_execution_remote():
30+
def is_execution_remote(command=None):
31+
del command
3132
return False
3233

3334
def __init__(self, module):
@@ -73,13 +74,13 @@ def preprocess(self, task_argument, job_type, uworker_env):
7374

7475

7576
def is_no_privilege_workload(command, job):
76-
if not COMMAND_TYPES[command].is_execution_remote():
77+
if not COMMAND_TYPES[command].is_execution_remote(command):
7778
return False
7879
return batch.is_no_privilege_workload(command, job)
7980

8081

8182
def is_remote_utask(command, job):
82-
if not COMMAND_TYPES[command].is_execution_remote():
83+
if not COMMAND_TYPES[command].is_execution_remote(command):
8384
return False
8485

8586
if environment.is_uworker():
@@ -117,8 +118,8 @@ class UTask(BaseUTask):
117118
opted-in. Otherwise executes locally."""
118119

119120
@staticmethod
120-
def is_execution_remote():
121-
return task_utils.is_remotely_executing_utasks()
121+
def is_execution_remote(command=None):
122+
return task_utils.is_remotely_executing_utasks(command)
122123

123124
def execute(self, task_argument, job_type, uworker_env):
124125
"""Executes a utask."""

src/clusterfuzz/_internal/tests/core/base/task_utils_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ def test_get_command_from_module(self):
3333
task_utils.get_command_from_module('postprocess')
3434
with self.assertRaises(ValueError):
3535
task_utils.get_command_from_module('uworker_main')
36+
37+
38+
class IsTaskOptedIntoUworkerExecution(unittest.TestCase):
39+
40+
def test_opt_in(self):
41+
self.assertTrue(task_utils.is_task_opted_into_uworker_execution('analyze'))
42+
43+
def test_no_opt_in(self):
44+
self.assertFalse(task_utils.is_task_opted_into_uworker_execution('fuzz'))

0 commit comments

Comments
 (0)