Diff
Modified: trunk/Tools/ChangeLog (266223 => 266224)
--- trunk/Tools/ChangeLog 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/ChangeLog 2020-08-27 05:43:04 UTC (rev 266224)
@@ -1,3 +1,25 @@
+2020-08-26 Jonathan Bedard <[email protected]>
+
+ [webkitcorepy] Move Timeout to webkitcorepy (Part 2)
+ https://bugs.webkit.org/show_bug.cgi?id=215584
+ <rdar://problem/67270713>
+
+ Reviewed by Dewei Zhu.
+
+ * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Bump version.
+ * Scripts/libraries/webkitcorepy/webkitcorepy/timeout.py:
+ (Timeout.__enter__): Forward patch flag to disable context.
+ (Timeout.__exit__): Ditto.
+ * Scripts/webkitpy/common/timeout_context.py: Replace with webkitcorepy's Timeout object.
+ (Timeout): Deleted.
+ * Scripts/webkitpy/common/timeout_context_unittest.py: Removed.
+ * Scripts/webkitpy/port/simulator_process.py:
+ (SimulatorProcess._start): Opt-out of patching time.sleep().
+ * Scripts/webkitpy/xcode/simulated_device.py:
+ (SimulatedDevice.launch_app): Opt-out of patching time.sleep().
+ * glib/api_test_runner.py:
+ (TestRunner._run_google_test): Use specific Timeout exception.
+
2020-08-26 Carlos Alberto Lopez Perez <[email protected]>
[GTK][WPE] Add bots for generating nightly bundle packages
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (266223 => 266224)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -35,7 +35,7 @@
from webkitcorepy.subprocess_utils import TimeoutExpired, CompletedProcess, run
from webkitcorepy.output_capture import LoggerCapture, OutputCapture, OutputDuplicate
-version = Version(0, 4, 1)
+version = Version(0, 4, 2)
from webkitcorepy.autoinstall import Package, AutoInstall
if sys.version_info > (3, 0):
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/timeout.py (266223 => 266224)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/timeout.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/timeout.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -169,7 +169,7 @@
self._patch = None
def __enter__(self):
- with self.DisableAlarm():
+ with self.DisableAlarm(patch=self._patch):
self.data = "" + self._timeout, self._handler)
bisect.insort(self._process_to_timeout_map[os.getpid()], self.data)
@@ -181,7 +181,7 @@
if self._patch:
self._patch.__exit__(*args, **kwargs)
- with self.DisableAlarm():
+ with self.DisableAlarm(patch=self._patch):
if not self._process_to_timeout_map[os.getpid()]:
raise RuntimeError('No timeout registered')
self._process_to_timeout_map[os.getpid()].remove(self.data)
Modified: trunk/Tools/Scripts/webkitpy/common/timeout_context.py (266223 => 266224)
--- trunk/Tools/Scripts/webkitpy/common/timeout_context.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/webkitpy/common/timeout_context.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -20,100 +20,4 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import logging
-import math
-import os
-import signal
-import time
-import threading
-
-_log = logging.getLogger(__name__)
-
-
-class Timeout(object):
-
- thread_exception = RuntimeError('Timeout originates from a different thread')
- _process_to_timeout_map = {}
-
- class TimeoutData(object):
-
- def __init__(self, alarm_time, handler):
- self.alarm_time = alarm_time
- self.handler = handler
- self.thread_id = threading.current_thread().ident
-
- @staticmethod
- def default_handler(signum, frame):
- raise RuntimeError('Timeout alarm was triggered')
-
- @staticmethod
- def current():
- result = Timeout._process_to_timeout_map.get(os.getpid(), [])
- if not result:
- return None
- if result[0].thread_id != threading.current_thread().ident:
- _log.critical('Using both alarms and threading in the same process, this is unsupported')
- raise Timeout.thread_exception
- return result[0]
-
- def __init__(self, seconds=1, handler=None):
- if seconds == 0:
- raise RuntimeError('Cannot have a timeout of 0 seconds')
-
- if isinstance(handler, BaseException):
- exception = handler
-
- def exception_handler(signum, frame):
- raise exception
-
- handler = exception_handler
-
- self._timeout = seconds
- self._handler = handler if handler else Timeout.default_handler
- self.data = ""
-
- @staticmethod
- def _bind_timeout_data_to_alarm(data):
- def handler(signum, frame):
- assert signum == signal.SIGALRM
- if data.thread_id != threading.current_thread().ident:
- raise Timeout.thread_exception
- data.handler(signum, frame)
-
- current_time = time.time()
- if data.alarm_time <= current_time:
- handler(signal.SIGALRM, None)
-
- signal.signal(signal.SIGALRM, handler)
- signal.alarm(int(math.ceil(data.alarm_time - current_time)))
-
- def __enter__(self):
- signal.alarm(0) # Imiediatly disable the alarm so we aren't interupted.
- self.data = "" + self._timeout, self._handler)
- current_timeout = Timeout.current()
-
- # Another timeout is more urgent.
- if current_timeout and current_timeout.alarm_time < self.data.alarm_time:
- for i in range(len(Timeout._process_to_timeout_map[os.getpid()]) - 1):
- if self.data.alarm_time < Timeout._process_to_timeout_map[os.getpid()][i + 1].alarm_time:
- Timeout._process_to_timeout_map[os.getpid()].insert(i, self.data)
- break
- Timeout._process_to_timeout_map[os.getpid()].append(self.data)
-
- # This is the most urgent timeout
- else:
- Timeout._process_to_timeout_map[os.getpid()] = [self.data] + Timeout._process_to_timeout_map.get(os.getpid(), [])
-
- Timeout._bind_timeout_data_to_alarm(Timeout.current())
- return self
-
- def __exit__(self, exc_type, exc_value, traceback):
- signal.alarm(0) # Imiediatly disable the alarm so we aren't interupted.
-
- if not Timeout._process_to_timeout_map[os.getpid()]:
- raise RuntimeError('No timeout registered')
- Timeout._process_to_timeout_map[os.getpid()].remove(self.data)
- self.data = ""
-
- if Timeout._process_to_timeout_map[os.getpid()]:
- Timeout._bind_timeout_data_to_alarm(Timeout.current())
+from webkitcorepy import Timeout
Deleted: trunk/Tools/Scripts/webkitpy/common/timeout_context_unittest.py (266223 => 266224)
--- trunk/Tools/Scripts/webkitpy/common/timeout_context_unittest.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/webkitpy/common/timeout_context_unittest.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -1,98 +0,0 @@
-# Copyright (C) 2017 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import time
-import threading
-import unittest
-
-from webkitpy.common.timeout_context import Timeout
-
-
-class TimeoutContextTests(unittest.TestCase):
-
- def test_current_timeout(self):
- self.assertEqual(None, Timeout.current())
- with Timeout(1) as tmp:
- self.assertEqual(tmp.data, Timeout.current())
- self.assertEqual(None, Timeout.current())
-
- def test_invalid_timeout(self):
- self.assertRaises(RuntimeError, Timeout, 0)
-
- def test_timeout_data(self):
- tmp = Timeout(1)
- self.assertEqual(None, tmp.data)
- with tmp:
- self.assertNotEqual(None, tmp.data)
- self.assertEqual(threading.current_thread().ident, tmp.data.thread_id)
- self.assertTrue(time.time() + 1 >= tmp.data.alarm_time)
- self.assertEqual(None, tmp.data)
-
- def test_nested_inner_precedence(self):
- tmp_outer = Timeout(2)
- tmp_inner = Timeout(1)
- with tmp_outer:
- self.assertEqual(tmp_outer.data, Timeout.current())
- with tmp_inner:
- self.assertEqual(tmp_inner.data, Timeout.current())
- self.assertEqual(tmp_outer.data, Timeout.current())
- self.assertEqual(None, Timeout.current())
-
- def test_nested_outer_precedence(self):
- tmp_outer = Timeout(1)
- tmp_inner = Timeout(2)
- with tmp_outer:
- self.assertEqual(tmp_outer.data, Timeout.current())
- with tmp_inner:
- self.assertEqual(tmp_outer.data, Timeout.current())
- self.assertEqual(tmp_outer.data, Timeout.current())
- self.assertEqual(None, Timeout.current())
-
- def test_no_timeout(self):
- with Timeout(2):
- time.sleep(1)
-
- def test_basic_timeout(self):
- def should_timeout():
- with Timeout(1):
- time.sleep(2)
- self.assertRaises(RuntimeError, should_timeout)
-
- def test_exception_constructor_timeout(self):
- def should_timeout():
- with Timeout(1, Exception('This should be raised')):
- time.sleep(2)
- self.assertRaises(Exception, should_timeout)
-
- def test_nested_inner_timeout(self):
- def should_timeout():
- with Timeout(3, Exception("This shouldn't be raised")):
- with Timeout(1):
- time.sleep(2)
- self.assertRaises(RuntimeError, should_timeout)
-
- def test_nested_outer_timeout(self):
- def should_timeout():
- with Timeout(1):
- with Timeout(3, Exception("This shouldn't be raised")):
- time.sleep(2)
- self.assertRaises(RuntimeError, should_timeout)
Modified: trunk/Tools/Scripts/webkitpy/port/simulator_process.py (266223 => 266224)
--- trunk/Tools/Scripts/webkitpy/port/simulator_process.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/webkitpy/port/simulator_process.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -104,7 +104,7 @@
self._system_pid = self._pid
# FIXME <rdar://problem/57032042>: This timeout should be 15 seconds
- with Timeout(30, RuntimeError('Timed out waiting for pid {} to connect at port {}'.format(self._pid, self._target_host.listening_port()))):
+ with Timeout(30, handler=RuntimeError('Timed out waiting for pid {} to connect at port {}'.format(self._pid, self._target_host.listening_port())), patch=False):
stdin = None
stdout = None
stderr = None
Modified: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (266223 => 266224)
--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -640,7 +640,7 @@
output = None
- with Timeout(timeout, RuntimeError(u'Timed out waiting for process to open {} on {}'.format(bundle_id, self.udid))):
+ with Timeout(timeout, handler=RuntimeError(u'Timed out waiting for process to open {} on {}'.format(bundle_id, self.udid)), patch=False):
while True:
output = self.executive.run_command(
['xcrun', 'simctl', 'launch', self.udid, bundle_id] + args,
Modified: trunk/Tools/glib/api_test_runner.py (266223 => 266224)
--- trunk/Tools/glib/api_test_runner.py 2020-08-27 05:27:16 UTC (rev 266223)
+++ trunk/Tools/glib/api_test_runner.py 2020-08-27 05:43:04 UTC (rev 266224)
@@ -30,7 +30,7 @@
import common
from webkitpy.common.host import Host
from webkitpy.common.test_expectations import TestExpectations
-from webkitpy.common.timeout_context import Timeout
+from webkitcorepy import Timeout
if os.name == 'posix' and sys.version_info[0] < 3:
try:
@@ -230,7 +230,7 @@
common.parse_output_lines(fd, sys.stdout.write)
status = self._waitpid(pid)
os.close(fd)
- except RuntimeError:
+ except Timeout.Exception:
self._kill_process(pid)
os.close(fd)
sys.stdout.write("**TIMEOUT** %s\n" % subtest)