<!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>[176669] 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/176669">176669</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2014-12-02 10:04:27 -0800 (Tue, 02 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] run-webkit-tests records most DumpRenderTree.app crashes as time-outs
https://bugs.webkit.org/show_bug.cgi?id=139143

Reviewed by David Kilzer.

Similar to the Windows-specific fix in &lt;https://bugs.webkit.org/show_bug.cgi?id=37859&gt;,
teach DumpRenderTree for iOS to write &quot;#CRASHED&quot; to the standard error stream when it
crashes. Run-webkit-tests will record as crashing the test associated with the
DumpRenderTree instance that wrote that string.

Currently almost all of the DumpRenderTree.app crashes are recorded by run-
webkit-tests as a time-out because ReportCrash(8) delays delivery of the
process exit notification for DumpRenderTree.app to LayoutTestRelay, which
launched DumpRenderTree.app, past the time-out time limit. Notice LayoutTestRelay
was launched by run-webkit-tests. So, run-webkit-tests kills LayoutTestRelay
(since it exceeded the time-out time limit) before it can inform rub-webkit-tests
about a crash.

Additionally, update the crash message format written to standard error when LayoutTestRelay
detects that {WebKitTestRunner, DumpRenderTree}.app crashed so as to be similar to the
crash message format used by WebKitTestRunner when it detects that the WebProcess crashed.
Then run-webkit-tests will collect the crash logs for {WebKitTestRunner, DumpRenderTree}.app
when they crash in their test machinery logic/UI process code.

* DumpRenderTree/mac/DumpRenderTree.mm:
(writeCrashedMessageOnFatalError): Added.
(dumpRenderTree): Register signal handler, writeCrashedMessageOnFatalError(), for signals:
SIGILL, SIGFPE, SIGBUS and SIGSEGV.
* LayoutTestRelay/LayoutTestRelay/LTRelayController.m:
(-[LTRelayController didCrashWithMessage:]): Emit a crash message with a format
similar to the format used by WebKitTestRunner so that run-webkit-tests will collect
the crash logs for WebKitTestRunner/DumpRenderTree.app.
* Scripts/webkitpy/port/driver.py:
(Driver.__init__): Update comment.
(Driver._check_for_driver_crash): Ditto.
* Scripts/webkitpy/port/ios.py:
(IOSSimulatorPort): Add class constant SUBPROCESS_CRASH_REGEX, which represents a compiled
regular expression. This constant is used as an optimization to avoid compiling the same
regular expression across invocations of _get_crash_log().
(IOSSimulatorPort._get_crash_log): Modified to parse the WebKitTestRunner-like crash message
for the subprocess name and pid. Also, moved variables crash_log, crash_logs, and now to be
closer to where they are used.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreemacDumpRenderTreemm">trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm</a></li>
<li><a href="#trunkToolsLayoutTestRelayLayoutTestRelayLTRelayControllerm">trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.m</a></li>
<li><a href="#trunkToolsScriptswebkitpyportdriverpy">trunk/Tools/Scripts/webkitpy/port/driver.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportiospy">trunk/Tools/Scripts/webkitpy/port/ios.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (176668 => 176669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-12-02 17:59:18 UTC (rev 176668)
+++ trunk/Tools/ChangeLog        2014-12-02 18:04:27 UTC (rev 176669)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2014-12-02  Daniel Bates  &lt;dabates@apple.com&gt;
+
+        [iOS] run-webkit-tests records most DumpRenderTree.app crashes as time-outs
+        https://bugs.webkit.org/show_bug.cgi?id=139143
+
+        Reviewed by David Kilzer.
+
+        Similar to the Windows-specific fix in &lt;https://bugs.webkit.org/show_bug.cgi?id=37859&gt;,
+        teach DumpRenderTree for iOS to write &quot;#CRASHED&quot; to the standard error stream when it
+        crashes. Run-webkit-tests will record as crashing the test associated with the
+        DumpRenderTree instance that wrote that string.
+
+        Currently almost all of the DumpRenderTree.app crashes are recorded by run-
+        webkit-tests as a time-out because ReportCrash(8) delays delivery of the
+        process exit notification for DumpRenderTree.app to LayoutTestRelay, which
+        launched DumpRenderTree.app, past the time-out time limit. Notice LayoutTestRelay
+        was launched by run-webkit-tests. So, run-webkit-tests kills LayoutTestRelay
+        (since it exceeded the time-out time limit) before it can inform rub-webkit-tests
+        about a crash.
+
+        Additionally, update the crash message format written to standard error when LayoutTestRelay
+        detects that {WebKitTestRunner, DumpRenderTree}.app crashed so as to be similar to the
+        crash message format used by WebKitTestRunner when it detects that the WebProcess crashed.
+        Then run-webkit-tests will collect the crash logs for {WebKitTestRunner, DumpRenderTree}.app
+        when they crash in their test machinery logic/UI process code.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (writeCrashedMessageOnFatalError): Added.
+        (dumpRenderTree): Register signal handler, writeCrashedMessageOnFatalError(), for signals:
+        SIGILL, SIGFPE, SIGBUS and SIGSEGV.
+        * LayoutTestRelay/LayoutTestRelay/LTRelayController.m:
+        (-[LTRelayController didCrashWithMessage:]): Emit a crash message with a format
+        similar to the format used by WebKitTestRunner so that run-webkit-tests will collect
+        the crash logs for WebKitTestRunner/DumpRenderTree.app.
+        * Scripts/webkitpy/port/driver.py:
+        (Driver.__init__): Update comment.
+        (Driver._check_for_driver_crash): Ditto.
+        * Scripts/webkitpy/port/ios.py:
+        (IOSSimulatorPort): Add class constant SUBPROCESS_CRASH_REGEX, which represents a compiled
+        regular expression. This constant is used as an optimization to avoid compiling the same
+        regular expression across invocations of _get_crash_log().
+        (IOSSimulatorPort._get_crash_log): Modified to parse the WebKitTestRunner-like crash message
+        for the subprocess name and pid. Also, moved variables crash_log, crash_logs, and now to be
+        closer to where they are used.
+
</ins><span class="cx"> 2014-12-01  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove WKBundleRemoveAllVisitedLinks
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacDumpRenderTreemm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (176668 => 176669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm        2014-12-02 17:59:18 UTC (rev 176668)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm        2014-12-02 18:04:27 UTC (rev 176669)
</span><span class="lines">@@ -1118,6 +1118,21 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+const char crashedMessage[] = &quot;#CRASHED\n&quot;;
+
+void writeCrashedMessageOnFatalError(int signalCode)
+{
+    // Reset the default action for the signal so that we run ReportCrash(8) on pending and
+    // subsequent instances of the signal.
+    signal(signalCode, SIG_DFL);
+
+    // WRITE(2) and FSYNC(2) are considered safe to call from a signal handler by SIGACTION(2).
+    write(STDERR_FILENO, &amp;crashedMessage[0], sizeof(crashedMessage) - 1);
+    fsync(STDERR_FILENO);
+}
+#endif
+
</ins><span class="cx"> void dumpRenderTree(int argc, const char *argv[])
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -1132,6 +1147,11 @@
</span><span class="cx">     dup2(outfd, STDOUT_FILENO);
</span><span class="cx">     int errfd = open(stderrPath, O_RDWR | O_NONBLOCK);
</span><span class="cx">     dup2(errfd, STDERR_FILENO);
</span><ins>+
+    signal(SIGILL, &amp;writeCrashedMessageOnFatalError);
+    signal(SIGFPE, &amp;writeCrashedMessageOnFatalError);
+    signal(SIGBUS, &amp;writeCrashedMessageOnFatalError);
+    signal(SIGSEGV, &amp;writeCrashedMessageOnFatalError);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     initializeGlobalsFromCommandLineOptions(argc, argv);
</span></span></pre></div>
<a id="trunkToolsLayoutTestRelayLayoutTestRelayLTRelayControllerm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.m (176668 => 176669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.m        2014-12-02 17:59:18 UTC (rev 176668)
+++ trunk/Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.m        2014-12-02 18:04:27 UTC (rev 176669)
</span><span class="lines">@@ -140,7 +140,7 @@
</span><span class="cx"> - (void)didCrashWithMessage:(NSString *)message
</span><span class="cx"> {
</span><span class="cx">     [[self relay] disconnect];
</span><del>-    NSString *crashMessage = [NSString stringWithFormat:@&quot;\nCRASH: %@ %d\n&quot;, [self processName], [self pid]];
</del><ins>+    NSString *crashMessage = [NSString stringWithFormat:@&quot;\n#CRASHED - %@ (pid %d)\n&quot;, [self processName], [self pid]];
</ins><span class="cx"> 
</span><span class="cx">     if (message)
</span><span class="cx">         crashMessage = [crashMessage stringByAppendingFormat:@&quot;%@\n&quot;, message];
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportdriverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/driver.py (176668 => 176669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/driver.py        2014-12-02 17:59:18 UTC (rev 176668)
+++ trunk/Tools/Scripts/webkitpy/port/driver.py        2014-12-02 18:04:27 UTC (rev 176669)
</span><span class="lines">@@ -130,10 +130,10 @@
</span><span class="cx">         self._no_timeout = no_timeout
</span><span class="cx"> 
</span><span class="cx">         self._driver_tempdir = None
</span><del>-        # WebKitTestRunner can report back subprocess crashes by printing
-        # &quot;#CRASHED - PROCESSNAME&quot;.  Since those can happen at any time
-        # and ServerProcess won't be aware of them (since the actual tool
-        # didn't crash, just a subprocess) we record the crashed subprocess name here.
</del><ins>+        # WebKitTestRunner/LayoutTestRelay can report back subprocess crashes by printing
+        # &quot;#CRASHED - PROCESSNAME&quot;.  Since those can happen at any time and ServerProcess
+        # won't be aware of them (since the actual tool didn't crash, just a subprocess)
+        # we record the crashed subprocess name here.
</ins><span class="cx">         self._crashed_process_name = None
</span><span class="cx">         self._crashed_pid = None
</span><span class="cx"> 
</span><span class="lines">@@ -361,13 +361,13 @@
</span><span class="cx"> 
</span><span class="cx">     def _check_for_driver_crash(self, error_line):
</span><span class="cx">         if error_line == &quot;#CRASHED\n&quot;:
</span><del>-            # This is used on Windows to report that the process has crashed
</del><ins>+            # This is used on Windows and iOS to report that the process has crashed
</ins><span class="cx">             # See http://trac.webkit.org/changeset/65537.
</span><span class="cx">             self._crashed_process_name = self._server_process.name()
</span><span class="cx">             self._crashed_pid = self._server_process.pid()
</span><span class="cx">         elif (error_line.startswith(&quot;#CRASHED - &quot;)
</span><span class="cx">             or error_line.startswith(&quot;#PROCESS UNRESPONSIVE - &quot;)):
</span><del>-            # WebKitTestRunner uses this to report that the WebProcess subprocess crashed.
</del><ins>+            # WebKitTestRunner/LayoutTestRelay uses this to report that the subprocess (e.g. WebProcess) crashed.
</ins><span class="cx">             match = re.match('#(?:CRASHED|PROCESS UNRESPONSIVE) - (\S+)', error_line)
</span><span class="cx">             self._crashed_process_name = match.group(1) if match else 'WebProcess'
</span><span class="cx">             match = re.search('pid (\d+)', error_line)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportiospy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/ios.py (176668 => 176669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/ios.py        2014-12-02 17:59:18 UTC (rev 176668)
+++ trunk/Tools/Scripts/webkitpy/port/ios.py        2014-12-02 18:04:27 UTC (rev 176669)
</span><span class="lines">@@ -219,24 +219,33 @@
</span><span class="cx">     def sample_file_path(self, name, pid):
</span><span class="cx">         return self._filesystem.join(self.results_directory(), &quot;{0}-{1}-sample.txt&quot;.format(name, pid))
</span><span class="cx"> 
</span><ins>+    SUBPROCESS_CRASH_REGEX = re.compile('#CRASHED - (?P&lt;subprocess_name&gt;\S+) \(pid (?P&lt;subprocess_pid&gt;\d+)\)')
+
</ins><span class="cx">     def _get_crash_log(self, name, pid, stdout, stderr, newer_than, time_fn=time.time, sleep_fn=time.sleep, wait_for_log=True):
</span><span class="cx">         time_fn = time_fn or time.time
</span><span class="cx">         sleep_fn = sleep_fn or time.sleep
</span><del>-        crash_log = ''
-        crash_logs = CrashLogs(self.host)
-        now = time_fn()
</del><span class="cx"> 
</span><del>-        crash_prefix = 'CRASH: '
</del><ins>+        # FIXME: We should collect the actual crash log for DumpRenderTree.app because it includes more
+        # information (e.g. exception codes) than is available in the stack trace written to standard error.
</ins><span class="cx">         stderr_lines = []
</span><del>-        crash_lines = []
</del><ins>+        crashed_subprocess_name_and_pid = None  # e.g. ('DumpRenderTree.app', 1234)
</ins><span class="cx">         for line in (stderr or '').splitlines():
</span><del>-            crash_lines.append(line) if line.startswith(crash_prefix) else stderr_lines.append(line)
</del><ins>+            if not crashed_subprocess_name_and_pid:
+                match = self.SUBPROCESS_CRASH_REGEX.match(line)
+                if match:
+                    crashed_subprocess_name_and_pid = (match.group('subprocess_name'), int(match.group('subprocess_pid')))
+                    continue
+            stderr_lines.append(line)
</ins><span class="cx"> 
</span><del>-        for crash_line in crash_lines:
-            identifier, pid = crash_line[len(crash_prefix):].split(' ')
-            return self._get_crash_log(identifier, int(pid), stdout, '\n'.join(stderr_lines), newer_than, time_fn, sleep_fn, wait_for_log)
</del><ins>+        if crashed_subprocess_name_and_pid:
+            return self._get_crash_log(crashed_subprocess_name_and_pid[0], crashed_subprocess_name_and_pid[1], stdout,
+                '\n'.join(stderr_lines), newer_than, time_fn, sleep_fn, wait_for_log)
</ins><span class="cx"> 
</span><ins>+        # LayoutTestRelay crashed
</ins><span class="cx">         _log.debug('looking for crash log for %s:%s' % (name, str(pid)))
</span><ins>+        crash_log = ''
+        crash_logs = CrashLogs(self.host)
+        now = time_fn()
</ins><span class="cx">         deadline = now + 5 * int(self.get_option('child_processes', 1))
</span><span class="cx">         while not crash_log and now &lt;= deadline:
</span><span class="cx">             crash_log = crash_logs.find_newest_log(name, pid, include_errors=True, newer_than=newer_than)
</span></span></pre>
</div>
</div>

</body>
</html>