Exemplo n.º 1
0
        private string CreateName(string deviceType, string runtime)
        {
            var runtimeName = _supportedRuntimes?.Where(v => v.Identifier == runtime).FirstOrDefault()?.Name ?? Path.GetExtension(runtime).Substring(1);
            var deviceName  = _supportedDeviceTypes?.Where(v => v.Identifier == deviceType).FirstOrDefault()?.Name ?? Path.GetExtension(deviceType).Substring(1);

            return($"{deviceName} ({runtimeName}) - created by XHarness");
        }
Exemplo n.º 2
0
        public ISimulatorDevice FindCompanionDevice(ILog log, ISimulatorDevice device)
        {
            var pair = _availableDevicePairs.Where(v => v.Gizmo == device.UDID).Single();

            return(_availableDevices.Single(v => v.UDID == pair.Companion));
        }
Exemplo n.º 3
0
        public async Task <(ISimulatorDevice Simulator, ISimulatorDevice?CompanionSimulator)> FindSimulators(TestTargetOs target, ILog log, bool createIfNeeded = true, bool minVersion = false)
        {
            var runtimePrefix = target.Platform switch
            {
                TestTarget.Simulator_iOS32 => "com.apple.CoreSimulator.SimRuntime.iOS-",
                TestTarget.Simulator_iOS64 => "com.apple.CoreSimulator.SimRuntime.iOS-",
                TestTarget.Simulator_iOS => "com.apple.CoreSimulator.SimRuntime.iOS-",
                TestTarget.Simulator_tvOS => "com.apple.CoreSimulator.SimRuntime.tvOS-",
                TestTarget.Simulator_watchOS => "com.apple.CoreSimulator.SimRuntime.watchOS-",
                _ => throw new Exception(string.Format("Invalid simulator target: {0}", target))
            };

            var runtimeVersion = target.OSVersion;

            if (runtimeVersion == null)
            {
                if (!_loaded)
                {
                    await LoadDevices(log);
                }

                string?firstOsVersion = _supportedRuntimes
                                        .Where(r => r.Identifier.StartsWith(runtimePrefix))
                                        .OrderByDescending(r => r.Identifier)
                                        .FirstOrDefault()?
                                        .Identifier
                                        .Substring(runtimePrefix.Length);

                runtimeVersion = firstOsVersion ?? throw new NoDeviceFoundException($"Failed to find a suitable OS runtime version for {target.AsString()}");
            }

            string simulatorRuntime    = runtimePrefix + runtimeVersion.Replace('.', '-');
            string simulatorDeviceType = target.Platform switch
            {
                TestTarget.Simulator_iOS => "com.apple.CoreSimulator.SimDeviceType.iPhone-5",
                TestTarget.Simulator_iOS32 => "com.apple.CoreSimulator.SimDeviceType.iPhone-5",
                TestTarget.Simulator_iOS64 => "com.apple.CoreSimulator.SimDeviceType." + (minVersion ? "iPhone-6" : "iPhone-X"),
                TestTarget.Simulator_tvOS => "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p",
                TestTarget.Simulator_watchOS => "com.apple.CoreSimulator.SimDeviceType." + (minVersion ? "Apple-Watch-38mm" : "Apple-Watch-Series-3-38mm"),
                _ => throw new Exception(string.Format("Invalid simulator target: {0}", target))
            };

            string?companionDeviceType = null;
            string?companionRuntime    = null;

            if (target.Platform == TestTarget.Simulator_watchOS)
            {
                // TODO: Allow to specify companion runtime
                companionRuntime    = "com.apple.CoreSimulator.SimRuntime.iOS-" + (minVersion ? SdkVersions.MinWatchOSCompanionSimulator : SdkVersions.MaxWatchOSCompanionSimulator).Replace('.', '-');
                companionDeviceType = "com.apple.CoreSimulator.SimDeviceType." + (minVersion ? "iPhone-6" : "iPhone-X");
            }

            var devices = await FindOrCreateDevicesAsync(log, simulatorRuntime, simulatorDeviceType);

            IEnumerable <ISimulatorDevice>?companionDevices = null;

            if (companionRuntime != null && companionDeviceType != null)
            {
                companionDevices = await FindOrCreateDevicesAsync(log, companionRuntime, companionDeviceType);
            }

            if (devices?.Any() != true)
            {
                throw new Exception($"Could not find or create devices{Environment.NewLine}" +
                                    $"runtime: {simulatorRuntime}{Environment.NewLine}" +
                                    $"device type: {simulatorDeviceType}");
            }

            ISimulatorDevice?simulator          = null;
            ISimulatorDevice?companionSimulator = null;

            if (companionRuntime == null)
            {
                simulator = devices.First();
            }
            else
            {
                if (companionDevices?.Any() != true)
                {
                    throw new Exception($"Could not find or create companion devices{Environment.NewLine}" +
                                        $"runtime: {companionRuntime}{Environment.NewLine}" +
                                        $"device type: {companionDeviceType}");
                }

                var pair = await FindOrCreateDevicePairAsync(log, devices, companionDevices);

                if (pair == null)
                {
                    throw new Exception($"Could not find or create device pair{Environment.NewLine}" +
                                        $"runtime: {companionRuntime}{Environment.NewLine}" +
                                        $"device type: {companionDeviceType}");
                }

                simulator          = devices.First(v => v.UDID == pair.Gizmo);
                companionSimulator = companionDevices.First(v => v.UDID == pair.Companion);
            }

            if (simulator == null)
            {
                throw new Exception($"Could not find simulator{Environment.NewLine}" +
                                    $"runtime: {simulatorRuntime}{Environment.NewLine}" +
                                    $"device type: {simulatorDeviceType}");
            }

            log.WriteLine("Found simulator: {0} {1}", simulator.Name, simulator.UDID);

            if (companionSimulator != null)
            {
                log.WriteLine("Found companion simulator: {0} {1}", companionSimulator.Name, companionSimulator.UDID);
            }

            return(simulator, companionSimulator);
        }