Changeset 280882 in webkit
- Timestamp:
- Aug 10, 2021, 9:09:33 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
Scripts/webkitpy/xcode/simulated_device.py (modified) (6 diffs)
-
Scripts/webkitpy/xcode/simulated_device_unittest.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r280871 r280882 1 2021-08-10 Jonathan Bedard <jbedard@apple.com> 2 3 [webkitpy] Stop relying on device.plist for simulated device state 4 https://bugs.webkit.org/show_bug.cgi?id=228974 5 <rdar://problem/81749547> 6 7 Reviewed by Stephanie Lewis. 8 9 * Scripts/webkitpy/xcode/simulated_device.py: 10 (SimulatedDeviceManager): 11 (SimulatedDeviceManager.populate_available_devices): Device state check is now shared between simulators. 12 (SimulatedDeviceManager._disambiguate_device_type): Only extract hardware family and type from candidate. 13 (SimulatedDevice.__init__): Device state check is now shared between simulators. 14 (SimulatedDevice.state): Use 'xcrun simctl list' instead of device.plist. 15 * Scripts/webkitpy/xcode/simulated_device_unittest.py: 16 (SimulatedDeviceTest.change_state_to): Deleted. 17 (SimulatedDeviceTest.test_swapping_devices): Deleted. 18 1 19 2021-08-10 Cameron McCormack <heycam@apple.com> 2 20 -
trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py
r280622 r280882 81 81 _device_identifier_to_name = {} 82 82 _managing_simulator_app = False 83 _last_updated_state = 0 83 84 84 85 @staticmethod … … 142 143 SimulatedDeviceManager.AVAILABLE_RUNTIMES = SimulatedDeviceManager._create_runtimes(simctl_json['runtimes']) 143 144 145 SimulatedDeviceManager._last_updated_state = time.time() 144 146 for runtime in SimulatedDeviceManager.AVAILABLE_RUNTIMES: 145 147 # Needed for <rdar://problem/47122965> … … 160 162 # Update device state from simctl output. 161 163 device.platform_device._state = SimulatedDevice.NAME_FOR_STATE.index(device_json['state'].upper()) 162 device.platform_device._last_updated_state = time.time()163 164 return 164 165 … … 254 255 candidate = DeviceType.from_string(type_name) 255 256 if candidate == full_device_type: 256 full_device_type = candidate 257 full_device_type.hardware_family = candidate.hardware_family 258 full_device_type.hardware_type = candidate.hardware_type 257 259 break 258 260 … … 551 553 self.build_version = build_version 552 554 self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN 553 self._last_updated_state = time.time()554 555 555 556 self.executive = host.executive … … 563 564 def state(self, force_update=False): 564 565 # Don't allow state to get stale 565 if not force_update and time.time() < self._last_updated_state + 1:566 if not force_update and time.time() < SimulatedDeviceManager._last_updated_state + 10: 566 567 return self._state 567 568 568 device_plist = self.filesystem.expanduser(self.filesystem.join(SimulatedDeviceManager.simulator_device_path, self.udid, 'device.plist'))569 569 try: 570 self._state = int(readPlist(self.filesystem.open_binary_file_for_reading(device_plist))['state']) 571 except IOError: 570 SimulatedDeviceManager._last_updated_state = time.time() 571 simctl_json = json.loads(self.executive.run_command([SimulatedDeviceManager.xcrun, 'simctl', 'list', '--json'], decode_output=False, return_stderr=False)) 572 state_map = {} 573 for devices in simctl_json['devices'].values(): 574 for device in devices: 575 if device.get('udid') and device.get('state'): 576 state_map[device.get('udid')] = device.get('state') 577 for device in SimulatedDeviceManager.AVAILABLE_DEVICES: 578 device.platform_device._state = SimulatedDevice.NAME_FOR_STATE.index(state_map.get(device.platform_device.udid, 'SHUTDOWN').upper()) 579 except (ValueError, ScriptError): 580 _log.error("Failed to decode 'simctl list' json output") 572 581 self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN 573 582 574 self._last_updated_state = time.time()575 583 return self._state 576 584 -
trunk/Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py
r277531 r280882 643 643 self.assertEquals(runtime, None) 644 644 645 @staticmethod646 def change_state_to(device, state):647 assert isinstance(state, int)648 649 # Reaching into device.plist to change device state. Note that this will not change the initial state of the device650 # as determined from the .json output.651 device_plist = device.filesystem.expanduser(device.filesystem.join(SimulatedDeviceManager.simulator_device_path, device.udid, 'device.plist'))652 index_position = device.filesystem.files[device_plist].index(b'</integer>') - 1653 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:]654 655 def test_swapping_devices(self):656 SimulatedDeviceTest.reset_simulated_device_manager()657 host = SimulatedDeviceTest.mock_host_for_simctl()658 SimulatedDeviceManager.available_devices(host)659 660 # We won't test the creation and deletion of simulators, only managing existing sims661 SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.device_type == DeviceType.from_string('iPhone 8'), host)[0], SimulatedDevice.DeviceState.BOOTED)662 SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.device_by_filter(lambda device: device.device_type == DeviceType.from_string('iPhone X'), host)[0], SimulatedDevice.DeviceState.BOOTED)663 664 SimulatedDeviceManager.initialize_devices(DeviceRequest(DeviceType.from_string('iPhone 8')), host=host)665 666 self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES))667 self.assertEquals('17104B4F-E77D-4019-98E6-621FE3CC3653', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid)668 self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state())669 670 # Now swap for the X671 SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN)672 SimulatedDeviceManager.swap(SimulatedDeviceManager.INITIALIZED_DEVICES[0], DeviceRequest(DeviceType.from_string('iPhone X')), host)673 674 self.assertEquals(1, len(SimulatedDeviceManager.INITIALIZED_DEVICES))675 self.assertEquals('4E6E7393-C4E3-4323-AA8B-4A42A45AE7B8', SimulatedDeviceManager.INITIALIZED_DEVICES[0].udid)676 self.assertEquals(SimulatedDevice.DeviceState.BOOTED, SimulatedDeviceManager.INITIALIZED_DEVICES[0].platform_device.state())677 678 SimulatedDeviceTest.change_state_to(SimulatedDeviceManager.INITIALIZED_DEVICES[0], SimulatedDevice.DeviceState.SHUT_DOWN)679 SimulatedDeviceManager.tear_down(host)680 self.assertIsNone(SimulatedDeviceManager.INITIALIZED_DEVICES)681 682 645 def test_no_state_files(self): 683 646 SimulatedDeviceTest.reset_simulated_device_manager()
Note:
See TracChangeset
for help on using the changeset viewer.