2018-01-31 10:21:44 +00:00
|
|
|
# Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2019-02-18 14:01:33 +00:00
|
|
|
# for py2/py3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2018-01-31 10:21:44 +00:00
|
|
|
import signal
|
|
|
|
|
|
|
|
from . import base
|
2018-02-20 17:23:37 +00:00
|
|
|
from testrunner.local import utils
|
2018-01-31 10:21:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SignalProc(base.TestProcObserver):
|
|
|
|
def __init__(self):
|
|
|
|
super(SignalProc, self).__init__()
|
2018-02-20 17:23:37 +00:00
|
|
|
self.exit_code = utils.EXIT_CODE_PASS
|
2018-01-31 10:21:44 +00:00
|
|
|
|
2018-01-31 11:04:33 +00:00
|
|
|
def setup(self, *args, **kwargs):
|
|
|
|
super(SignalProc, self).setup(*args, **kwargs)
|
|
|
|
# It should be called after processors are chained together to not loose
|
|
|
|
# catched signal.
|
2018-01-31 10:21:44 +00:00
|
|
|
signal.signal(signal.SIGINT, self._on_ctrlc)
|
2018-02-20 17:23:37 +00:00
|
|
|
signal.signal(signal.SIGTERM, self._on_sigterm)
|
2018-01-31 10:21:44 +00:00
|
|
|
|
|
|
|
def _on_ctrlc(self, _signum, _stack_frame):
|
2019-02-18 14:01:33 +00:00
|
|
|
print('>>> Ctrl-C detected, early abort...')
|
2018-02-20 17:23:37 +00:00
|
|
|
self.exit_code = utils.EXIT_CODE_INTERRUPTED
|
|
|
|
self.stop()
|
|
|
|
|
|
|
|
def _on_sigterm(self, _signum, _stack_frame):
|
2019-02-18 14:01:33 +00:00
|
|
|
print('>>> SIGTERM received, early abort...')
|
2018-02-20 17:23:37 +00:00
|
|
|
self.exit_code = utils.EXIT_CODE_TERMINATED
|
|
|
|
self.stop()
|