<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[214192] trunk/Tools</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/214192">214192</a></dd>
<dt>Author</dt> <dd>jbedard@apple.com</dd>
<dt>Date</dt> <dd>2017-03-20 14:33:58 -0700 (Mon, 20 Mar 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>webkitpy: Work around simctl launch returning dead processes
https://bugs.webkit.org/show_bug.cgi?id=169878
Reviewed by Daniel Bates.
simctl launch will sometimes give the PID of a process which has just been terminated.
To work around this, we will always check if the returned PID is of a process which is
still running.
* Scripts/webkitpy/port/simulator_process.py:
(SimulatorProcess.Popen.__init__): Accept device argument.
(SimulatorProcess.Popen.poll): Call device.poll().
(SimulatorProcess._start): Pass device into Popen object.
* Scripts/webkitpy/xcode/device.py:
(Device.poll): Added.
* Scripts/webkitpy/xcode/simulated_device.py:
(SimulatedDevice.install_app): Change attempts to timeout.
(SimulatedDevice.launch_app): Check that the process being returned is active, use a
timeout instead of attempts.
(SimulatedDevice):
(SimulatedDevice.poll): Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpyportsimulator_processpy">trunk/Tools/Scripts/webkitpy/port/simulator_process.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyxcodedevicepy">trunk/Tools/Scripts/webkitpy/xcode/device.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyxcodesimulated_devicepy">trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (214191 => 214192)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-03-20 20:09:20 UTC (rev 214191)
+++ trunk/Tools/ChangeLog        2017-03-20 21:33:58 UTC (rev 214192)
</span><span class="lines">@@ -1,5 +1,29 @@
</span><span class="cx"> 2017-03-20 Jonathan Bedard <jbedard@apple.com>
</span><span class="cx">
</span><ins>+ webkitpy: Work around simctl launch returning dead processes
+ https://bugs.webkit.org/show_bug.cgi?id=169878
+
+ Reviewed by Daniel Bates.
+
+ simctl launch will sometimes give the PID of a process which has just been terminated.
+ To work around this, we will always check if the returned PID is of a process which is
+ still running.
+
+ * Scripts/webkitpy/port/simulator_process.py:
+ (SimulatorProcess.Popen.__init__): Accept device argument.
+ (SimulatorProcess.Popen.poll): Call device.poll().
+ (SimulatorProcess._start): Pass device into Popen object.
+ * Scripts/webkitpy/xcode/device.py:
+ (Device.poll): Added.
+ * Scripts/webkitpy/xcode/simulated_device.py:
+ (SimulatedDevice.install_app): Change attempts to timeout.
+ (SimulatedDevice.launch_app): Check that the process being returned is active, use a
+ timeout instead of attempts.
+ (SimulatedDevice):
+ (SimulatedDevice.poll): Added.
+
+2017-03-20 Jonathan Bedard <jbedard@apple.com>
+
</ins><span class="cx"> buildbot: run-webkit-tests should display test failures and run exceptions differently
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=169793
</span><span class="cx"> <rdar://problem/30987863>
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportsimulator_processpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/simulator_process.py (214191 => 214192)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/simulator_process.py        2017-03-20 20:09:20 UTC (rev 214191)
+++ trunk/Tools/Scripts/webkitpy/port/simulator_process.py        2017-03-20 21:33:58 UTC (rev 214192)
</span><span class="lines">@@ -34,21 +34,18 @@
</span><span class="cx">
</span><span class="cx"> class Popen(object):
</span><span class="cx">
</span><del>- def __init__(self, pid, stdin, stdout, stderr):
</del><ins>+ def __init__(self, pid, stdin, stdout, stderr, device):
</ins><span class="cx"> self.stdin = stdin
</span><span class="cx"> self.stdout = stdout
</span><span class="cx"> self.stderr = stderr
</span><span class="cx"> self.pid = pid
</span><span class="cx"> self.returncode = None
</span><ins>+ self._device = device
</ins><span class="cx">
</span><span class="cx"> def poll(self):
</span><span class="cx"> if self.returncode:
</span><span class="cx"> return self.returncode
</span><del>- try:
- os.kill(self.pid, 0)
- except OSError, err:
- assert err.errno == errno.ESRCH
- self.returncode = 1
</del><ins>+ self.returncode = self._device.poll(self.pid)
</ins><span class="cx"> return self.returncode
</span><span class="cx">
</span><span class="cx"> def wait(self):
</span><span class="lines">@@ -116,7 +113,7 @@
</span><span class="cx"> stdin = open(self._in_path, 'w', 0) # Opening with no buffering, like popen
</span><span class="cx"> except:
</span><span class="cx"> # We set self._proc as _reset() and _kill() depend on it.
</span><del>- self._proc = SimulatorProcess.Popen(self._pid, stdin, stdout, stderr)
</del><ins>+ self._proc = SimulatorProcess.Popen(self._pid, stdin, stdout, stderr, self._device)
</ins><span class="cx"> if self._proc.poll() is not None:
</span><span class="cx"> self._reset()
</span><span class="cx"> raise Exception('App {} crashed before stdin could be attached'.format(os.path.basename(self._cmd[0])))
</span><span class="lines">@@ -125,7 +122,7 @@
</span><span class="cx"> raise
</span><span class="cx"> signal.alarm(0) # Cancel alarm
</span><span class="cx">
</span><del>- self._proc = SimulatorProcess.Popen(self._pid, stdin, stdout, stderr)
</del><ins>+ self._proc = SimulatorProcess.Popen(self._pid, stdin, stdout, stderr, self._device)
</ins><span class="cx">
</span><span class="cx"> def stop(self, timeout_secs=3.0):
</span><span class="cx"> try:
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodedevicepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/xcode/device.py (214191 => 214192)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/device.py        2017-03-20 20:09:20 UTC (rev 214191)
+++ trunk/Tools/Scripts/webkitpy/xcode/device.py        2017-03-20 21:33:58 UTC (rev 214192)
</span><span class="lines">@@ -33,6 +33,9 @@
</span><span class="cx"> def launch_app(self, bundle_id, args, env=None):
</span><span class="cx"> raise NotImplementedError
</span><span class="cx">
</span><ins>+ def poll(self, pid):
+ raise NotImplementedError
+
</ins><span class="cx"> def __eq__(self, other):
</span><span class="cx"> return self.udid == other.udid
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyxcodesimulated_devicepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (214191 => 214192)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py        2017-03-20 20:09:20 UTC (rev 214191)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py        2017-03-20 21:33:58 UTC (rev 214192)
</span><span class="lines">@@ -20,8 +20,11 @@
</span><span class="cx"> # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
</span><span class="cx"> # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">
</span><ins>+import errno
+import os
</ins><span class="cx"> import logging
</span><span class="cx"> import re
</span><ins>+import signal
</ins><span class="cx"> import subprocess
</span><span class="cx">
</span><span class="cx"> from webkitpy.xcode.device import Device
</span><span class="lines">@@ -142,13 +145,13 @@
</span><span class="cx"> 'Print CFBundleIdentifier',
</span><span class="cx"> self._host.filesystem.join(app_path, 'Info.plist'),
</span><span class="cx"> ]).rstrip()
</span><del>- self._host.executive.kill_process(self.launch_app(bundle_id, [], env=env, attempts=1))
</del><ins>+ self._host.executive.kill_process(self.launch_app(bundle_id, [], env=env, timeout=1))
</ins><span class="cx"> return True
</span><span class="cx"> except RuntimeError:
</span><span class="cx"> pass
</span><span class="cx"> return False
</span><span class="cx">
</span><del>- def launch_app(self, bundle_id, args, env=None, attempts=3):
</del><ins>+ def launch_app(self, bundle_id, args, env=None, timeout=10):
</ins><span class="cx"> environment_to_use = {}
</span><span class="cx"> SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
</span><span class="cx"> for value in (env or {}):
</span><span class="lines">@@ -161,8 +164,14 @@
</span><span class="cx"> def _log_debug_error(error):
</span><span class="cx"> _log.debug(error.message_with_output())
</span><span class="cx">
</span><ins>+ def _install_timeout(signum, frame):
+ assert signum == signal.SIGALRM
+ raise Exception('Timed out waiting for process to open {} on {}'.format(bundle_id, self.udid))
+
</ins><span class="cx"> output = None
</span><del>- for x in xrange(attempts):
</del><ins>+ signal.signal(signal.SIGALRM, _install_timeout)
+ signal.alarm(timeout) # In seconds
+ while True:
</ins><span class="cx"> output = self._host.executive.run_command(
</span><span class="cx"> ['xcrun', 'simctl', 'launch', self.udid, bundle_id] + args,
</span><span class="cx"> env=environment_to_use,
</span><span class="lines">@@ -169,13 +178,24 @@
</span><span class="cx"> error_handler=_log_debug_error,
</span><span class="cx"> )
</span><span class="cx"> match = re.match(r'(?P<bundle>[^:]+): (?P<pid>\d+)\n', output)
</span><del>- if match:
</del><ins>+ # FIXME: We shouldn't need to check the PID <rdar://problem/31154075>.
+ if match and self.poll(int(match.group('pid'))) is None:
</ins><span class="cx"> break
</span><span class="cx">
</span><del>- if not match or match.group('bundle') != bundle_id:
</del><ins>+ signal.alarm(0) # Cancel alarm
+
+ if match.group('bundle') != bundle_id:
</ins><span class="cx"> raise RuntimeError('Failed to find process id for {}: {}'.format(bundle_id, output))
</span><span class="cx"> return int(match.group('pid'))
</span><span class="cx">
</span><ins>+ def poll(self, pid):
+ try:
+ os.kill(pid, 0)
+ except OSError as err:
+ assert err.errno == errno.ESRCH
+ return 1
+ return None
+
</ins><span class="cx"> def __repr__(self):
</span><span class="cx"> return '<{device_info} State: {state}. Runtime: {runtime}, Available: {available}>'.format(
</span><span class="cx"> device_info=super(SimulatedDevice, self).__repr__(),
</span></span></pre>
</div>
</div>
</body>
</html>