Esempio n. 1
0
        public async Task FindAsyncDoNotCreateTest(AppRunnerTarget target, int expected)
        {
            string           processPath     = null;
            MlaunchArguments passedArguments = null;

            // set the expectations of the mocks to get an error when
            // executing the process
            harness.Setup(h => h.MlaunchPath).Returns(mlaunchPath);
            harness.Setup(h => h.XcodeRoot).Returns(sdkPath);
            // moq It.Is is not working as nicelly as we would like it, we capture data and use asserts
            processManager.Setup(p => p.RunAsync(It.IsAny <Process> (), It.IsAny <MlaunchArguments> (), It.IsAny <ILog> (), It.IsAny <TimeSpan?> (), It.IsAny <Dictionary <string, string> > (), It.IsAny <CancellationToken?> (), It.IsAny <bool?> ()))
            .Returns <Process, MlaunchArguments, ILog, TimeSpan?, Dictionary <string, string>, CancellationToken?, bool?> ((p, args, log, t, env, token, d) => {
                processPath     = p.StartInfo.FileName;
                passedArguments = args;

                // we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :)
                var(type, value) = args.GetArguments().Where(a => a.type == MlaunchArgumentType.ListSim).First();
                var tempPath     = value;
                CopySampleData(tempPath);
                return(Task.FromResult(new ProcessExecutionResult {
                    ExitCode = 0, TimedOut = false
                }));
            });

            await simulators.LoadAsync(executionLog.Object);

            var sims = await simulators.FindAsync(target, executionLog.Object, false, false);

            Assert.AreEqual(expected, sims.Count(), $"{target} simulators count");
        }
Esempio n. 2
0
        public static string AsString(this AppRunnerTarget @this)
        {
            switch (@this)
            {
            case AppRunnerTarget.None:
                return(null);

            case AppRunnerTarget.Device_iOS:
                return("ios-device");

            case AppRunnerTarget.Device_tvOS:
                return("tvos-device");

            case AppRunnerTarget.Device_watchOS:
                return("watchos-device");

            case AppRunnerTarget.Simulator_iOS:
                return("ios-simulator");

            case AppRunnerTarget.Simulator_iOS32:
                return("ios-simulator-32");

            case AppRunnerTarget.Simulator_iOS64:
                return("ios-simulator-64");

            case AppRunnerTarget.Simulator_tvOS:
                return("tvos-simulator");

            case AppRunnerTarget.Simulator_watchOS:
                return("watchos-simulator");

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
 public IEnumerable <SimDevice> SelectDevices(AppRunnerTarget target, Log log)
 {
     return(new SimulatorEnumerable
     {
         Simulators = this,
         Target = target,
         Log = log,
     });
 }
Esempio n. 4
0
 public IEnumerable <ISimulatorDevice> SelectDevices(AppRunnerTarget target, ILog log, bool min_version)
 {
     return(new SimulatorEnumerable {
         Simulators = this,
         Target = target,
         MinVersion = min_version,
         Log = log,
     });
 }
Esempio n. 5
0
        public async Task <SimDevice []> FindAsync(AppRunnerTarget target, Log log)
        {
            SimDevice [] simulators = null;

            string [] simulator_devicetypes;
            string    simulator_runtime;

            string [] companion_devicetypes = null;
            string    companion_runtime     = null;

            switch (target)
            {
            case AppRunnerTarget.Simulator_iOS32:
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_iOS64:
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5s" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_iOS:
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-5" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_tvOS:
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.tvOS-" + Xamarin.SdkVersions.TVOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_watchOS:
                simulator_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm", "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-38mm" };
                simulator_runtime     = "com.apple.CoreSimulator.SimRuntime.watchOS-" + Xamarin.SdkVersions.WatchOS.Replace('.', '-');
                companion_devicetypes = new string [] { "com.apple.CoreSimulator.SimDeviceType.iPhone-6s" };
                companion_runtime     = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            default:
                throw new Exception(string.Format("Unknown simulator target: {0}", target));
            }

            var devices = AvailableDevices.Where((SimDevice v) =>
            {
                if (v.SimRuntime != simulator_runtime)
                {
                    return(false);
                }

                if (!simulator_devicetypes.Contains(v.SimDeviceType))
                {
                    return(false);
                }

                if (target == AppRunnerTarget.Simulator_watchOS)
                {
                    return(AvailableDevicePairs.Any((SimDevicePair pair) => pair.Companion == v.UDID || pair.Gizmo == v.UDID));
                }

                return(true);
            });

            SimDevice candidate = null;

            foreach (var device in devices)
            {
                var data           = device;
                var secondaryData  = (SimDevice)null;
                var nodeCompanions = AvailableDevicePairs.Where((SimDevicePair v) => v.Companion == device.UDID);
                var nodeGizmos     = AvailableDevicePairs.Where((SimDevicePair v) => v.Gizmo == device.UDID);

                if (nodeCompanions.Any())
                {
                    var gizmo_udid = nodeCompanions.First().Gizmo;
                    var node       = AvailableDevices.Where((SimDevice v) => v.UDID == gizmo_udid);
                    secondaryData = node.First();
                }
                else if (nodeGizmos.Any())
                {
                    var companion_udid = nodeGizmos.First().Companion;
                    var node           = AvailableDevices.Where((SimDevice v) => v.UDID == companion_udid);
                    secondaryData = node.First();
                }
                if (secondaryData != null)
                {
                    simulators = new SimDevice [] { data, secondaryData };
                    break;
                }
                else
                {
                    candidate = data;
                }
            }

            if (simulators == null && candidate == null && target == AppRunnerTarget.Simulator_watchOS)
            {
                // We might be only missing device pairs to match phone + watch.
                var watchDevices     = AvailableDevices.Where((SimDevice v) => { return(v.SimRuntime == simulator_runtime && simulator_devicetypes.Contains(v.SimDeviceType)); });
                var companionDevices = AvailableDevices.Where((SimDevice v) => { return(v.SimRuntime == companion_runtime && companion_devicetypes.Contains(v.SimDeviceType)); });
                if (!watchDevices.Any() || !companionDevices.Any())
                {
                    log.WriteLine($"Could not find both watch devices for <runtime={simulator_runtime} and device type={string.Join (";", simulator_devicetypes)}> and companion device for <runtime={companion_runtime} and device type {string.Join (";", companion_devicetypes)}>");
                    return(null);
                }
                var watchDevice     = watchDevices.First();
                var companionDevice = companionDevices.First();

                log.WriteLine($"Creating device pair for '{watchDevice.Name}' and '{companionDevice.Name}'");
                var rv = await Harness.ExecuteXcodeCommandAsync("simctl", $"pair {watchDevice.UDID} {companionDevice.UDID}", log, TimeSpan.FromMinutes(1));

                if (!rv.Succeeded)
                {
                    log.WriteLine($"Could not create device pair, so could not find simulator for runtime={simulator_runtime} and device type={string.Join ("; ", simulator_devicetypes)}.");
                    return(null);
                }
                available_device_pairs.Add(new SimDevicePair()
                {
                    Companion = companionDevice.UDID,
                    Gizmo     = watchDevice.UDID,
                    UDID      = $"<created for {companionDevice.UDID} and {watchDevice.UDID}",
                });
                simulators = new SimDevice [] { watchDevice, companionDevice };
            }

            if (simulators == null)
            {
                if (candidate == null)
                {
                    log.WriteLine($"Could not find simulator for runtime={simulator_runtime} and device type={string.Join (";", simulator_devicetypes)}.");
                    return(null);
                }
                simulators = new SimDevice [] { candidate };
            }

            if (simulators == null)
            {
                log.WriteLine("Could not find simulator");
                return(null);
            }

            log.WriteLine("Found simulator: {0} {1}", simulators [0].Name, simulators [0].UDID);
            if (simulators.Length > 1)
            {
                log.WriteLine("Found companion simulator: {0} {1}", simulators [1].Name, simulators [1].UDID);
            }

            return(simulators);
        }
Esempio n. 6
0
        public async Task <SimDevice []> FindAsync(AppRunnerTarget target, Log log, bool create_if_needed = true)
        {
            SimDevice [] simulators = null;

            string simulator_devicetype;
            string simulator_runtime;
            string companion_devicetype = null;
            string companion_runtime    = null;

            switch (target)
            {
            case AppRunnerTarget.Simulator_iOS32:
                simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
                simulator_runtime    = "com.apple.CoreSimulator.SimRuntime.iOS-10-3";
                break;

            case AppRunnerTarget.Simulator_iOS64:
                simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-X";
                simulator_runtime    = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_iOS:
                simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
                simulator_runtime    = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_tvOS:
                simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p";
                simulator_runtime    = "com.apple.CoreSimulator.SimRuntime.tvOS-" + Xamarin.SdkVersions.TVOS.Replace('.', '-');
                break;

            case AppRunnerTarget.Simulator_watchOS:
                simulator_devicetype = "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-38mm";
                simulator_runtime    = "com.apple.CoreSimulator.SimRuntime.watchOS-" + Xamarin.SdkVersions.WatchOS.Replace('.', '-');
                companion_devicetype = "com.apple.CoreSimulator.SimDeviceType.iPhone-X";
                companion_runtime    = "com.apple.CoreSimulator.SimRuntime.iOS-" + Xamarin.SdkVersions.iOS.Replace('.', '-');
                break;

            default:
                throw new Exception(string.Format("Unknown simulator target: {0}", target));
            }

            var devices = await FindOrCreateDevicesAsync(log, simulator_runtime, simulator_devicetype);

            var companion_devices = await FindOrCreateDevicesAsync(log, companion_runtime, companion_devicetype);

            if (devices?.Any() != true)
            {
                log.WriteLine($"Could not find or create devices runtime={simulator_runtime} and device type={simulator_devicetype}.");
                return(null);
            }

            if (companion_runtime == null)
            {
                simulators = new SimDevice [] { devices.First() };
            }
            else
            {
                if (companion_devices?.Any() != true)
                {
                    log.WriteLine($"Could not find or create companion devices runtime={companion_runtime} and device type={companion_devicetype}.");
                    return(null);
                }

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

                if (pair == null)
                {
                    log.WriteLine($"Could not find or create device pair runtime={companion_runtime} and device type={companion_devicetype}.");
                    return(null);
                }

                simulators = new SimDevice [] {
                    devices.First((v) => v.UDID == pair.Gizmo),
                    companion_devices.First((v) => v.UDID == pair.Companion),
                };
            }

            if (simulators == null)
            {
                log.WriteLine($"Could not find simulator for runtime={simulator_runtime} and device type={simulator_devicetype}.");
                return(null);
            }

            log.WriteLine("Found simulator: {0} {1}", simulators [0].Name, simulators [0].UDID);
            if (simulators.Length > 1)
            {
                log.WriteLine("Found companion simulator: {0} {1}", simulators [1].Name, simulators [1].UDID);
            }

            return(simulators);
        }