⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280882 in webkit


Ignore:
Timestamp:
Aug 10, 2021, 9:09:33 PM (5 years ago)
Author:
Jonathan Bedard
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.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r280871 r280882  
     12021-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
    1192021-08-10  Cameron McCormack  <heycam@apple.com>
    220
  • trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py

    r280622 r280882  
    8181    _device_identifier_to_name = {}
    8282    _managing_simulator_app = False
     83    _last_updated_state = 0
    8384
    8485    @staticmethod
     
    142143        SimulatedDeviceManager.AVAILABLE_RUNTIMES = SimulatedDeviceManager._create_runtimes(simctl_json['runtimes'])
    143144
     145        SimulatedDeviceManager._last_updated_state = time.time()
    144146        for runtime in SimulatedDeviceManager.AVAILABLE_RUNTIMES:
    145147            # Needed for <rdar://problem/47122965>
     
    160162                # Update device state from simctl output.
    161163                device.platform_device._state = SimulatedDevice.NAME_FOR_STATE.index(device_json['state'].upper())
    162                 device.platform_device._last_updated_state = time.time()
    163164        return
    164165
     
    254255                candidate = DeviceType.from_string(type_name)
    255256                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
    257259                    break
    258260
     
    551553        self.build_version = build_version
    552554        self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN
    553         self._last_updated_state = time.time()
    554555
    555556        self.executive = host.executive
     
    563564    def state(self, force_update=False):
    564565        # 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:
    566567            return self._state
    567568
    568         device_plist = self.filesystem.expanduser(self.filesystem.join(SimulatedDeviceManager.simulator_device_path, self.udid, 'device.plist'))
    569569        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")
    572581            self._state = SimulatedDevice.DeviceState.SHUTTING_DOWN
    573582
    574         self._last_updated_state = time.time()
    575583        return self._state
    576584
  • trunk/Tools/Scripts/webkitpy/xcode/simulated_device_unittest.py

    r277531 r280882  
    643643        self.assertEquals(runtime, None)
    644644
    645     @staticmethod
    646     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 device
    650         # 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>') - 1
    653         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 sims
    661         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 X
    671         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 
    682645    def test_no_state_files(self):
    683646        SimulatedDeviceTest.reset_simulated_device_manager()
Note: See TracChangeset for help on using the changeset viewer.