Skip to content

Commit d64a48d

Browse files
mi-acCommit Bot
authored andcommitted
[testrunner] Prevent erroneous overriding of signal handlers
When an overall timeout is reached, swarming sends a SIGTERM to terminate the test runner. The test runner has a signal handler on the main process to terminate all workers gracefully. Additionally, every worker process installs a signal handler for terminating ongoing tests wrapped by command.Command. Also, command.Command is used on the main process to list tests for cctest and gtest executables, which led to overriding the test runner's main signal handler. This CL disables using signal handlers in commands by default and only explicitly enables it in safe source locations. Bug: v8:8292 Change-Id: Ifceadaff75bdd2b77e761498bccbe00b6a3e265c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2002528 Reviewed-by: Tamer Tas <tmrts@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#65815}
1 parent 2cd24eb commit d64a48d

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

tools/predictable_wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def allocation_str(stdout):
3737
return line
3838
return None
3939

40-
cmd = command.Command(args[0], args[1:], timeout=TIMEOUT)
40+
cmd = command.Command(
41+
args[0], args[1:], timeout=TIMEOUT, handle_sigterm=True)
4142

4243
previous_allocations = None
4344
for run in range(1, MAX_TRIES + 1):

tools/run_perf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ def GetCommand(self, cmd_prefix, shell_dir, extra_flags=None):
479479
cmd_prefix=cmd_prefix,
480480
shell=os.path.join(shell_dir, self.binary),
481481
args=self.GetCommandFlags(extra_flags=extra_flags),
482-
timeout=self.timeout or 60)
482+
timeout=self.timeout or 60,
483+
handle_sigterm=True)
483484

484485
def ProcessOutput(self, output, result_tracker, count):
485486
"""Processes test run output and updates result tracker.

tools/testrunner/local/command.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AbortException(Exception):
4141

4242
class BaseCommand(object):
4343
def __init__(self, shell, args=None, cmd_prefix=None, timeout=60, env=None,
44-
verbose=False, resources_func=None):
44+
verbose=False, resources_func=None, handle_sigterm=False):
4545
"""Initialize the command.
4646
4747
Args:
@@ -52,6 +52,9 @@ def __init__(self, shell, args=None, cmd_prefix=None, timeout=60, env=None,
5252
env: Environment dict for execution.
5353
verbose: Print additional output.
5454
resources_func: Callable, returning all test files needed by this command.
55+
handle_sigterm: Flag indicating if SIGTERM will be used to terminate the
56+
underlying process. Should not be used from the main thread, e.g. when
57+
using a command to list tests.
5558
"""
5659
assert(timeout > 0)
5760

@@ -61,6 +64,7 @@ def __init__(self, shell, args=None, cmd_prefix=None, timeout=60, env=None,
6164
self.timeout = timeout
6265
self.env = env or {}
6366
self.verbose = verbose
67+
self.handle_sigterm = handle_sigterm
6468

6569
def execute(self):
6670
if self.verbose:
@@ -72,7 +76,9 @@ def execute(self):
7276
abort_occured = [False]
7377
def handler(signum, frame):
7478
self._abort(process, abort_occured)
75-
signal.signal(signal.SIGTERM, handler)
79+
80+
if self.handle_sigterm:
81+
signal.signal(signal.SIGTERM, handler)
7682

7783
# Variable to communicate with the timer.
7884
timeout_occured = [False]

tools/testrunner/objects/testcase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def _create_cmd(self, shell, params, env, timeout):
271271
timeout=timeout,
272272
verbose=self._test_config.verbose,
273273
resources_func=self._get_resources,
274+
handle_sigterm=True,
274275
)
275276

276277
def _parse_source_flags(self, source=None):

tools/unittests/run_perf_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ def _VerifyMock(self, binary, *args, **kwargs):
191191
cmd_prefix=[],
192192
shell=shell,
193193
args=list(args),
194-
timeout=kwargs.get('timeout', 60))
194+
timeout=kwargs.get('timeout', 60),
195+
handle_sigterm=True)
195196

196197
def _VerifyMockMultiple(self, *args, **kwargs):
197198
self.assertEqual(len(args), len(command.Command.call_args_list))
@@ -200,7 +201,8 @@ def _VerifyMockMultiple(self, *args, **kwargs):
200201
'cmd_prefix': [],
201202
'shell': os.path.join(os.path.dirname(BASE_DIR), arg[0]),
202203
'args': list(arg[1:]),
203-
'timeout': kwargs.get('timeout', 60)
204+
'timeout': kwargs.get('timeout', 60),
205+
'handle_sigterm': True,
204206
}
205207
self.assertTupleEqual((expected, ), actual)
206208

0 commit comments

Comments
 (0)