<!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>[204253] 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/204253">204253</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-08 09:18:33 -0700 (Mon, 08 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>run-webkit-tests should trigger a spindump when WebContent process is unresponsive
https://bugs.webkit.org/show_bug.cgi?id=159827

Patch by Jonathan Bedard &lt;jbedard@apple.com&gt; on 2016-08-08
Reviewed by Daniel Bates.

This change was spurred by a process hang which occurred between tests and did
not produce a meaningful crashlog.

* Scripts/webkitpy/port/driver.py:
(Driver._check_for_driver_crash_or_unresponsiveness): Notify test controller when finished through stdin.

 * Scripts/webkitpy/port/ios.py:
(IOSSimulatorPort):
(IOSSimulatorPort.sample_process): Attempt spindump, but use sample if spindump fails.
* Scripts/webkitpy/port/mac.py:
(MacPort):
(MacPort.sample_process): Attempt spindump, but use sample if spindump fails.

* Scripts/webkitpy/port/mac_unittest.py: Changed expected values to match spindump calls, added specific spindump test.
* Scripts/webkitpy/port/driver_unittest.py: Added dummy write function.

* WebKitTestRunner/TestController.h:
(WTR::TestController::usingServerMode): Added accessor for m_usingServerMode.
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::dumpWebProcessUnresponsiveness): Wait for stdin before continuing when in server mode.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptswebkitpyportdriverpy">trunk/Tools/Scripts/webkitpy/port/driver.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportdriver_unittestpy">trunk/Tools/Scripts/webkitpy/port/driver_unittest.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportiospy">trunk/Tools/Scripts/webkitpy/port/ios.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportmacpy">trunk/Tools/Scripts/webkitpy/port/mac.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportmac_unittestpy">trunk/Tools/Scripts/webkitpy/port/mac_unittest.py</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllerh">trunk/Tools/WebKitTestRunner/TestController.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestInvocationcpp">trunk/Tools/WebKitTestRunner/TestInvocation.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/ChangeLog        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-08-08  Jonathan Bedard  &lt;jbedard@apple.com&gt;
+
+        run-webkit-tests should trigger a spindump when WebContent process is unresponsive
+        https://bugs.webkit.org/show_bug.cgi?id=159827
+
+        Reviewed by Daniel Bates.
+
+        This change was spurred by a process hang which occurred between tests and did
+        not produce a meaningful crashlog.
+
+        * Scripts/webkitpy/port/driver.py:
+        (Driver._check_for_driver_crash_or_unresponsiveness): Notify test controller when finished through stdin.
+
+         * Scripts/webkitpy/port/ios.py:
+        (IOSSimulatorPort):
+        (IOSSimulatorPort.sample_process): Attempt spindump, but use sample if spindump fails.
+        * Scripts/webkitpy/port/mac.py:
+        (MacPort):
+        (MacPort.sample_process): Attempt spindump, but use sample if spindump fails.
+
+        * Scripts/webkitpy/port/mac_unittest.py: Changed expected values to match spindump calls, added specific spindump test.
+        * Scripts/webkitpy/port/driver_unittest.py: Added dummy write function.
+
+        * WebKitTestRunner/TestController.h:
+        (WTR::TestController::usingServerMode): Added accessor for m_usingServerMode.
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::dumpWebProcessUnresponsiveness): Wait for stdin before continuing when in server mode.
+
</ins><span class="cx"> 2016-08-07  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Reply block leaks if the remote object doesn’t call it
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportdriverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/driver.py (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/driver.py        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/Scripts/webkitpy/port/driver.py        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -444,6 +444,7 @@
</span><span class="cx">             if child_process_pid:
</span><span class="cx">                 self._port.sample_process(child_process_name, child_process_pid)
</span><span class="cx">             self.error_from_test += error_line
</span><ins>+            self._server_process.write('#SAMPLE FINISHED\n')
</ins><span class="cx">             return True
</span><span class="cx">         return self.has_crashed()
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportdriver_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/driver_unittest.py (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/driver_unittest.py        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/Scripts/webkitpy/port/driver_unittest.py        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -206,6 +206,9 @@
</span><span class="cx">             def stop(self, timeout):
</span><span class="cx">                 pass
</span><span class="cx"> 
</span><ins>+            def write(self, str):
+                pass
+
</ins><span class="cx">         def assert_crash(driver, error_line, crashed, name, pid, unresponsive=False):
</span><span class="cx">             self.assertEqual(driver._check_for_driver_crash_or_unresponsiveness(error_line), crashed)
</span><span class="cx">             self.assertEqual(driver._crashed_process_name, name)
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportiospy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/ios.py (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/ios.py        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/Scripts/webkitpy/port/ios.py        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -408,18 +408,29 @@
</span><span class="cx">         return sample_files
</span><span class="cx"> 
</span><span class="cx">     def sample_process(self, name, pid):
</span><del>-        try:
-            hang_report = self.sample_file_path(name, pid)
-            self._executive.run_command([
-                &quot;/usr/bin/sample&quot;,
-                pid,
-                10,
-                10,
-                &quot;-file&quot;,
-                hang_report,
-            ])
-        except ScriptError as e:
-            _log.warning('Unable to sample process:' + str(e))
</del><ins>+        hang_report = self.sample_file_path(name, pid)
+        exit_status = self._executive.run_command([
+            &quot;/usr/bin/sudo&quot;,
+            &quot;-n&quot;,
+            &quot;/usr/sbin/spindump&quot;,
+            pid,
+            10,
+            10,
+            &quot;-file&quot;,
+            hang_report,
+        ], return_exit_code=True)
+        if exit_status:
+            try:
+                self._executive.run_command([
+                    &quot;/usr/bin/sample&quot;,
+                    pid,
+                    10,
+                    10,
+                    &quot;-file&quot;,
+                    hang_report,
+                ])
+            except ScriptError as e:
+                _log.warning('Unable to sample process:' + str(e))
</ins><span class="cx"> 
</span><span class="cx">     def _path_to_helper(self):
</span><span class="cx">         binary_name = 'LayoutTestHelper'
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportmacpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/mac.py (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/mac.py        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/Scripts/webkitpy/port/mac.py        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -290,18 +290,29 @@
</span><span class="cx">         return sample_files
</span><span class="cx"> 
</span><span class="cx">     def sample_process(self, name, pid):
</span><del>-        try:
-            hang_report = self.sample_file_path(name, pid)
-            self._executive.run_command([
-                &quot;/usr/bin/sample&quot;,
-                pid,
-                10,
-                10,
-                &quot;-file&quot;,
-                hang_report,
-            ])
-        except ScriptError as e:
-            _log.warning('Unable to sample process:' + str(e))
</del><ins>+        hang_report = self.sample_file_path(name, pid)
+        exit_status = self._executive.run_command([
+            &quot;/usr/bin/sudo&quot;,
+            &quot;-n&quot;,
+            &quot;/usr/sbin/spindump&quot;,
+            pid,
+            10,
+            10,
+            &quot;-file&quot;,
+            hang_report,
+        ], return_exit_code=True)
+        if exit_status:
+            try:
+                self._executive.run_command([
+                    &quot;/usr/bin/sample&quot;,
+                    pid,
+                    10,
+                    10,
+                    &quot;-file&quot;,
+                    hang_report,
+                ])
+            except ScriptError as e:
+                _log.warning('Unable to sample process:' + str(e))
</ins><span class="cx"> 
</span><span class="cx">     def _path_to_helper(self):
</span><span class="cx">         binary_name = 'LayoutTestHelper'
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportmac_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/mac_unittest.py (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/mac_unittest.py        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/Scripts/webkitpy/port/mac_unittest.py        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -203,10 +203,23 @@
</span><span class="cx">         port.stop_helper()
</span><span class="cx">         oc.restore_output()
</span><span class="cx"> 
</span><ins>+    def test_spindump(self):
+
+        def logging_run_command(args):
+            print args
+
+        port = self.make_port()
+        port._executive = MockExecutive2(run_command_fn=logging_run_command)
+        expected_stdout = &quot;['/usr/bin/sudo', '-n', '/usr/sbin/spindump', 42, 10, 10, '-file', '/mock-build/layout-test-results/test-42-sample.txt']\n&quot;
+        OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
+
</ins><span class="cx">     def test_sample_process(self):
</span><span class="cx"> 
</span><span class="cx">         def logging_run_command(args):
</span><ins>+            if args[0] == '/usr/bin/sudo':
+                return 1
</ins><span class="cx">             print args
</span><ins>+            return 0
</ins><span class="cx"> 
</span><span class="cx">         port = self.make_port()
</span><span class="cx">         port._executive = MockExecutive2(run_command_fn=logging_run_command)
</span><span class="lines">@@ -213,9 +226,10 @@
</span><span class="cx">         expected_stdout = &quot;['/usr/bin/sample', 42, 10, 10, '-file', '/mock-build/layout-test-results/test-42-sample.txt']\n&quot;
</span><span class="cx">         OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
</span><span class="cx"> 
</span><del>-    def test_sample_process_throws_exception(self):
-
</del><ins>+    def test_sample_process_exception(self):
</ins><span class="cx">         def throwing_run_command(args):
</span><ins>+            if args[0] == '/usr/bin/sudo':
+                return 1
</ins><span class="cx">             raise ScriptError(&quot;MOCK script error&quot;)
</span><span class="cx"> 
</span><span class="cx">         port = self.make_port()
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.h (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.h        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/WebKitTestRunner/TestController.h        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx">     void notifyDone();
</span><span class="cx"> 
</span><span class="cx">     bool shouldShowWebView() const { return m_shouldShowWebView; }
</span><del>-
</del><ins>+    bool usingServerMode() const { return m_usingServerMode; }
</ins><span class="cx">     void configureViewForTest(const TestInvocation&amp;);
</span><span class="cx">     
</span><span class="cx">     bool beforeUnloadReturnValue() const { return m_beforeUnloadReturnValue; }
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestInvocationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (204252 => 204253)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2016-08-08 06:05:47 UTC (rev 204252)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2016-08-08 16:18:33 UTC (rev 204253)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> #include &lt;WebKit/WKWebsiteDataStoreRef.h&gt;
</span><span class="cx"> #include &lt;climits&gt;
</span><span class="cx"> #include &lt;cstdio&gt;
</span><ins>+#include &lt;unistd.h&gt;
</ins><span class="cx"> #include &lt;wtf/StdLibExtras.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -189,15 +190,24 @@
</span><span class="cx"> void TestInvocation::dumpWebProcessUnresponsiveness(const char* errorMessage)
</span><span class="cx"> {
</span><span class="cx">     fprintf(stderr, &quot;%s&quot;, errorMessage);
</span><del>-    char errorMessageToStderr[1024];
</del><ins>+    char buffer[1024] = { };
</ins><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     pid_t pid = WKPageGetProcessIdentifier(TestController::singleton().mainWebView()-&gt;page());
</span><del>-    sprintf(errorMessageToStderr, &quot;#PROCESS UNRESPONSIVE - %s (pid %ld)\n&quot;, TestController::webProcessName(), static_cast&lt;long&gt;(pid));
</del><ins>+    snprintf(buffer, sizeof(buffer), &quot;#PROCESS UNRESPONSIVE - %s (pid %ld)\n&quot;, TestController::webProcessName(), static_cast&lt;long&gt;(pid));
</ins><span class="cx"> #else
</span><del>-    sprintf(errorMessageToStderr, &quot;#PROCESS UNRESPONSIVE - %s\n&quot;, TestController::webProcessName());
</del><ins>+    snprintf(buffer, sizeof(buffer), &quot;#PROCESS UNRESPONSIVE - %s\n&quot;, TestController::webProcessName());
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    dump(errorMessage, errorMessageToStderr, true);
</del><ins>+    dump(errorMessage, buffer, true);
+    
+    if (!TestController::singleton().usingServerMode())
+        return;
+    
+    if (isatty(fileno(stdin)) || isatty(fileno(stderr)))
+        fputs(&quot;Grab an image of the stack, then hit enter...\n&quot;, stderr);
+    
+    if (!fgets(buffer, sizeof(buffer), stdin) || strcmp(buffer, &quot;#SAMPLE FINISHED\n&quot;))
+        fprintf(stderr, &quot;Failed receive expected sample response, got:\n\t\&quot;%s\&quot;\nContinuing...\n&quot;, buffer);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void TestInvocation::dump(const char* textToStdout, const char* textToStderr, bool seenError)
</span></span></pre>
</div>
</div>

</body>
</html>