[iOS] run-webkit-tests should check that simctl can boot and shutdown simulator devic...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 22:30:07 +0000 (22:30 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 22:30:07 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141718

Reviewed by Alex Christensen.

We should only run layout tests if simctl can successfully boot and shutdown the testing device.

* Scripts/webkitpy/port/ios.py:
(IOSSimulatorPort.check_sys_deps): Modified to call Simulator.check_simulator_device_and_erase_if_needed().
Log a error and return False if we are unable to boot the simulator device so that the caller can take
appropriate action, say exit(3) before running any layout tests.
* Scripts/webkitpy/xcode/simulator.py:
(Simulator._boot_and_shutdown_simulator_device): Added. Boot and then shut down the simulator device
with the specified UDID.
(Simulator.check_simulator_device_and_erase_if_needed): Added. Checks that simulator device
with the specified UDID can successfully boot and shut down. We make at most two attempts to
boot and shut down the device, erasing the device between tries so as to restore the device
to a known good state.

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

Tools/ChangeLog
Tools/Scripts/webkitpy/port/ios.py
Tools/Scripts/webkitpy/xcode/simulator.py

index 6703da1..7e48db2 100644 (file)
@@ -1,5 +1,26 @@
 2015-02-17  Daniel Bates  <dabates@apple.com>
 
+        [iOS] run-webkit-tests should check that simctl can boot and shutdown simulator device before running tests
+        https://bugs.webkit.org/show_bug.cgi?id=141718
+
+        Reviewed by Alex Christensen.
+
+        We should only run layout tests if simctl can successfully boot and shutdown the testing device.
+
+        * Scripts/webkitpy/port/ios.py:
+        (IOSSimulatorPort.check_sys_deps): Modified to call Simulator.check_simulator_device_and_erase_if_needed().
+        Log a error and return False if we are unable to boot the simulator device so that the caller can take
+        appropriate action, say exit(3) before running any layout tests.
+        * Scripts/webkitpy/xcode/simulator.py:
+        (Simulator._boot_and_shutdown_simulator_device): Added. Boot and then shut down the simulator device
+        with the specified UDID.
+        (Simulator.check_simulator_device_and_erase_if_needed): Added. Checks that simulator device
+        with the specified UDID can successfully boot and shut down. We make at most two attempts to
+        boot and shut down the device, erasing the device between tries so as to restore the device
+        to a known good state.
+
+2015-02-17  Daniel Bates  <dabates@apple.com>
+
         run_webkit_tests.py should not know about iOS Simulator details
         https://bugs.webkit.org/show_bug.cgi?id=141711
 
index bc277c3..d13a2be 100644 (file)
@@ -239,6 +239,10 @@ class IOSSimulatorPort(Port):
         if not self.simulator_runtime.available:
             _log.error('The iOS Simulator runtime with identifier "{0}" cannot be used because it is unavailable.'.format(self.simulator_runtime.identifier))
             return False
+        testing_device = self.testing_device  # May create a new simulator device
+        if not Simulator.check_simulator_device_and_erase_if_needed(self.host, testing_device.udid):
+            _log.error('Unable to boot the simulator device with UDID {0}.'.format(testing_device.udid))
+            return False
         return super(IOSSimulatorPort, self).check_sys_deps(needs_http)
 
     def check_for_leaks(self, process_name, process_pid):
index 797d4ba..06dcbba 100644 (file)
@@ -277,6 +277,24 @@ class Simulator(object):
     def device_directory(udid):
         return os.path.realpath(os.path.expanduser(os.path.join('~/Library/Developer/CoreSimulator/Devices', udid)))
 
+    @staticmethod
+    def _boot_and_shutdown_simulator_device(host, udid):
+        exit_code = host.executive.run_command(['xcrun', 'simctl', 'boot', udid], return_exit_code=True)
+        if exit_code:
+            return exit_code
+        exit_code = host.executive.run_command(['xcrun', 'simctl', 'shutdown', udid], return_exit_code=True)
+        return exit_code
+
+    @staticmethod
+    def check_simulator_device_and_erase_if_needed(host, udid):
+        exit_code = Simulator._boot_and_shutdown_simulator_device(host, udid)
+        if not exit_code:
+            return True  # Can boot device
+        # Try erasing the simulator device to restore it to a known good state.
+        if not host.executive.run_command(['xcrun', 'simctl', 'erase', udid], return_exit_code=True):
+            return Simulator._boot_and_shutdown_simulator_device(host, udid) == 0  # Can boot device
+        return False  # Cannot boot or erase device
+
     def refresh(self):
         """
         Refresh runtime and device type information from ``simctl list``.