webkitpy: Run sample/spindump on iOS devices
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Jun 2017 20:39:00 +0000 (20:39 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Jun 2017 20:39:00 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171881
<rdar://problem/32084602>

Reviewed by Daniel Bates.

* Scripts/webkitpy/port/darwin.py:
(DarwinPort.sample_process): Only add sudo prefix if the platform is Mac, which
requires sudo to run spindump.
* Scripts/webkitpy/port/ios_device.py:
(IOSDevicePort.look_for_new_samples): Deleted.
(IOSDevicePort.sample_process): Deleted.
* Scripts/webkitpy/port/ios_device_unittest.py:
(IOSDeviceTest): iOS devices use 'ios' and their os_name.
(IOSDeviceTest.test_spindump):
(IOSDeviceTest.test_sample_process):
(IOSDeviceTest.test_sample_process_exception):
* Scripts/webkitpy/port/ios_simulator_unittest.py:
(IOSSimulatorTest): iOS Simulators run on Mac and use 'mac' as their os_name.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217946 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/port/darwin.py
Tools/Scripts/webkitpy/port/ios_device.py
Tools/Scripts/webkitpy/port/ios_device_unittest.py
Tools/Scripts/webkitpy/port/ios_simulator_unittest.py

index 8f25b8f..b461ebb 100644 (file)
@@ -1,3 +1,25 @@
+2017-06-08  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: Run sample/spindump on iOS devices
+        https://bugs.webkit.org/show_bug.cgi?id=171881
+        <rdar://problem/32084602>
+
+        Reviewed by Daniel Bates.
+
+        * Scripts/webkitpy/port/darwin.py:
+        (DarwinPort.sample_process): Only add sudo prefix if the platform is Mac, which
+        requires sudo to run spindump.
+        * Scripts/webkitpy/port/ios_device.py:
+        (IOSDevicePort.look_for_new_samples): Deleted.
+        (IOSDevicePort.sample_process): Deleted.
+        * Scripts/webkitpy/port/ios_device_unittest.py:
+        (IOSDeviceTest): iOS devices use 'ios' and their os_name.
+        (IOSDeviceTest.test_spindump):
+        (IOSDeviceTest.test_sample_process):
+        (IOSDeviceTest.test_sample_process_exception):
+        * Scripts/webkitpy/port/ios_simulator_unittest.py:
+        (IOSSimulatorTest): iOS Simulators run on Mac and use 'mac' as their os_name.
+
 2017-06-08  Keith Miller  <keith_miller@apple.com>
 
         WebAssembly: We should only create wrappers for functions that can be exported
index 327bf04..b25b33b 100644 (file)
@@ -154,24 +154,25 @@ class DarwinPort(ApplePort):
     def sample_process(self, name, pid, target_host=None):
         host = target_host or self.host
         tempdir = host.filesystem.mkdtemp()
-        exit_status = host.executive.run_command([
-            "/usr/bin/sudo",
-            "-n",
-            "/usr/sbin/spindump",
+        command = [
+            '/usr/sbin/spindump',
             pid,
             10,
             10,
-            "-file",
+            '-file',
             DarwinPort.spindump_file_path(host, name, pid, str(tempdir)),
-        ], return_exit_code=True)
+        ]
+        if self.host.platform.is_mac():
+            command = ['/usr/bin/sudo', '-n'] + command
+        exit_status = host.executive.run_command(command, return_exit_code=True)
         if exit_status:
             try:
                 host.executive.run_command([
-                    "/usr/bin/sample",
+                    '/usr/bin/sample',
                     pid,
                     10,
                     10,
-                    "-file",
+                    '-file',
                     DarwinPort.sample_file_path(host, name, pid, str(tempdir)),
                 ])
                 host.filesystem.move_to_base_host(DarwinPort.sample_file_path(host, name, pid, str(tempdir)),
index 521baac..479182a 100644 (file)
@@ -95,12 +95,6 @@ class IOSDevicePort(IOSPort):
     def check_for_leaks(self, process_name, process_pid):
         pass
 
-    def look_for_new_samples(self, unresponsive_processes, start_time):
-        return {}
-
-    def sample_process(self, name, pid, target_host=None):
-        pass
-
     # Despite their names, these flags do not actually get passed all the way down to webkit-build.
     def _build_driver_flags(self):
         return ['--sdk', self.SDK] + (['ARCHS=%s' % self.architecture()] if self.architecture() else [])
index d9237fd..f3faf0e 100644 (file)
 
 import time
 
+from webkitpy.common.system.outputcapture import OutputCapture
+from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
 from webkitpy.port.ios_device import IOSDevicePort
 from webkitpy.port import ios_testcase
 
 
 class IOSDeviceTest(ios_testcase.IOSTest):
-    os_name = 'ios-device'
+    os_name = 'ios'
     os_version = ''
     port_name = 'ios-device'
     port_maker = IOSDevicePort
@@ -44,17 +46,44 @@ class IOSDeviceTest(ios_testcase.IOSTest):
         with self.assertRaises(RuntimeError):
             port.path_to_crash_logs()
 
-    def test_get_crash_log(self):
-        port = self.make_port(port_name=self.port_name)
-        with self.assertRaises(RuntimeError):
-            port._get_crash_log('DumpRenderTree', 1234, None, None, time.time(), wait_for_log=False)
-
-    # FIXME: Update tests when <rdar://problem/30497991> is completed.
     def test_spindump(self):
-        pass
+        def logging_run_command(args):
+            print args
+
+        port = self.make_port()
+        port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'] = 'Spindump file'
+        port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
+        expected_stdout = "['/usr/sbin/spindump', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-spindump.txt']\n"
+        OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
+        self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-spindump.txt'], 'Spindump file')
+        self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-spindump.txt'])
 
     def test_sample_process(self):
-        pass
+        def logging_run_command(args):
+            if args[0] == '/usr/sbin/spindump':
+                return 1
+            print args
+            return 0
+
+        port = self.make_port()
+        port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'] = 'Sample file'
+        port.host.executive = MockExecutive2(run_command_fn=logging_run_command)
+        expected_stdout = "['/usr/bin/sample', 42, 10, 10, '-file', '/__im_tmp/tmp_0_/test-42-sample.txt']\n"
+        OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42], expected_stdout=expected_stdout)
+        self.assertEqual(port.host.filesystem.files['/mock-build/layout-test-results/test-42-sample.txt'], 'Sample file')
+        self.assertIsNone(port.host.filesystem.files['/__im_tmp/tmp_0_/test-42-sample.txt'])
 
     def test_sample_process_exception(self):
-        pass
+        def throwing_run_command(args):
+            if args[0] == '/usr/sbin/spindump':
+                return 1
+            raise ScriptError('MOCK script error')
+
+        port = self.make_port()
+        port.host.executive = MockExecutive2(run_command_fn=throwing_run_command)
+        OutputCapture().assert_outputs(self, port.sample_process, args=['test', 42])
+
+    def test_get_crash_log(self):
+        port = self.make_port(port_name=self.port_name)
+        with self.assertRaises(RuntimeError):
+            port._get_crash_log('DumpRenderTree', 1234, None, None, time.time(), wait_for_log=False)
index 24b194d..c28204a 100644 (file)
@@ -30,7 +30,8 @@ from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
 
 
 class IOSSimulatorTest(ios_testcase.IOSTest):
-    os_name = 'ios-simulator'
+    # FIXME: https://bugs.webkit.org/show_bug.cgi?id=173107
+    os_name = 'mac'
     os_version = ''
     port_name = 'ios-simulator'
     port_maker = IOSSimulatorPort