Diff
Modified: trunk/Tools/ChangeLog (226811 => 226812)
--- trunk/Tools/ChangeLog 2018-01-11 23:21:18 UTC (rev 226811)
+++ trunk/Tools/ChangeLog 2018-01-11 23:28:16 UTC (rev 226812)
@@ -1,3 +1,18 @@
+2018-01-11 Jonathan Bedard <jbed...@apple.com>
+
+ webkitpy: Reimplement simulator code (Part 3)
+ https://bugs.webkit.org/show_bug.cgi?id=180555
+ <rdar://problem/36131381>
+
+ Reviewed by Aakash Jain.
+
+ Remove old simulator code.
+
+ * Scripts/webkitpy/xcode/__init__.py: Remove import statement.
+ * Scripts/webkitpy/xcode/simulated_device.py: Removed.
+ * Scripts/webkitpy/xcode/simulator.py: Removed.
+ * Scripts/webkitpy/xcode/simulator_unittest.py: Removed.
+
2018-01-11 Wenson Hsieh <wenson_hs...@apple.com>
[Attachment Support] Support moving attachment elements in editable areas using drag and drop
Modified: trunk/Tools/Scripts/webkitpy/xcode/__init__.py (226811 => 226812)
--- trunk/Tools/Scripts/webkitpy/xcode/__init__.py 2018-01-11 23:21:18 UTC (rev 226811)
+++ trunk/Tools/Scripts/webkitpy/xcode/__init__.py 2018-01-11 23:28:16 UTC (rev 226812)
@@ -1 +1 @@
-import simulator
+# Required for Python to search this directory for module files
Deleted: trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py (226811 => 226812)
--- trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2018-01-11 23:21:18 UTC (rev 226811)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulated_device.py 2018-01-11 23:28:16 UTC (rev 226812)
@@ -1,208 +0,0 @@
-# Copyright (C) 2014-2017 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import logging
-import re
-import subprocess
-
-from webkitpy.common.host import Host
-from webkitpy.common.system.executive import ScriptError
-from webkitpy.common.timeout_context import Timeout
-from webkitpy.xcode.simulator import Simulator
-
-_log = logging.getLogger(__name__)
-
-
-class SimulatedDevice(object):
- """
- Represents a CoreSimulator device underneath a runtime
- """
-
- def __init__(self, name, udid, available, runtime, host):
- """
- :param name: The device name
- :type name: str
- :param udid: The device UDID (a UUID string)
- :type udid: str
- :param available: Whether the device is available for use.
- :type available: bool
- :param runtime: The iOS Simulator runtime that hosts this device
- :type runtime: Runtime
- :param host: The host which can run command line commands
- :type host: Host
- """
- self.available = available
- self.runtime = runtime
- self._host = host
- self.name = name
- self.udid = udid
-
- self.executive = host.executive
- self.filesystem = host.filesystem
- self.user = None
- self.platform = host.platform
- self.workspace = host.workspace
-
- @property
- def state(self):
- """
- :returns: The current state of the device.
- :rtype: Simulator.DeviceState
- """
- return Simulator.device_state(self.udid)
-
- @property
- def path(self):
- """
- :returns: The filesystem path that contains the simulator device's data.
- :rtype: str
- """
- return Simulator.device_directory(self.udid)
-
- @classmethod
- def create(cls, name, device_type, runtime):
- """
- Create a new CoreSimulator device.
- :param name: The name of the device.
- :type name: str
- :param device_type: The CoreSimulatort device type.
- :type device_type: DeviceType
- :param runtime: The CoreSimualtor runtime.
- :type runtime: Runtime
- :return: The new device or raises a CalledProcessError if ``simctl create`` failed.
- :rtype: Device
- """
- device_udid = subprocess.check_output(['xcrun', 'simctl', 'create', name, device_type.identifier, runtime.identifier]).rstrip()
- _log.debug('"xcrun simctl create %s %s %s" returned %s', name, device_type.identifier, runtime.identifier, device_udid)
- Simulator.wait_until_device_is_in_state(device_udid, Simulator.DeviceState.SHUTDOWN)
- return Simulator().find_device_by_udid(device_udid)
-
- @classmethod
- def shutdown(cls, udid):
- """
- Shut down the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- device_state = Simulator.device_state(udid)
- if device_state == Simulator.DeviceState.BOOTING or device_state == Simulator.DeviceState.BOOTED:
- _log.debug('xcrun simctl shutdown %s', udid)
- # Don't throw on error. Device shutdown seems to be racy with Simulator app killing.
- subprocess.call(['xcrun', 'simctl', 'shutdown', udid])
-
- Simulator.wait_until_device_is_in_state(udid, Simulator.DeviceState.SHUTDOWN)
-
- @classmethod
- def delete(cls, udid):
- """
- Delete the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- SimulatedDevice.shutdown(udid)
- try:
- _log.debug('xcrun simctl delete %s', udid)
- subprocess.check_call(['xcrun', 'simctl', 'delete', udid])
- except subprocess.CalledProcessError:
- raise RuntimeError('"xcrun simctl delete" failed: device state is {}'.format(Simulator.device_state(udid)))
-
- @classmethod
- def reset(cls, udid):
- """
- Reset the given CoreSimulator device.
- :param udid: The udid of the device.
- :type udid: str
- """
- SimulatedDevice.shutdown(udid)
- try:
- _log.debug('xcrun simctl erase %s', udid)
- subprocess.check_call(['xcrun', 'simctl', 'erase', udid])
- except subprocess.CalledProcessError:
- raise RuntimeError('"xcrun simctl erase" failed: device state is {}'.format(Simulator.device_state(udid)))
-
- def install_app(self, app_path, env=None):
- # FIXME: This is a workaround for <rdar://problem/30273973>, Racey failure of simctl install.
- for x in xrange(3):
- try:
- self._host.executive.run_command(['xcrun', 'simctl', 'install', self.udid, app_path])
- bundle_id = self._host.executive.run_command([
- '/usr/libexec/PlistBuddy',
- '-c',
- 'Print CFBundleIdentifier',
- self._host.filesystem.join(app_path, 'Info.plist'),
- ]).rstrip()
- self._host.executive.kill_process(self.launch_app(bundle_id, [], env=env, timeout=10))
- return True
- except (RuntimeError, ScriptError):
- pass
- return False
-
- # FIXME: Increase timeout for <rdar://problem/31331576>
- def launch_app(self, bundle_id, args, env=None, timeout=300):
- environment_to_use = {}
- SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'
- for value in (env or {}):
- if not value.startswith(SIMCTL_ENV_PREFIX):
- environment_to_use[SIMCTL_ENV_PREFIX + value] = env[value]
- else:
- environment_to_use[value] = env[value]
-
- # FIXME: This is a workaround for <rdar://problem/30172453>.
- def _log_debug_error(error):
- _log.debug(error.message_with_output())
-
- output = None
-
- with Timeout(timeout, RuntimeError('Timed out waiting for process to open {} on {}'.format(bundle_id, self.udid))):
- while True:
- output = self._host.executive.run_command(
- ['xcrun', 'simctl', 'launch', self.udid, bundle_id] + args,
- env=environment_to_use,
- error_handler=_log_debug_error,
- )
- match = re.match(r'(?P<bundle>[^:]+): (?P<pid>\d+)\n', output)
- # FIXME: We shouldn't need to check the PID <rdar://problem/31154075>.
- if match and self.executive.check_running_pid(int(match.group('pid'))):
- break
- if match:
- _log.debug('simctl launch reported pid {}, but this process is not running'.format(match.group('pid')))
- else:
- _log.debug('simctl launch did not report a pid')
-
- if match.group('bundle') != bundle_id:
- raise RuntimeError('Failed to find process id for {}: {}'.format(bundle_id, output))
- _log.debug('Returning pid {} of launched process'.format(match.group('pid')))
- return int(match.group('pid'))
-
- def __eq__(self, other):
- return self.udid == other.udid
-
- def __ne__(self, other):
- return not self.__eq__(other)
-
- def __repr__(self):
- return '<Device "{name}": {udid}. State: {state}. Runtime: {runtime}, Available: {available}>'.format(
- name=self.name,
- udid=self.udid,
- state=self.state,
- available=self.available,
- runtime=self.runtime.identifier)
Deleted: trunk/Tools/Scripts/webkitpy/xcode/simulator.py (226811 => 226812)
--- trunk/Tools/Scripts/webkitpy/xcode/simulator.py 2018-01-11 23:21:18 UTC (rev 226811)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulator.py 2018-01-11 23:28:16 UTC (rev 226812)
@@ -1,530 +0,0 @@
-# Copyright (C) 2014-2017 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import itertools
-import logging
-import os
-import plistlib
-import re
-import subprocess
-import time
-
-from webkitpy.common.timeout_context import Timeout
-from webkitpy.common.host import Host
-from webkitpy.common.version import Version
-
-_log = logging.getLogger(__name__)
-
-"""
-Minimally wraps CoreSimulator functionality through simctl.
-
-If possible, use real CoreSimulator.framework functionality by linking to the framework itself.
-Do not use PyObjC to dlopen the framework.
-"""
-
-
-class DeviceType(object):
- """
- Represents a CoreSimulator device type.
- """
- def __init__(self, name, identifier):
- """
- :param name: The device type's human-readable name
- :type name: str
- :param identifier: The CoreSimulator identifier.
- :type identifier: str
- """
- self.name = name
- self.identifier = identifier
-
- @classmethod
- def from_name(cls, name):
- """
- :param name: The name for the desired device type.
- :type name: str
- :returns: A `DeviceType` object with the specified identifier or throws a TypeError if it doesn't exist.
- :rtype: DeviceType
- """
- identifier = None
- for device_type in Simulator().device_types:
- if device_type.name == name:
- identifier = device_type.identifier
- break
-
- if identifier is None:
- raise TypeError('A device type with name "{name}" does not exist.'.format(name=name))
-
- return DeviceType(name, identifier)
-
- @classmethod
- def from_identifier(cls, identifier):
- """
- :param identifier: The CoreSimulator identifier for the desired runtime.
- :type identifier: str
- :returns: A `Runtime` object witht the specified identifier or throws a TypeError if it doesn't exist.
- :rtype: DeviceType
- """
- name = None
- for device_type in Simulator().device_types:
- if device_type.identifier == identifier:
- name = device_type.name
- break
-
- if name is None:
- raise TypeError('A device type with identifier "{identifier}" does not exist.'.format(
- identifier=identifier))
-
- return DeviceType(name, identifier)
-
- def __eq__(self, other):
- return (self.name == other.name) and (self.identifier == other.identifier)
-
- def __ne__(self, other):
- return not self.__eq__(other)
-
- def __repr__(self):
- return '<DeviceType "{name}": {identifier}>'.format(name=self.name, identifier=self.identifier)
-
-
-class Runtime(object):
- """
- Represents a CoreSimulator runtime associated with an iOS SDK.
- """
-
- def __init__(self, version, identifier, available, devices=None, is_internal_runtime=False):
- """
- :param version: The iOS SDK version
- :type version: tuple
- :param identifier: The CoreSimulator runtime identifier
- :type identifier: str
- :param availability: Whether the runtime is available for use.
- :type availability: bool
- :param devices: A list of devices under this runtime
- :type devices: list or None
- :param is_internal_runtime: Whether the runtime is an Apple internal runtime
- :type is_internal_runtime: bool
- """
- self.version = version
- self.identifier = identifier
- self.available = available
- self.devices = devices or []
- self.is_internal_runtime = is_internal_runtime
-
- @classmethod
- def from_version(cls, version):
- return cls.from_identifier('com.apple.CoreSimulator.SimRuntime.iOS-' + '{}-{}'.format(version[0], version[1]))
-
- @classmethod
- def from_identifier(cls, identifier):
- """
- :param identifier: The identifier for the desired CoreSimulator runtime.
- :type identifier: str
- :returns: A `Runtime` object with the specified identifier or throws a TypeError if it doesn't exist.
- :rtype: Runtime
- """
- for runtime in Simulator().runtimes:
- if runtime.identifier == identifier:
- return runtime
- raise TypeError('A runtime with identifier "{identifier}" does not exist.'.format(identifier=identifier))
-
- def __eq__(self, other):
- return (self.version == other.version) and (self.identifier == other.identifier) and (self.is_internal_runtime == other.is_internal_runtime)
-
- def __ne__(self, other):
- return not self.__eq__(other)
-
- def __repr__(self):
- version_suffix = ""
- if self.is_internal_runtime:
- version_suffix = " Internal"
- return '<Runtime {version}: {identifier}. Available: {available}, {num_devices} devices>'.format(
- version=str(self.version) + version_suffix,
- identifier=self.identifier,
- available=self.available,
- num_devices=len(self.devices))
-
-
-# FIXME: This class is fragile because it parses the output of the simctl command line utility, which may change.
-# We should find a better way to query for simulator device state and capabilities. Maybe take a similiar
-# approach as in webkitdirs.pm and utilize the parsed output from the device.plist files in the sub-
-# directories of ~/Library/Developer/CoreSimulator/Devices?
-# Also, simctl has the option to output in JSON format (xcrun simctl list --json).
-class Simulator(object):
- """
- Represents the iOS Simulator infrastructure under the currently select Xcode.app bundle.
- """
- device_type_re = re.compile('(?P<name>.+)\((?P<identifier>[^)]+)\)')
- runtime_re = re.compile('(?P<os>.+) \((?P<version>\d+\.\d+(\.\d+)?) - (?P<build_version>[^)]+)\) \((?P<identifier>[^)]+)\)( \((?P<availability>[^)]+)\))?')
- new_runtime_re = re.compile('(?P<os>.+) \((?P<version>\d+\.\d+(\.\d+)?) - (?P<build_version>[^)]+)\) - (?P<identifier>[^)]+)( \((?P<availability>[^)]+)\))?')
- unavailable_version_re = re.compile('-- (Unavailable: )?(?P<identifier>[^ ]+) --')
- version_re = re.compile('-- (i|watch|tv)OS (?P<version>\d+\.\d+)(?P<internal> Internal)? --')
- devices_re = re.compile(
- '\s*(?P<name>.+) \((?P<udid>[A-Z0-9\-]+)\) \((?P<state>[^)]+)\)( \((?P<availability>[^)]+)\))?')
-
- managed_devices = {}
- Device = None
-
- def __init__(self, host=None):
- # FIXME: This circular import should be resolved.
- if not Simulator.Device:
- from webkitpy.xcode.simulated_device import SimulatedDevice
- Simulator.Device = SimulatedDevice
-
- self._host = host or Host()
- self.runtimes = []
- self.device_types = []
- self.refresh()
-
- # Keep these constants synchronized with the SimDeviceState constants in CoreSimulator/SimDevice.h.
- class DeviceState:
- DOES_NOT_EXIST = -1
- CREATING = 0
- SHUTDOWN = 1
- BOOTING = 2
- BOOTED = 3
- SHUTTING_DOWN = 4
-
- NAME_FOR_STATE = [
- 'CREATING',
- 'SHUTDOWN',
- 'BOOTING',
- 'BOOTED',
- 'SHUTTING_DOWN'
- ]
-
- @staticmethod
- def create_device(number, device_type, runtime):
- device = Simulator().lookup_or_create_device(device_type.name + ' WebKit Tester' + str(number), device_type, runtime)
- _log.debug('created device {} {}'.format(number, device))
- assert(len(Simulator.managed_devices) == number)
- Simulator.managed_devices[number] = device
-
- @staticmethod
- def remove_device(number):
- if not Simulator.managed_devices[number]:
- return
- device_udid = Simulator.managed_devices[number].udid
- _log.debug('removing device {} {}'.format(number, device_udid))
- del Simulator.managed_devices[number]
- Simulator.delete_device(device_udid)
-
- @staticmethod
- def device_number(number):
- return Simulator.managed_devices[number]
-
- @staticmethod
- def device_state_description(state):
- if (state == Simulator.DeviceState.DOES_NOT_EXIST):
- return 'DOES_NOT_EXIST'
- return Simulator.NAME_FOR_STATE[state]
-
- # FIXME: When <rdar://problem/31080009> is fixed, decrease timeout back to 5 minutes
- @staticmethod
- def wait_until_device_is_booted(udid, timeout_seconds=60 * 15):
- Simulator.wait_until_device_is_in_state(udid, Simulator.DeviceState.BOOTED, timeout_seconds)
- with Timeout(seconds=timeout_seconds):
- while True:
- try:
- state = subprocess.check_output(['xcrun', 'simctl', 'spawn', udid, 'launchctl', 'print', 'system']).strip()
- _log.debug('xcrun simctl spawn %s', udid)
-
- if re.search("A[\s]+com.apple.springboard.services", state):
- return
- except subprocess.CalledProcessError:
- if Simulator.device_state(udid) != Simulator.DeviceState.BOOTED:
- raise RuntimeError('Simuator device quit unexpectedly.')
- _log.warn("Error in checking Simulator boot status. Will retry in 1 second.")
- time.sleep(1)
-
- # FIXME: When <rdar://problem/31080009> is fixed, decrease timeout back to 5 minutes
- @staticmethod
- def wait_until_device_is_in_state(udid, wait_until_state, timeout_seconds=60 * 15):
- _log.debug('waiting for device %s to enter state %s with timeout %s', udid, Simulator.device_state_description(wait_until_state), timeout_seconds)
- with Timeout(seconds=timeout_seconds):
- device_state = Simulator.device_state(udid)
- while (device_state != wait_until_state):
- device_state = Simulator.device_state(udid)
- _log.debug(' device state %s', Simulator.device_state_description(device_state))
- time.sleep(0.5)
-
- end_state = Simulator.device_state(udid)
- if (end_state != wait_until_state):
- raise RuntimeError('Timed out waiting for simulator device to enter state {0}; current state is {1}'.format(Simulator.device_state_description(wait_until_state), Simulator.device_state_description(end_state)))
-
- @staticmethod
- def device_state(udid):
- device_plist = os.path.join(Simulator.device_directory(udid), 'device.plist')
- if not os.path.isfile(device_plist):
- return Simulator.DeviceState.DOES_NOT_EXIST
- return plistlib.readPlist(device_plist)['state']
-
- @staticmethod
- def device_directory(udid):
- return os.path.realpath(os.path.expanduser(os.path.join('~/Library/Developer/CoreSimulator/Devices', udid)))
-
- @staticmethod
- def delete_device(udid):
- Simulator.Device.delete(udid)
-
- @staticmethod
- def reset_device(udid):
- Simulator.Device.reset(udid)
-
- def refresh(self):
- """
- Refresh runtime and device type information from ``simctl list``.
- """
- lines = self._host.platform.xcode_simctl_list()
- if not lines:
- return
- device_types_header = next(lines)
- if device_types_header != '== Device Types ==':
- raise RuntimeError('Expected == Device Types == header but got: "{}"'.format(device_types_header))
- self._parse_device_types(lines)
-
- def _parse_device_types(self, lines):
- """
- Parse device types from ``simctl list``.
- :param lines: A generator for the output lines from ``simctl list``.
- :type lines: genexpr
- :return: None
- """
- for line in lines:
- device_type_match = self.device_type_re.match(line)
- if not device_type_match:
- if line != '== Runtimes ==':
- raise RuntimeError('Expected == Runtimes == header but got: "{}"'.format(line))
- break
- device_type = DeviceType(name=device_type_match.group('name').rstrip(),
- identifier=device_type_match.group('identifier'))
- self.device_types.append(device_type)
-
- self._parse_runtimes(lines)
-
- def _parse_runtimes(self, lines):
- """
- Continue to parse runtimes from ``simctl list``.
- :param lines: A generator for the output lines from ``simctl list``.
- :type lines: genexpr
- :return: None
- """
- for line in lines:
- runtime_match = self.runtime_re.match(line) or self.new_runtime_re.match(line)
- if not runtime_match:
- if line != '== Devices ==':
- raise RuntimeError('Expected == Devices == header but got: "{}"'.format(line))
- break
- runtime = Runtime(version=Version.from_string(runtime_match.group('version')),
- identifier=runtime_match.group('identifier'),
- available=runtime_match.group('availability') is None,
- is_internal_runtime=('Internal' in runtime_match.group('os')))
- self.runtimes.append(runtime)
- self._parse_devices(lines)
-
- def _parse_devices(self, lines):
- """
- Continue to parse devices from ``simctl list``.
- :param lines: A generator for the output lines from ``simctl list``.
- :type lines: genexpr
- :return: None
- """
- current_runtime = None
- for line in lines:
- version_match = self.version_re.match(line)
- if version_match:
- current_runtime = self.runtime(version=Version.from_string(version_match.group('version')), is_internal_runtime=bool(version_match.group('internal')))
- assert current_runtime
- continue
-
- unavailable_version_match = self.unavailable_version_re.match(line)
- if unavailable_version_match:
- current_runtime = None
- continue
-
- device_match = self.devices_re.match(line)
- if not device_match:
- if line != '== Device Pairs ==':
- raise RuntimeError('Expected == Device Pairs == header but got: "{}"'.format(line))
- break
- if current_runtime:
- device = Simulator.Device(name=device_match.group('name').rstrip(),
- udid=device_match.group('udid'),
- available=device_match.group('availability') is None,
- runtime=current_runtime,
- host=self._host)
- current_runtime.devices.append(device)
-
- def device_type(self, name=None, identifier=None):
- """
- :param name: The short name of the device type.
- :type name: str
- :param identifier: The CoreSimulator identifier of the desired device type.
- :type identifier: str
- :return: A device type with the specified name and/or identifier, or None if one doesn't exist as such.
- :rtype: DeviceType
- """
- for device_type in self.device_types:
- if name and device_type.name != name:
- continue
- if identifier and device_type.identifier != identifier:
- continue
- return device_type
- return None
-
- def runtime(self, version=None, identifier=None, is_internal_runtime=None):
- """
- :param version: The iOS version of the desired runtime.
- :type version: tuple
- :param identifier: The CoreSimulator identifier of the desired runtime.
- :type identifier: str
- :return: A runtime with the specified version and/or identifier, or None if one doesn't exist as such.
- :rtype: Runtime or None
- """
- if version is None and identifier is None:
- raise TypeError('Must supply version and/or identifier.')
-
- for runtime in self.runtimes:
- if version and runtime.version != version:
- continue
- if is_internal_runtime and runtime.is_internal_runtime != is_internal_runtime:
- continue
- if identifier and runtime.identifier != identifier:
- continue
- return runtime
-
- # Allow for a partial version match
- for runtime in self.runtimes:
- if version and runtime.version not in version:
- continue
- if is_internal_runtime and runtime.is_internal_runtime != is_internal_runtime:
- continue
- if identifier and runtime.identifier != identifier:
- continue
- return runtime
- return None
-
- def find_device_by_udid(self, udid):
- """
- :param udid: The UDID of the device to find.
- :type udid: str
- :return: The `Device` with the specified UDID.
- :rtype: Device
- """
- for device in self.devices:
- if device.udid == udid:
- return device
- return None
-
- def current_device(self):
- # FIXME: Find the simulator device that was booted by Simulator.app. For now, pick some booted simulator device, which
- # may have been booted using the simctl command line tool.
- for device in self.devices:
- if device.state == Simulator.DeviceState.BOOTED:
- return device
- return None
-
- # FIXME: We should find an existing device with respect to its name, device type and runtime.
- def device(self, name=None, runtime=None, should_ignore_unavailable_devices=False):
- """
- :param name: The name of the desired device.
- :type name: str
- :param runtime: The runtime of the desired device.
- :type runtime: Runtime
- :return: A device with the specified name and/or runtime, or None if one doesn't exist as such
- :rtype: Device or None
- """
- if name is None and runtime is None:
- raise TypeError('Must supply name and/or runtime.')
-
- for device in self.devices:
- if should_ignore_unavailable_devices and not device.available:
- continue
- if name and device.name != name:
- continue
- if runtime and device.runtime != runtime:
- continue
- return device
- return None
-
- @property
- def available_runtimes(self):
- """
- :return: An iterator of all available runtimes.
- :rtype: iter
- """
- return itertools.ifilter(lambda runtime: runtime.available, self.runtimes)
-
- @property
- def devices(self):
- """
- :return: An iterator of all devices from all runtimes.
- :rtype: iter
- """
- return itertools.chain(*[runtime.devices for runtime in self.runtimes])
-
- @property
- def latest_available_runtime(self):
- """
- :return: Returns a Runtime object with the highest version.
- :rtype: Runtime or None
- """
- if not self.runtimes:
- return None
- return sorted(self.available_runtimes, key=lambda runtime: runtime.version, reverse=True)[0]
-
- def lookup_or_create_device(self, name, device_type, runtime):
- """
- Returns an available iOS Simulator device for testing.
-
- This function will create a new simulator device with the specified name,
- device type and runtime if one does not already exist.
-
- :param name: The name of the simulator device to lookup or create.
- :type name: str
- :param device_type: The CoreSimulator device type.
- :type device_type: DeviceType
- :param runtime: The CoreSimulator runtime.
- :type runtime: Runtime
- :return: A dictionary describing the device.
- :rtype: Device
- """
- assert(runtime.available)
- testing_device = self.device(name=name, runtime=runtime, should_ignore_unavailable_devices=True)
- if testing_device:
- _log.debug('lookup_or_create_device %s %s %s found %s', name, device_type, runtime, testing_device.name)
- return testing_device
- testing_device = Simulator.Device.create(name, device_type, runtime)
- _log.debug('lookup_or_create_device %s %s %s created %s', name, device_type, runtime, testing_device.name)
- assert(testing_device.available)
- return testing_device
-
- def __repr__(self):
- return '<iOS Simulator: {num_runtimes} runtimes, {num_device_types} device types>'.format(
- num_runtimes=len(self.runtimes),
- num_device_types=len(self.device_types))
-
- def __str__(self):
- description = ['iOS Simulator:']
- description += map(str, self.runtimes)
- description += map(str, self.device_types)
- description += map(str, self.devices)
- return '\n'.join(description)
Deleted: trunk/Tools/Scripts/webkitpy/xcode/simulator_unittest.py (226811 => 226812)
--- trunk/Tools/Scripts/webkitpy/xcode/simulator_unittest.py 2018-01-11 23:21:18 UTC (rev 226811)
+++ trunk/Tools/Scripts/webkitpy/xcode/simulator_unittest.py 2018-01-11 23:28:16 UTC (rev 226812)
@@ -1,381 +0,0 @@
-# Copyright (C) 2015-2017 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
-# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import unittest
-
-from webkitpy.common.host_mock import MockHost
-from webkitpy.common.version import Version
-from webkitpy.xcode.simulator import Simulator
-
-
-class SimulatorTest(unittest.TestCase):
-
- def setUp(self):
- """ Set up method for SimulatorTest """
- self._host = MockHost()
-
- def _set_expected_xcrun_simctl_list(self, lines):
- self._host.platform.expected_xcode_simctl_list = (line for line in lines.splitlines())
-
- def test_simulator_device_types(self):
- """ Tests that valid `xcrun simctl list` output is parsed as expected """
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
-iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
-iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
-iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
-iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
-iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
-iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
-iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
-iPad Pro (9.7-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-)
-Apple TV 1080p (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p)
-Apple Watch - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm)
-Apple Watch - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm)
-== Runtimes ==
-iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0)
-iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found)
-iOS 8.4 (8.4.1 - 12H321) (com.apple.CoreSimulator.SimRuntime.iOS-8-4)
-tvOS 9.0 (9.0 - 13T5347l) (com.apple.CoreSimulator.SimRuntime.tvOS-9-0)
-watchOS 2.0 (2.0 - 13S343) (com.apple.CoreSimulator.SimRuntime.watchOS-2-0)
-iOS 10.0 (10.0 - 14280) - com.apple.CoreSimulator.SimRuntime.iOS-10-0
-iOS 11.0.1 (11.0.1 - 15280) - com.apple.CoreSimulator.SimRuntime.iOS-11-0
-== Devices ==
--- iOS 8.0 --
- iPhone 4s (68D9A792-E3A9-462B-B211-762C6A5D3779) (Shutdown)
- iPhone 5 (1C3767FF-C268-4961-B6DA-F4F75E99EF5D) (Shutdown)
- iPhone 5s (2A1CB363-9A09-4438-B9BE-9C42BD208F72) (Shutdown)
- iPhone 5s WebKit Tester (79BA9206-E0B6-4D0E-B0E8-A88E2D45515D) (Booted)
- iPhone 6 Plus (7F8039BE-D4A0-4245-9D56-AF94413FD6F5) (Shutdown)
- iPhone 6 (7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691) (Shutdown)
- iPad 2 (2967C54F-A499-4043-A82C-8C1F5ADBB4A9) (Shutdown)
- iPad Retina (733FC71E-22F4-4077-BF79-25C27EA881FC) (Shutdown)
- iPad Air (67266841-82F3-4545-AED6-568B117E41A8) (Shutdown)
- iPad Pro (9.7 inch) (DEBD50B8-0566-4D7A-BCDB-4134CFE5DA40) (Shutdown)
- iPhone 7 (2AE58BBE-0995-4326-9B65-2F413E2E33DC) (Shutdown) (unavailable, runtime profile not found)
--- iOS 8.0 Internal --
--- tvOS 9.0 --
-Apple TV 1080p (55281ABE-9C27-438B-AD50-C540D7BC4BAC) (Shutdown)
--- watchOS 2.0 --
- Apple Watch - 38mm (00138CD2-D30C-4380-A30E-A70B88E1A3C5) (Shutdown)
- Apple Watch - 42mm (186AD85E-9BE5-4734-BC33-DF50484AAFF0) (Shutdown)
--- iOS 11.0 --
- iPhone 7 (48E6CA73-4BF7-4153-BEE2-736CD881FEBD) (Shutdown) (unavailable, runtime profile not found)
-''')
- simulator = Simulator(host=self._host)
- self.assertEqual(12, len(simulator.device_types))
-
- device_type_iphone_4s = simulator.device_types[0]
- self.assertEqual('iPhone 4s', device_type_iphone_4s.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier)
-
- device_type_iphone_5 = simulator.device_types[1]
- self.assertEqual('iPhone 5', device_type_iphone_5.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5', device_type_iphone_5.identifier)
-
- device_type_iphone_5s = simulator.device_types[2]
- self.assertEqual('iPhone 5s', device_type_iphone_5s.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-5s', device_type_iphone_5s.identifier)
-
- device_type_iphone_6_plus = simulator.device_types[3]
- self.assertEqual('iPhone 6 Plus', device_type_iphone_6_plus.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus', device_type_iphone_6_plus.identifier)
-
- device_type_iphone_6 = simulator.device_types[4]
- self.assertEqual('iPhone 6', device_type_iphone_6.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-6', device_type_iphone_6.identifier)
-
- device_type_ipad_2 = simulator.device_types[5]
- self.assertEqual('iPad 2', device_type_ipad_2.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-2', device_type_ipad_2.identifier)
-
- device_type_ipad_retina = simulator.device_types[6]
- self.assertEqual('iPad Retina', device_type_ipad_retina.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Retina', device_type_ipad_retina.identifier)
-
- device_type_ipad_air = simulator.device_types[7]
- self.assertEqual('iPad Air', device_type_ipad_air.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Air', device_type_ipad_air.identifier)
-
- device_type_ipad_pro = simulator.device_types[8]
- self.assertEqual('iPad Pro (9.7-inch)', device_type_ipad_pro.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-', device_type_ipad_pro.identifier)
-
- device_type_apple_tv_1080p = simulator.device_types[9]
- self.assertEqual('Apple TV 1080p', device_type_apple_tv_1080p.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p', device_type_apple_tv_1080p.identifier)
-
- device_type_apple_watch_38mm = simulator.device_types[10]
- self.assertEqual('Apple Watch - 38mm', device_type_apple_watch_38mm.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm', device_type_apple_watch_38mm.identifier)
-
- device_type_apple_watch_42mm = simulator.device_types[11]
- self.assertEqual('Apple Watch - 42mm', device_type_apple_watch_42mm.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm', device_type_apple_watch_42mm.identifier)
-
- self.assertEqual(7, len(simulator.runtimes))
-
- runtime_ios_8 = simulator.runtimes[0]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
- self.assertEqual(True, runtime_ios_8.available)
- self.assertEqual(False, runtime_ios_8.is_internal_runtime)
- self.assertEqual(Version(8, 0), runtime_ios_8.version)
- self.assertEqual(11, len(runtime_ios_8.devices))
-
- device_iphone_4s = runtime_ios_8.devices[0]
- self.assertEqual('iPhone 4s', device_iphone_4s.name)
- self.assertEqual('68D9A792-E3A9-462B-B211-762C6A5D3779', device_iphone_4s.udid)
- self.assertEqual(True, device_iphone_4s.available)
- self.assertEqual(runtime_ios_8, device_iphone_4s.runtime)
-
- device_iphone_5 = runtime_ios_8.devices[1]
- self.assertEqual('iPhone 5', device_iphone_5.name)
- self.assertEqual('1C3767FF-C268-4961-B6DA-F4F75E99EF5D', device_iphone_5.udid)
- self.assertEqual(True, device_iphone_5.available)
- self.assertEqual(runtime_ios_8, device_iphone_5.runtime)
-
- device_iphone_5s = runtime_ios_8.devices[2]
- self.assertEqual('iPhone 5s', device_iphone_5s.name)
- self.assertEqual('2A1CB363-9A09-4438-B9BE-9C42BD208F72', device_iphone_5s.udid)
- self.assertEqual(True, device_iphone_5s.available)
- self.assertEqual(runtime_ios_8, device_iphone_5s.runtime)
-
- device_iphone_5s_webkit_tester = runtime_ios_8.devices[3]
- self.assertEqual('iPhone 5s WebKit Tester', device_iphone_5s_webkit_tester.name)
- self.assertEqual('79BA9206-E0B6-4D0E-B0E8-A88E2D45515D', device_iphone_5s_webkit_tester.udid)
- self.assertEqual(True, device_iphone_5s_webkit_tester.available)
- self.assertEqual(runtime_ios_8, device_iphone_5s_webkit_tester.runtime)
-
- device_iphone_6_plus = runtime_ios_8.devices[4]
- self.assertEqual('iPhone 6 Plus', device_iphone_6_plus.name)
- self.assertEqual('7F8039BE-D4A0-4245-9D56-AF94413FD6F5', device_iphone_6_plus.udid)
- self.assertEqual(True, device_iphone_6_plus.available)
- self.assertEqual(runtime_ios_8, device_iphone_6_plus.runtime)
-
- device_iphone_6 = runtime_ios_8.devices[5]
- self.assertEqual('iPhone 6', device_iphone_6.name)
- self.assertEqual('7BF9F835-0CEA-4EE3-BD15-A62BD9F4B691', device_iphone_6.udid)
- self.assertEqual(True, device_iphone_6.available)
- self.assertEqual(runtime_ios_8, device_iphone_6.runtime)
-
- device_ipad_2 = runtime_ios_8.devices[6]
- self.assertEqual('iPad 2', device_ipad_2.name)
- self.assertEqual('2967C54F-A499-4043-A82C-8C1F5ADBB4A9', device_ipad_2.udid)
- self.assertEqual(True, device_ipad_2.available)
- self.assertEqual(runtime_ios_8, device_ipad_2.runtime)
-
- device_ipad_retina = runtime_ios_8.devices[7]
- self.assertEqual('iPad Retina', device_ipad_retina.name)
- self.assertEqual('733FC71E-22F4-4077-BF79-25C27EA881FC', device_ipad_retina.udid)
- self.assertEqual(True, device_ipad_retina.available)
- self.assertEqual(runtime_ios_8, device_ipad_retina.runtime)
-
- device_ipad_air = runtime_ios_8.devices[8]
- self.assertEqual('iPad Air', device_ipad_air.name)
- self.assertEqual('67266841-82F3-4545-AED6-568B117E41A8', device_ipad_air.udid)
- self.assertEqual(True, device_ipad_air.available)
- self.assertEqual(runtime_ios_8, device_ipad_air.runtime)
-
- device_ipad_pro = runtime_ios_8.devices[9]
- self.assertEqual('iPad Pro (9.7 inch)', device_ipad_pro.name)
- self.assertEqual('DEBD50B8-0566-4D7A-BCDB-4134CFE5DA40', device_ipad_pro.udid)
- self.assertEqual(True, device_ipad_pro.available)
- self.assertEqual(runtime_ios_8, device_ipad_pro.runtime)
-
- device_iphone_7 = runtime_ios_8.devices[10]
- self.assertEqual('iPhone 7', device_iphone_7.name)
- self.assertEqual('2AE58BBE-0995-4326-9B65-2F413E2E33DC', device_iphone_7.udid)
- self.assertEqual(False, device_iphone_7.available)
- self.assertEqual(runtime_ios_8, device_iphone_7.runtime)
-
- runtime_ios_8_internal = simulator.runtimes[1]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
- self.assertEqual(False, runtime_ios_8_internal.available)
- self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
- self.assertEqual(Version(8, 0), runtime_ios_8_internal.version)
- self.assertEqual(0, len(runtime_ios_8_internal.devices))
-
- runtime_ios_8_4 = simulator.runtimes[2]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-4', runtime_ios_8_4.identifier)
- self.assertEqual(True, runtime_ios_8_4.available)
- self.assertEqual(False, runtime_ios_8_4.is_internal_runtime)
- self.assertEqual(Version(8, 4, 1), runtime_ios_8_4.version)
- self.assertEqual(0, len(runtime_ios_8_4.devices))
-
- runtime_tvos_9 = simulator.runtimes[3]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.tvOS-9-0', runtime_tvos_9.identifier)
- self.assertEqual(True, runtime_tvos_9.available)
- self.assertEqual(False, runtime_tvos_9.is_internal_runtime)
- self.assertEqual(Version(9, 0), runtime_tvos_9.version)
- self.assertEqual(1, len(runtime_tvos_9.devices))
-
- device_apple_tv_1080p = runtime_tvos_9.devices[0]
- self.assertEqual('Apple TV 1080p', device_apple_tv_1080p.name)
- self.assertEqual('55281ABE-9C27-438B-AD50-C540D7BC4BAC', device_apple_tv_1080p.udid)
- self.assertEqual(True, device_apple_tv_1080p.available)
- self.assertEqual(runtime_tvos_9, device_apple_tv_1080p.runtime)
-
- runtime_watchos_2 = simulator.runtimes[4]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.watchOS-2-0', runtime_watchos_2.identifier)
- self.assertEqual(True, runtime_watchos_2.available)
- self.assertEqual(False, runtime_watchos_2.is_internal_runtime)
- self.assertEqual(Version(2, 0), runtime_watchos_2.version)
- self.assertEqual(2, len(runtime_watchos_2.devices))
-
- runtime_ios_10 = simulator.runtimes[5]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-10-0', runtime_ios_10.identifier)
- self.assertEqual(True, runtime_ios_10.available)
- self.assertEqual(False, runtime_ios_10.is_internal_runtime)
- self.assertEqual(Version(10, 0), runtime_ios_10.version)
- self.assertEqual(0, len(runtime_ios_10.devices))
-
- device_apple_watch_38mm = runtime_watchos_2.devices[0]
- self.assertEqual('Apple Watch - 38mm', device_apple_watch_38mm.name)
- self.assertEqual('00138CD2-D30C-4380-A30E-A70B88E1A3C5', device_apple_watch_38mm.udid)
- self.assertEqual(True, device_apple_watch_38mm.available)
- self.assertEqual(runtime_watchos_2, device_apple_watch_38mm.runtime)
-
- device_apple_watch_42mm = runtime_watchos_2.devices[1]
- self.assertEqual('Apple Watch - 42mm', device_apple_watch_42mm.name)
- self.assertEqual('186AD85E-9BE5-4734-BC33-DF50484AAFF0', device_apple_watch_42mm.udid)
- self.assertEqual(True, device_apple_watch_42mm.available)
- self.assertEqual(runtime_watchos_2, device_apple_watch_42mm.runtime)
-
- def test_invalid_device_types_header(self):
- """ Tests that an invalid Device Types header throws an exception """
- self._set_expected_xcrun_simctl_list('''XX Device Types XX
-''')
- with self.assertRaises(RuntimeError) as cm:
- Simulator(host=self._host)
- self.assertEqual('Expected == Device Types == header but got: "XX Device Types XX"', cm.exception.message)
-
- def test_invalid_runtimes_header(self):
- """ Tests that an invalid Runtimes header throws an exception """
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
-XX Runtimes XX
-''')
- with self.assertRaises(RuntimeError) as cm:
- Simulator(host=self._host)
- self.assertEqual('Expected == Runtimes == header but got: "XX Runtimes XX"', cm.exception.message)
-
- def test_invalid_devices_header(self):
- """ Tests that an invalid Devices header throws an exception """
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
-== Runtimes ==
-iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0)
-XX Devices XX
-''')
- with self.assertRaises(RuntimeError) as cm:
- Simulator(host=self._host)
- self.assertEqual('Expected == Devices == header but got: "XX Devices XX"', cm.exception.message)
-
- def test_unavailable_devices(self):
- """ Tests that unavailable devices are ignored """
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
-== Runtimes ==
-iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0)
-iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found)
-== Devices ==
--- iOS 8.0 --
- iPhone 4s (271BBEAC-1826-4CE1-B3AF-83F35CDD1D82) (Shutdown)
--- iOS 8.0 Internal --
--- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-1 --
- iPhone 4s (08C0542B-65F7-46E8-B203-CB4055207BC8) (Shutdown) (unavailable, runtime profile not found)
--- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-2 --
- iPhone 4s (A36F7432-0AF5-49C4-A261-C44383992597) (Shutdown) (unavailable, runtime profile not found)
-''')
- simulator = Simulator(host=self._host)
- self.assertEqual(1, len(simulator.device_types))
-
- device_type_iphone_4s = simulator.device_types[0]
- self.assertEqual('iPhone 4s', device_type_iphone_4s.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier)
-
- self.assertEqual(2, len(simulator.runtimes))
-
- runtime_ios_8 = simulator.runtimes[0]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
- self.assertEqual(True, runtime_ios_8.available)
- self.assertEqual(False, runtime_ios_8.is_internal_runtime)
- self.assertEqual(Version(8, 0), runtime_ios_8.version)
- self.assertEqual(1, len(runtime_ios_8.devices))
-
- device_iphone_4s = runtime_ios_8.devices[0]
- self.assertEqual('iPhone 4s', device_iphone_4s.name)
- self.assertEqual('271BBEAC-1826-4CE1-B3AF-83F35CDD1D82', device_iphone_4s.udid)
- self.assertEqual(True, device_iphone_4s.available)
- self.assertEqual(runtime_ios_8, device_iphone_4s.runtime)
-
- runtime_ios_8_internal = simulator.runtimes[1]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
- self.assertEqual(False, runtime_ios_8_internal.available)
- self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
- self.assertEqual(Version(8, 0), runtime_ios_8_internal.version)
- self.assertEqual(0, len(runtime_ios_8_internal.devices))
-
- def test_failed_partial_version_match(self):
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
-== Runtimes ==
-iOS 11.0.1 (11.0.1 - 15280) - com.apple.CoreSimulator.SimRuntime.iOS-11-0
-== Devices ==
--- iOS 11.1 --
-iPhone 6 (48E6CA73-4BF7-4153-BEE2-736CD881FEBD) (Shutdown)
- ''')
- self.assertRaises(AssertionError, lambda: Simulator(host=self._host))
-
- def test_device_pairs(self):
- """ Tests that Device Pairs header does not cause parsing exception """
- self._set_expected_xcrun_simctl_list('''== Device Types ==
-iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
-== Runtimes ==
-iOS 8.0 (8.0 - 12A465) (com.apple.CoreSimulator.SimRuntime.iOS-8-0)
-iOS 8.0 Internal (8.0 - Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal) (unavailable, runtime path not found)
-== Devices ==
--- iOS 8.0 --
- iPhone 4s (271BBEAC-1826-4CE1-B3AF-83F35CDD1D82) (Shutdown)
-== Device Pairs ==
-''')
- simulator = Simulator(host=self._host)
- self.assertEqual(1, len(simulator.device_types))
-
- device_type_iphone_4s = simulator.device_types[0]
- self.assertEqual('iPhone 4s', device_type_iphone_4s.name)
- self.assertEqual('com.apple.CoreSimulator.SimDeviceType.iPhone-4s', device_type_iphone_4s.identifier)
-
- self.assertEqual(2, len(simulator.runtimes))
-
- runtime_ios_8 = simulator.runtimes[0]
- self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
- self.assertEqual(True, runtime_ios_8.available)
- self.assertEqual(False, runtime_ios_8.is_internal_runtime)
- self.assertEqual(Version(8, 0), runtime_ios_8.version)
- self.assertEqual(1, len(runtime_ios_8.devices))
-
- device_iphone_4s = runtime_ios_8.devices[0]
- self.assertEqual('iPhone 4s', device_iphone_4s.name)
- self.assertEqual('271BBEAC-1826-4CE1-B3AF-83F35CDD1D82', device_iphone_4s.udid)
- self.assertEqual(True, device_iphone_4s.available)
- self.assertEqual(runtime_ios_8, device_iphone_4s.runtime)