webkitpy: Check for specific process instead of using data migrator
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2018 19:59:34 +0000 (19:59 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2018 19:59:34 +0000 (19:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191551
<rdar://problem/45993156>

Rubber-stamped by Aakash Jain.

It's possible for the data migrator process to be stuck, but for a simulator to be
usable. Use device-specific processes to detect when a device is usable.

* Scripts/webkitpy/xcode/simulated_device.py:
(SimulatedDeviceManager._wait_until_device_is_usable):
(SimulatedDeviceManager):
(SimulatedDeviceManager.initialize_devices): Explicitly wait until a device is usable
since this implies that a device is booted.
(SimulatedDeviceManager.swap): Ditto.
(SimulatedDevice.is_usable): Check that a device is booted and that a device-specific
process indicating the device is usable can be found.
(SimulatedDeviceManager.wait_until_data_migration_is_done): Deleted.
* Scripts/webkitpy/xcode/simulated_device_unittest.py: Update simctl_json so that
it triggers the logic in is_usable()

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

Tools/ChangeLog
Tools/Scripts/webkitpy/xcode/simulated_device.py
Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py

index 7a1752e..8de6396 100644 (file)
@@ -1,3 +1,26 @@
+2018-11-12  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: Check for specific process instead of using data migrator
+        https://bugs.webkit.org/show_bug.cgi?id=191551
+        <rdar://problem/45993156>
+
+        Rubber-stamped by Aakash Jain.
+
+        It's possible for the data migrator process to be stuck, but for a simulator to be
+        usable. Use device-specific processes to detect when a device is usable.
+
+        * Scripts/webkitpy/xcode/simulated_device.py:
+        (SimulatedDeviceManager._wait_until_device_is_usable):
+        (SimulatedDeviceManager):
+        (SimulatedDeviceManager.initialize_devices): Explicitly wait until a device is usable
+        since this implies that a device is booted.
+        (SimulatedDeviceManager.swap): Ditto.
+        (SimulatedDevice.is_usable): Check that a device is booted and that a device-specific
+        process indicating the device is usable can be found.
+        (SimulatedDeviceManager.wait_until_data_migration_is_done): Deleted.
+        * Scripts/webkitpy/xcode/simulated_device_unittest.py: Update simctl_json so that
+        it triggers the logic in is_usable()
+
 2018-11-12  Takashi Komori  <Takashi.Komori@sony.com>
 
         Resurrect WebKitTestRunner for Windows port
index 824f38a..701274a 100644 (file)
@@ -309,6 +309,14 @@ class SimulatedDeviceManager(object):
                 raise RuntimeError('Timed out while waiting for all devices to boot')
 
     @staticmethod
+    def _wait_until_device_is_usable(device, deadline):
+        _log.debug('Waiting until {} is usable'.format(device))
+        while not device.platform_device.is_usable(force_update=True):
+            if time.time() > deadline:
+                raise RuntimeError('Timed out while waiting for {} to become usable'.format(device))
+            time.sleep(1)
+
+    @staticmethod
     def _boot_device(device, host=SystemHost()):
         _log.debug("Booting device '{}'".format(device.udid))
         device.platform_device.booted_by_script = True
@@ -366,8 +374,7 @@ class SimulatedDeviceManager(object):
 
         deadline = time.time() + timeout
         for device in SimulatedDeviceManager.INITIALIZED_DEVICES:
-            SimulatedDeviceManager._wait_until_device_in_state(device, SimulatedDevice.DeviceState.BOOTED, deadline)
-        SimulatedDeviceManager.wait_until_data_migration_is_done(host, max(0, deadline - time.time()))
+            SimulatedDeviceManager._wait_until_device_is_usable(device, deadline)
 
         return SimulatedDeviceManager.INITIALIZED_DEVICES
 
@@ -417,18 +424,7 @@ class SimulatedDeviceManager(object):
         SimulatedDeviceManager.INITIALIZED_DEVICES[index] = device
 
         deadline = time.time() + timeout
-        SimulatedDeviceManager._wait_until_device_in_state(device, SimulatedDevice.DeviceState.BOOTED, deadline)
-        SimulatedDeviceManager.wait_until_data_migration_is_done(host, max(0, deadline - time.time()))
-
-    @staticmethod
-    def wait_until_data_migration_is_done(host, timeout=SIMULATOR_BOOT_TIMEOUT):
-        # The existence of a datamigrator process means that simulators are still booting.
-        deadline = time.time() + timeout
-        _log.debug('Waiting until no com.apple.datamigrator processes are found')
-        while host.executive.running_pids(lambda process_name: 'com.apple.datamigrator' in process_name):
-            if time.time() > deadline:
-                raise RuntimeError('Timed out while waiting for data migration')
-            time.sleep(1)
+        SimulatedDeviceManager._wait_until_device_is_usable(device, max(0, deadline - time.time()))
 
     @staticmethod
     def tear_down(host=SystemHost(), timeout=60):
@@ -498,6 +494,23 @@ class SimulatedDevice(object):
             return True
         return False
 
+    def is_usable(self, force_update=False):
+        if self.state(force_update=force_update) != SimulatedDevice.DeviceState.BOOTED:
+            return False
+
+        if self.device_type.software_variant == 'iOS':
+            home_screen_service = 'com.apple.springboard.services'
+        elif self.device_type.software_version == 'watchOS':
+            home_screen_service = 'com.apple.carousel.sessionservice'
+        else:
+            _log.debug('{} has no service to check if the device is usable'.format(self.device_type.software_variant))
+            return True
+
+        for line in self.executive.run_command([SimulatedDeviceManager.xcrun, 'simctl', 'spawn', self.udid, 'launchctl', 'print', 'system']).splitlines():
+            if home_screen_service in line:
+                return True
+        return False
+
     def _shut_down(self, timeout=10.0):
         deadline = time.time() + timeout
 
index 52d7a16..9f58671 100644 (file)
@@ -487,7 +487,12 @@ simctl_json_output = """{
      },
      "state" : "(active, disconnected)"
    }
- }
+ },
+ "services" : [
+   "This triggers the bail-out logic in SimulatedDevice.is_usable()",
+   "com.apple.springboard.services",
+   "com.apple.carousel.sessionservice"
+ ]
 }"""
 
 import json