- Revision
- 280882
- Author
- jbed...@apple.com
- Date
- 2021-08-10 21:09:33 -0700 (Tue, 10 Aug 2021)
Log Message
[webkitpy] Stop relying on device.plist for simulated device state
https://bugs.webkit.org/show_bug.cgi?id=228974
<rdar://problem/81749547>
Reviewed by Stephanie Lewis.
* Scripts/webkitpy/xcode/simulated_device.py:
(SimulatedDeviceManager):
(SimulatedDeviceManager.populate_available_devices): Device state check is now shared between simulators.
(SimulatedDeviceManager._disambiguate_device_type): Only extract hardware family and type from candidate.
(SimulatedDevice.__init__): Device state check is now shared between simulators.
(SimulatedDevice.state): Use 'xcrun simctl list' instead of device.plist.
* Scripts/webkitpy/xcode/simulated_device_unittest.py:
(SimulatedDeviceTest.change_state_to): Deleted.
(SimulatedDeviceTest.test_swapping_devices): Deleted.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (280881 => 280882)
--- trunk/Tools/ChangeLog 2021-08-11 02:58:01 UTC (rev 280881)
+++ trunk/Tools/ChangeLog 2021-08-11 04:09:33 UTC (rev 280882)
@@ -1,3 +1,21 @@
+2021-08-10 Jonathan Bedard <jbed...@apple.com>
+
+ [webkitpy] Stop relying on device.plist for simulated device state
+ https://bugs.webkit.org/show_bug.cgi?id=228974
+ <rdar://problem/81749547>
+
+ Reviewed by Stephanie Lewis.
+
+ * Scripts/webkitpy/xcode/simulated_device.py:
+ (SimulatedDeviceManager):
+ (SimulatedDeviceManager.populate_available_devices): Device state check is now shared between simulators.
+ (SimulatedDeviceManager._disambiguate_device_type): Only extract hardware family and type from candidate.
+ (SimulatedDevice.__init__): Device state check is now shared between simulators.
+ (SimulatedDevice.state): Use 'xcrun simctl list' instead of device.plist.
+ * Scripts/webkitpy/xcode/simulated_device_unittest.py:
+ (SimulatedDeviceTest.change_state_to): Deleted.
+ (SimulatedDeviceTest.test_swapping_devices): Deleted.
+
2021-08-10 Cameron McCormack <hey...@apple.com>
Restore color profiles correctly on displays with multiple named modes
Modified: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (280881 => 280882)
--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2021-08-11 02:58:01 UTC (rev 280881)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2021-08-11 04:09:33 UTC (rev 280882)
@@ -80,6 +80,7 @@
simulator_bundle_id = 'com.apple.iphonesimulator'
_device_identifier_to_name = {}
_managing_simulator_app = False
+ _last_updated_state = 0
@staticmethod
def _create_runtimes(runtimes):
@@ -141,6 +142,7 @@
SimulatedDeviceManager._device_identifier_to_name = {device['identifier']: device['name'] for device in simctl_json['devicetypes']}
SimulatedDeviceManager.AVAILABLE_RUNTIMES = SimulatedDeviceManager._create_runtimes(simctl_json['runtimes'])
+ SimulatedDeviceManager._last_updated_state = time.time()
for runtime in SimulatedDeviceManager.AVAILABLE_RUNTIMES:
# Needed for <rdar://problem/47122965>
devices = []
@@ -159,7 +161,6 @@
# Update device state from simctl output.
device.platform_device._state = SimulatedDevice.NAME_FOR_STATE.index(device_json['state'].upper())
- device.platform_device._last_updated_state = time.time()
return
@staticmethod
@@ -253,7 +254,8 @@
for _, type_name in reversed(SimulatedDeviceManager._device_identifier_to_name.items()):
candidate = DeviceType.from_string(type_name)
if candidate == full_device_type:
- full_device_type = candidate
+ full_device_type.hardware_family = candidate.hardware_family
+ full_device_type.hardware_type = candidate.hardware_type
break
full_device_type.check_consistency()
@@ -550,7 +552,6 @@
self.device_type = device_type
self.build_version = build_version
self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN
- self._last_updated_state = time.time()
self.executive = host.executive
self.filesystem = host.filesystem
@@ -562,16 +563,23 @@
def state(self, force_update=False):
# Don't allow state to get stale
- if not force_update and time.time() < self._last_updated_state + 1:
+ if not force_update and time.time() < SimulatedDeviceManager._last_updated_state + 10:
return self._state
- device_plist = self.filesystem.expanduser(self.filesystem.join(SimulatedDeviceManager.simulator_device_path, self.udid, 'device.plist'))
try:
- self._state = int(readPlist(self.filesystem.open_binary_file_for_reading(device_plist))['state'])
- except IOError:
+ SimulatedDeviceManager._last_updated_state = time.time()
+ simctl_json = json.loads(self.executive.run_command([SimulatedDeviceManager.xcrun, 'simctl', 'list', '--json'], decode_output=False, return_stderr=False))
+ state_map = {}
+ for devices in simctl_json['devices'].values():
+ for device in devices:
+ if device.get('udid') and device.get('state'):
+ state_map[device.get('udid')] = device.get('state')
+ for device in SimulatedDeviceManager.AVAILABLE_DEVICES:
+ device.platform_device._state = SimulatedDevice.NAME_FOR_STATE.index(state_map.get(device.platform_device.udid, 'SHUTDOWN').upper())
+ except (ValueError, ScriptError):
+ _log.error("Failed to decode 'simctl list' json output")
self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN
- self._last_updated_state = time.time()
return self._state
def is_booted_or_booting(self, force_update=False):
Modified: trunk/Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py (280881 => 280882)
--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py 2021-08-11 02:58:01 UTC (rev 280881)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py 2021-08-11 04:09:33 UTC (rev 280882)
@@ -642,43 +642,6 @@
runtime = SimulatedDeviceManager.get_runtime_for_device_type(DeviceType.from_string('iphone 5s', Version(9, 4)))
self.assertEquals(runtime, None)
- @staticmethod
- def change_state_to(device, state):
- assert isinstance(state, int)
-
- # Reaching into device.plist to change device state. Note that this will not change the initial state of the device
- # as determined from the .json output.
- device_plist = device.filesystem.expanduser(device.filesystem.join(SimulatedDeviceManager.simulator_device_path, device.udid, 'device.plist'))
- index_position = device.filesystem.files[device_plist].index(b'</integer>') - 1
- device.filesystem.files[device_plist] = device.filesystem.files[device_plist][:index_position] + string_utils.encode(str(state)) + device.filesystem.files[device_plist][index_position + 1:]
-
- def test_swapping_devices(self):
- SimulatedDeviceTest.reset_simulated_device_manager()
- host = SimulatedDeviceTest.mock_host_for_simctl()
- SimulatedDeviceManager.available_devices(host)
-
- # We won't test the creation and deletion of simulators, only managing existing sims
- SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.device_type == DeviceType.from_string('iPhone 8'), host)[0], SimulatedDevice.DeviceState.BOOTED)
- SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.device_type == DeviceType.from_string('iPhone X'), host)[0], SimulatedDevice.DeviceState.BOOTED)
-
- SimulatedDeviceManager.initialize_devices(DeviceRequest(DeviceType.from_string('iPhone 8')), host=host)
-
- self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES))
- self.assertEquals('17104B4F-E77D-4019-98E6-621FE3CC3653', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid)
- self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state())
-
- # Now swap for the X
- SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN)
- SimulatedDeviceManager.swap(SimulatedDeviceManager.INITIALIZED_DEVICES[0], DeviceRequest(DeviceType.from_string('iPhone X')), host)
-
- self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES))
- self.assertEquals('4E6E7393-C4E3-4323-AA8B-4A42A45AE7B8', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid)
- self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state())
-
- SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN)
- SimulatedDeviceManager.tear_down(host)
- self.assertIsNone(SimulatedDeviceManager.INITIALIZED_DEVICES)
-
def test_no_state_files(self):
SimulatedDeviceTest.reset_simulated_device_manager()
host = SimulatedDeviceTest.mock_host_for_simctl()