Exemplo n.º 1
0
        public IEnumerator <RunTestTask> GetEnumerator()
        {
            foreach (var project in jenkins.Harness.MacTestProjects)
            {
                bool ignored = !jenkins.IncludeMac;
                if (project.Ignore == true)
                {
                    ignored = true;
                }

                if (!jenkins.IncludeMmpTest && project.Path.Contains("mmptest"))
                {
                    ignored = true;
                }

                if (!jenkins.IsIncluded(project))
                {
                    ignored = true;
                }

                var configurations = project.Configurations;
                if (configurations == null)
                {
                    configurations = new string [] { "Debug" }
                }
                ;

                TestPlatform platform = project.TargetFrameworkFlavors.ToTestPlatform();
                foreach (var config in configurations)
                {
                    MSBuildTask build = new MSBuildTask(jenkins: jenkins, testProject: project, processManager: processManager);
                    build.Platform = platform;
                    build.CloneTestProject(jenkins.MainLog, processManager, project, HarnessConfiguration.RootDirectory);
                    build.ProjectConfiguration = config;
                    build.ProjectPlatform      = project.Platform;
                    build.SpecifyPlatform      = false;
                    build.SpecifyConfiguration = build.ProjectConfiguration != "Debug";
                    build.Dependency           = project.Dependency;

                    var ignored_main = ignored;
                    var execs        = project.IsNUnitProject
                                                ? (IEnumerable <RunTestTask>) new [] { CreateNUnitTask(project, build, ignored_main) }
                                                : CreateMacExecuteTask(project, build, ignored_main);

                    foreach (var e in execs)
                    {
                        e.Variation = string.IsNullOrEmpty(e.Variation) ? config : e.Variation;
                        yield return(e);
                    }
                }
            }
        }

        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }
Exemplo n.º 2
0
        public Task <IEnumerable <ITestTask> > CreateAsync(Jenkins jenkins, IProcessManager processManager, TestVariationsFactory testVariationsFactory)
        {
            var rv           = new List <RunDeviceTask> ();
            var projectTasks = new List <RunDeviceTask> ();

            foreach (var project in jenkins.Harness.IOSTestProjects)
            {
                if (!project.IsExecutableProject)
                {
                    continue;
                }

                if (project.SkipDeviceVariations)
                {
                    continue;
                }

                bool ignored = !jenkins.IncludeDevice;
                if (!jenkins.IsIncluded(project))
                {
                    ignored = true;
                }

                projectTasks.Clear();

                bool createiOS;
                bool createTodayExtension;
                bool createtvOS;
                bool createwatchOS;

                if (project.GenerateVariations)
                {
                    createiOS            = !project.SkipiOSVariation;
                    createTodayExtension = !project.SkipTodayExtensionVariation;
                    createtvOS           = !project.SkiptvOSVariation;
                    createwatchOS        = !project.SkipwatchOSVariation;
                }
                else
                {
                    createiOS            = project.TestPlatform == TestPlatform.iOS_Unified;
                    createTodayExtension = project.TestPlatform == TestPlatform.iOS_TodayExtension64;
                    createtvOS           = project.TestPlatform == TestPlatform.tvOS;
                    createwatchOS        = project.TestPlatform == TestPlatform.watchOS;
                }

                if (createiOS)
                {
                    var build64 = new MSBuildTask(jenkins: jenkins, testProject: project, processManager: processManager)
                    {
                        ProjectConfiguration = "Debug64",
                        ProjectPlatform      = "iPhone",
                        Platform             = TestPlatform.iOS_Unified64,
                        TestName             = project.Name,
                    };
                    build64.CloneTestProject(jenkins.MainLog, processManager, project);
                    projectTasks.Add(new RunDeviceTask(
                                         jenkins: jenkins,
                                         devices: jenkins.Devices,
                                         buildTask: build64,
                                         processManager: processManager,
                                         tunnelBore: jenkins.TunnelBore,
                                         errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                         useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                         candidates: jenkins.Devices.Connected64BitIOS.Where(d => project.IsSupported(d.DevicePlatform, d.ProductVersion)))
                    {
                        Ignored = !jenkins.IncludeiOS64
                    });

                    var build32 = new MSBuildTask(jenkins: jenkins, testProject: project, processManager: processManager)
                    {
                        ProjectConfiguration = project.Name != "dont link" ? "Debug32" : "Release32",
                        ProjectPlatform      = "iPhone",
                        Platform             = TestPlatform.iOS_Unified32,
                        TestName             = project.Name,
                    };
                    build32.CloneTestProject(jenkins.MainLog, processManager, project);
                    projectTasks.Add(new RunDeviceTask(
                                         jenkins: jenkins,
                                         devices: jenkins.Devices,
                                         buildTask: build32,
                                         processManager: processManager,
                                         tunnelBore: jenkins.TunnelBore,
                                         errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                         useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                         candidates: jenkins.Devices.Connected32BitIOS.Where(d => project.IsSupported(d.DevicePlatform, d.ProductVersion)))
                    {
                        Ignored = !jenkins.IncludeiOS32
                    });

                    if (createTodayExtension)
                    {
                        var todayProject = project.GenerateVariations ? project.AsTodayExtensionProject() : project;
                        var buildToday   = new MSBuildTask(jenkins: jenkins, testProject: todayProject, processManager: processManager)
                        {
                            ProjectConfiguration = "Debug64",
                            ProjectPlatform      = "iPhone",
                            Platform             = TestPlatform.iOS_TodayExtension64,
                            TestName             = project.Name,
                        };
                        buildToday.CloneTestProject(jenkins.MainLog, processManager, todayProject);
                        projectTasks.Add(new RunDeviceTask(
                                             jenkins: jenkins,
                                             devices: jenkins.Devices,
                                             buildTask: buildToday,
                                             processManager: processManager,
                                             tunnelBore: jenkins.TunnelBore,
                                             errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                             useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                             candidates: jenkins.Devices.Connected64BitIOS.Where(d => project.IsSupported(d.DevicePlatform, d.ProductVersion)))
                        {
                            Ignored = !jenkins.IncludeiOSExtensions, BuildOnly = jenkins.ForceExtensionBuildOnly
                        });
                    }
                }

                if (createtvOS)
                {
                    var tvOSProject = project.GenerateVariations ? project.AsTvOSProject() : project;
                    var buildTV     = new MSBuildTask(jenkins: jenkins, testProject: tvOSProject, processManager: processManager)
                    {
                        ProjectConfiguration = "Debug",
                        ProjectPlatform      = "iPhone",
                        Platform             = TestPlatform.tvOS,
                        TestName             = project.Name,
                    };
                    buildTV.CloneTestProject(jenkins.MainLog, processManager, tvOSProject);
                    projectTasks.Add(new RunDeviceTask(
                                         jenkins: jenkins,
                                         devices: jenkins.Devices,
                                         buildTask: buildTV,
                                         processManager: processManager,
                                         tunnelBore: jenkins.TunnelBore,
                                         errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                         useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                         candidates: jenkins.Devices.ConnectedTV.Where(d => project.IsSupported(d.DevicePlatform, d.ProductVersion)))
                    {
                        Ignored = !jenkins.IncludetvOS
                    });
                }

                if (createwatchOS)
                {
                    var watchOSProject = project.GenerateVariations ? project.AsWatchOSProject() : project;
                    if (!project.SkipwatchOS32Variation)
                    {
                        var buildWatch32 = new MSBuildTask(jenkins: jenkins, testProject: watchOSProject, processManager: processManager)
                        {
                            ProjectConfiguration = "Debug32",
                            ProjectPlatform      = "iPhone",
                            Platform             = TestPlatform.watchOS_32,
                            TestName             = project.Name,
                        };
                        buildWatch32.CloneTestProject(jenkins.MainLog, processManager, watchOSProject);
                        projectTasks.Add(new RunDeviceTask(
                                             jenkins: jenkins,
                                             devices: jenkins.Devices,
                                             buildTask: buildWatch32,
                                             processManager: processManager,
                                             tunnelBore: jenkins.TunnelBore,
                                             errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                             useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                             candidates: jenkins.Devices.ConnectedWatch)
                        {
                            Ignored = !jenkins.IncludewatchOS
                        });
                    }

                    if (!project.SkipwatchOSARM64_32Variation)
                    {
                        var buildWatch64_32 = new MSBuildTask(jenkins: jenkins, testProject: watchOSProject, processManager: processManager)
                        {
                            ProjectConfiguration = "Release64_32",                             // We don't support Debug for ARM64_32 yet.
                            ProjectPlatform      = "iPhone",
                            Platform             = TestPlatform.watchOS_64_32,
                            TestName             = project.Name,
                        };
                        buildWatch64_32.CloneTestProject(jenkins.MainLog, processManager, watchOSProject);
                        projectTasks.Add(new RunDeviceTask(
                                             jenkins: jenkins,
                                             devices: jenkins.Devices,
                                             buildTask: buildWatch64_32,
                                             processManager: processManager,
                                             tunnelBore: jenkins.TunnelBore,
                                             errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                             useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                             candidates: jenkins.Devices.ConnectedWatch32_64.Where(d => project.IsSupported(d.DevicePlatform, d.ProductVersion)))
                        {
                            Ignored = !jenkins.IncludewatchOS
                        });
                    }
                }
                foreach (var task in projectTasks)
                {
                    task.TimeoutMultiplier = project.TimeoutMultiplier;
                    task.BuildOnly        |= project.BuildOnly;
                    task.Ignored          |= ignored;
                }
                rv.AddRange(projectTasks);
            }

            return(Task.FromResult <IEnumerable <ITestTask> > (testVariationsFactory.CreateTestVariations(rv, (buildTask, test, candidates)
                                                                                                          => new RunDeviceTask(
                                                                                                              jenkins: jenkins,
                                                                                                              devices: jenkins.Devices,
                                                                                                              buildTask: buildTask,
                                                                                                              processManager: processManager,
                                                                                                              tunnelBore: jenkins.TunnelBore,
                                                                                                              errorKnowledgeBase: jenkins.ErrorKnowledgeBase,
                                                                                                              useTcpTunnel: jenkins.Harness.UseTcpTunnel,
                                                                                                              candidates: candidates?.Cast <IHardwareDevice> () ?? test.Candidates))));
        }
        public async Task <IEnumerable <ITestTask> > CreateAsync(Jenkins jenkins, IMlaunchProcessManager processManager, TestVariationsFactory testVariationsFactory)
        {
            var runSimulatorTasks = new List <RunSimulatorTask> ();

            foreach (var project in jenkins.Harness.IOSTestProjects)
            {
                if (!project.IsExecutableProject)
                {
                    continue;
                }

                bool ignored = project.Ignore ?? !jenkins.IncludeSimulator;
                if (!jenkins.IsIncluded(project))
                {
                    ignored = true;
                }

                var ps = new List <Tuple <TestProject, TestPlatform, bool> > ();
                if (!project.GenerateVariations)
                {
                    ps.Add(new Tuple <TestProject, TestPlatform, bool> (project, project.TestPlatform, ignored));
                }
                else
                {
                    if (!project.SkipiOSVariation)
                    {
                        ps.Add(new Tuple <TestProject, TestPlatform, bool> (project, TestPlatform.iOS_Unified, ignored));
                    }
                    if (project.MonoNativeInfo != null)
                    {
                        ps.Add(new Tuple <TestProject, TestPlatform, bool> (project, TestPlatform.iOS_TodayExtension64, ignored));
                    }
                    if (!project.SkiptvOSVariation)
                    {
                        ps.Add(new Tuple <TestProject, TestPlatform, bool> (project.AsTvOSProject(), TestPlatform.tvOS, ignored));
                    }
                    if (!project.SkipwatchOSVariation)
                    {
                        ps.Add(new Tuple <TestProject, TestPlatform, bool> (project.AsWatchOSProject(), TestPlatform.watchOS, ignored));
                    }
                }

                var configurations = project.Configurations;
                if (configurations == null)
                {
                    configurations = new string [] { "Debug" }
                }
                ;
                foreach (var config in configurations)
                {
                    foreach (var pair in ps)
                    {
                        var configIgnored = pair.Item3;
                        var testPlatform  = pair.Item2;
                        switch (testPlatform)
                        {
                        case TestPlatform.iOS_Unified:
                        case TestPlatform.iOS_TodayExtension64:
                            configIgnored |= !jenkins.IncludeiOS64;
                            break;

                        case TestPlatform.tvOS:
                            configIgnored |= !jenkins.IncludetvOS;
                            break;

                        case TestPlatform.watchOS:
                            configIgnored |= !jenkins.IncludewatchOS;
                            break;

                        default:
                            Console.WriteLine("Unknown test platform for ignore check: {0}", testPlatform);
                            break;
                        }

                        configIgnored |= project.IsDotNetProject && !jenkins.IncludeDotNet;

                        var derived = new MSBuildTask(jenkins: jenkins, testProject: project, processManager: processManager);
                        derived.ProjectConfiguration = config;
                        derived.ProjectPlatform      = "iPhoneSimulator";
                        derived.Platform             = testPlatform;
                        derived.Ignored    = configIgnored;
                        derived.TestName   = project.Name;
                        derived.Dependency = project.Dependency;
                        derived.CloneTestProject(jenkins.MainLog, processManager, pair.Item1, HarnessConfiguration.RootDirectory);
                        var simTasks = CreateAsync(jenkins, processManager, derived);
                        runSimulatorTasks.AddRange(simTasks);
                        foreach (var task in simTasks)
                        {
                            if (configurations.Length > 1)
                            {
                                task.Variation = config;
                            }
                            task.TimeoutMultiplier = project.TimeoutMultiplier;
                        }
                    }
                }
            }

            var testVariations = testVariationsFactory.CreateTestVariations(runSimulatorTasks, (buildTask, test, candidates) =>
                                                                            new RunSimulatorTask(
                                                                                jenkins: jenkins,
                                                                                simulators: jenkins.Simulators,
                                                                                buildTask: buildTask,
                                                                                processManager: processManager,
                                                                                candidates: candidates?.Cast <SimulatorDevice> () ?? test.Candidates)).ToList();

            if (jenkins.IsServerMode)
            {
                return(testVariations);
            }

            foreach (var tv in testVariations)
            {
                if (!tv.Ignored)
                {
                    await tv.FindSimulatorAsync();
                }
            }

            var rv = new List <AggregatedRunSimulatorTask> ();

            foreach (var taskGroup in testVariations.GroupBy((RunSimulatorTask task) => task.Device?.UDID ?? task.Candidates.ToString()))
            {
                rv.Add(new AggregatedRunSimulatorTask(jenkins: jenkins, tasks: taskGroup)
                {
                    TestName = $"Tests for {taskGroup.Key}",
                });
            }
            return(rv);
        }

        IEnumerable <RunSimulatorTask> CreateAsync(Jenkins jenkins, IMlaunchProcessManager processManager, MSBuildTask buildTask)
        {
            var runtasks = new List <RunSimulatorTask> ();

            TestTarget []   targets = buildTask.Platform.GetAppRunnerTargets();
            TestPlatform [] platforms;
            bool []         ignored;

            switch (buildTask.Platform)
            {
            case TestPlatform.tvOS:
                platforms = new TestPlatform [] { TestPlatform.tvOS };
                ignored   = new [] { false };
                break;

            case TestPlatform.watchOS:
                platforms = new TestPlatform [] { TestPlatform.watchOS_32 };
                ignored   = new [] { false };
                break;

            case TestPlatform.iOS_Unified:
                platforms = new TestPlatform [] { TestPlatform.iOS_Unified64 };
                ignored   = new [] { false };
                break;

            case TestPlatform.iOS_TodayExtension64:
                platforms = new TestPlatform [] { TestPlatform.iOS_TodayExtension64 };
                ignored   = new [] { false };
                break;

            default:
                throw new NotImplementedException();
            }

            for (int i = 0; i < targets.Length; i++)
            {
                var sims = jenkins.Simulators.SelectDevices(targets [i], jenkins.SimulatorLoadLog, false);
                runtasks.Add(new RunSimulatorTask(
                                 jenkins: jenkins,
                                 simulators: jenkins.Simulators,
                                 buildTask: buildTask,
                                 processManager: processManager,
                                 candidates: sims)
                {
                    Platform = platforms [i],
                    Ignored  = ignored [i] || buildTask.Ignored
                });
            }

            return(runtasks);
        }
    }