Exemple #1
0
        private void TestProjectFromPerfTestSourceRepository(
            ProjectPerfOperation operation,
            string testName,
            string solutionDirectoryNameInPerfTestRepo,
            string projectDirectoryName = null)
        {
            string sourceProject = Path.Combine(
                TestContext.GetRepoRoot(),
                $".perftestsource/PerformanceTestProjects/{solutionDirectoryNameInPerfTestRepo}");

            var testDir = _testAssetsManager.CreateTestDirectory(
                solutionDirectoryNameInPerfTestRepo,
                identifier: operation.ToString());

            Console.WriteLine($"Mirroring {sourceProject} to {testDir}...");
            FolderSnapshot.MirrorFiles(sourceProject, testDir.Path);
            TestContext.Current.WriteGlobalJson(testDir.Path);
            Console.WriteLine("Done");

            string projectFolderOrFile =
                projectDirectoryName != null
                ? Path.Combine(testDir.Path, projectDirectoryName)
                : testDir.Path;

            TestProject(projectFolderOrFile, testName, operation);
        }
Exemple #2
0
        public void BuildProjectFromPerfSuite(string name, ProjectPerfOperation operation)
        {
            string sourceProject = Path.Combine(@"C:\MSBPerf\3", name);
            var    testDir       = _testAssetsManager.CreateTestDirectory("Perf_" + name, identifier: operation.ToString());

            FolderSnapshot.MirrorFiles(sourceProject, testDir.Path);

            //  The generated projects target .NET Core 2.1, retarget them to .NET Core 2.0
            foreach (var projFile in Directory.GetFiles(testDir.Path, "*.csproj", SearchOption.AllDirectories))
            {
                var project = XDocument.Load(projFile);
                var ns      = project.Root.Name.Namespace;

                //  Find both TargetFramework and TargetFrameworks elements
                var targetFrameworkElements = project.Root.Elements(ns + "PropertyGroup").Elements("TargetFramework");
                targetFrameworkElements = targetFrameworkElements.Concat(project.Root.Elements(ns + "PropertyGroup").Elements("TargetFrameworks"));

                foreach (var tfElement in targetFrameworkElements)
                {
                    tfElement.Value = tfElement.Value.Replace("netcoreapp2.1", "netcoreapp2.0");
                }

                project.Save(projFile);
            }

            TestProject(testDir.Path, name, operation);
        }
Exemple #3
0
        public void BuildRoslynCompilers(ProjectPerfOperation operation)
        {
            string sourceProject = @"C:\git\roslyn";
            var    testDir       = _testAssetsManager.CreateTestDirectory("Perf_Roslyn", identifier: operation.ToString());

            Console.WriteLine($"Mirroring {sourceProject} to {testDir.Path}...");
            FolderSnapshot.MirrorFiles(sourceProject, testDir.Path);
            TestContext.Current.WriteGlobalJson(testDir.Path);
            Console.WriteLine("Done");

            //  Override global.json from repo
            File.Delete(Path.Combine(testDir.Path, "global.json"));

            //  Run Roslyn's restore script
            var restoreCmd = new SdkCommandSpec()
            {
                FileName         = Path.Combine(testDir.Path, "Restore.cmd"),
                WorkingDirectory = testDir.Path
            };

            TestContext.Current.AddTestEnvironmentVariables(restoreCmd);
            restoreCmd.ToCommand().Execute().Should().Pass();

            TestProject(Path.Combine(testDir.Path, "Compilers.sln"), "Roslyn", operation);
        }
Exemple #4
0
 public void BuildNetFullFrameworkWindowsFormsLarge(ProjectPerfOperation operation)
 {
     TestProjectFromPerfTestSourceRepository(
         operation: operation,
         testName: "Build Full framework Windows Forms large",
         solutionDirectoryNameInPerfTestRepo: "WinformsNetFrameworkPerfApp1");
 }
Exemple #5
0
        public void BuildNetFullFrameworkWindowsFormsHelloWorld(ProjectPerfOperation operation)
        {
            var testAsset = _testAssetsManager
                            .CopyTestAsset("WindowsFormsHelloWorldFullFramework", identifier: operation.ToString())
                            .WithSource();

            TestProject(testAsset.Path, "Full Windows Forms hello world", operation);
        }
Exemple #6
0
 public void BuildWebLarge30(ProjectPerfOperation operation)
 {
     TestProjectFromPerfTestSourceRepository(
         operation: operation,
         testName: "Build Web Large 3.0",
         solutionDirectoryNameInPerfTestRepo: "WebLarge30",
         projectDirectoryName: "mvc");
 }
Exemple #7
0
 public void BuildNetFullFrameworkWpfLarge(ProjectPerfOperation operation)
 {
     TestProjectFromPerfTestSourceRepository(
         operation: operation,
         testName: "Build Full framework WPF large",
         solutionDirectoryNameInPerfTestRepo: "WpfLargeFullframework",
         projectDirectoryName: "WpfLargeFullframework");
 }
Exemple #8
0
 public void BuildNetCoreWpfLarge(ProjectPerfOperation operation)
 {
     TestProjectFromPerfTestSourceRepository(
         operation: operation,
         testName: "Build WPF large",
         solutionDirectoryNameInPerfTestRepo: "WpfLarge",
         projectDirectoryName: "WpfLarge");
 }
Exemple #9
0
        public void BuildWebLarge30(ProjectPerfOperation operation)
        {
            string sourceProject = Path.Combine(TestContext.GetRepoRoot(), ".perftestsource/PerformanceTestProjects/WebLarge30");
            var    testDir       = _testAssetsManager.CreateTestDirectory("WebLarge30", identifier: operation.ToString());

            Console.WriteLine($"Mirroring {sourceProject} to {testDir}...");
            FolderSnapshot.MirrorFiles(sourceProject, testDir.Path);
            Console.WriteLine("Done");

            TestProject(Path.Combine(testDir.Path, "mvc"), "Build Web Large 3.0", operation);
        }
Exemple #10
0
        public void BuildMVCApp(ProjectPerfOperation operation)
        {
            var testDir    = _testAssetsManager.CreateTestDirectory(identifier: operation.ToString());
            var newCommand = new DotnetCommand(Log);

            newCommand.WorkingDirectory = testDir.Path;

            newCommand.Execute("new", "mvc", "--no-restore").Should().Pass();

            TestProject(testDir.Path, "ASP.NET Core MVC app", operation, "https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;https://api.nuget.org/v3/index.json");
        }
Exemple #11
0
        public void BuildNetStandard2Library(ProjectPerfOperation operation)
        {
            var testProject = new TestProject()
            {
                Name             = "NetCoreApp",
                TargetFrameworks = "netstandard2.0",
                IsSdkProject     = true
            };

            var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: operation.ToString());

            TestProject(testAsset.Path, ".NET Standard 2.0 Library", operation);
        }
Exemple #12
0
        public void BuildMVCApp(ProjectPerfOperation operation)
        {
            var testDir = _testAssetsManager.CreateTestDirectory(identifier: operation.ToString());

            NuGetConfigWriter.Write(testDir.Path, NuGetConfigWriter.AspNetCoreDevFeed);

            var newCommand = new DotnetCommand(Log);

            newCommand.WorkingDirectory = testDir.Path;

            newCommand.Execute("new", "mvc", "--no-restore").Should().Pass();

            TestProject(testDir.Path, "ASP.NET Core MVC app", operation);
        }
Exemple #13
0
        public void BuildNetCore2App(ProjectPerfOperation operation)
        {
            var testProject = new TestProject()
            {
                Name             = "NetCoreApp",
                TargetFrameworks = "netcoreapp2.0",
                IsSdkProject     = true,
                IsExe            = true
            };

            var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: operation.ToString());

            TestProject(testAsset.Path, ".NET Core 2 Console App", operation);
        }
Exemple #14
0
        public void BuildNetCoreWindowsFormsHelloWorld(ProjectPerfOperation operation)
        {
            var testDir = _testAssetsManager.CreateTestDirectory(identifier: operation.ToString());

            NuGetConfigWriter.Write(testDir.Path, NuGetConfigWriter.DotnetCoreBlobFeed);

            var newCommand = new DotnetCommand(Log);

            newCommand.WorkingDirectory = testDir.Path;

            newCommand.Execute("new", "winforms", "--no-restore").Should().Pass();

            TestProject(testDir.Path, "Windows Forms hello world", operation);
        }
Exemple #15
0
        private void TestProject(string projectFolderOrFile, string testName, ProjectPerfOperation perfOperation, string restoreSources = null)
        {
            string testProjectPath;
            string testProjectDirectory;
            bool   projectFileSpecified;

            if (File.Exists(projectFolderOrFile))
            {
                projectFileSpecified = true;
                testProjectPath      = projectFolderOrFile;
                testProjectDirectory = Path.GetDirectoryName(projectFolderOrFile);
            }
            else
            {
                projectFileSpecified = false;
                testProjectPath      = Directory.GetFiles(projectFolderOrFile, "*.sln", SearchOption.AllDirectories).SingleOrDefault();
                if (testProjectPath == null)
                {
                    testProjectPath = Directory.GetFiles(projectFolderOrFile, "*.csproj", SearchOption.AllDirectories).SingleOrDefault();
                    if (testProjectPath == null)
                    {
                        throw new ArgumentException("Could not find project file to test in folder: " + projectFolderOrFile);
                    }
                }
                testProjectDirectory = Path.GetDirectoryName(testProjectPath);
            }

            TestCommand commandToTest;
            var         perfTest = new PerfTest();

            perfTest.ScenarioName = testName;

            if (perfOperation == ProjectPerfOperation.NoOpRestore)
            {
                TestCommand restoreCommand;

                if (TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild)
                {
                    restoreCommand = new RestoreCommand(Log, testProjectPath);
                }
                else
                {
                    restoreCommand = new RestoreCommand(Log, testProjectPath);
                    restoreCommand = new DotnetCommand(Log, "restore");
                    if (projectFileSpecified)
                    {
                        restoreCommand.Arguments.Add(testProjectPath);
                    }
                }
                if (!string.IsNullOrEmpty(restoreSources))
                {
                    restoreCommand.Arguments.Add($"/p:RestoreSources={restoreSources}");
                }
                restoreCommand.WorkingDirectory = testProjectDirectory;

                restoreCommand.Execute().Should().Pass();

                commandToTest     = restoreCommand;
                perfTest.TestName = "Restore (No-op)";
            }
            else
            {
                if (TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild)
                {
                    commandToTest = new BuildCommand(Log, projectFileSpecified ? testProjectPath : testProjectDirectory);
                    commandToTest.Arguments.Add("/restore");
                }
                else
                {
                    commandToTest = new DotnetCommand(Log, "build");
                    if (projectFileSpecified)
                    {
                        commandToTest.Arguments.Add(testProjectPath);
                    }
                }
                if (!string.IsNullOrEmpty(restoreSources))
                {
                    commandToTest.Arguments.Add($"/p:RestoreSources={restoreSources}");
                }
                commandToTest.WorkingDirectory = testProjectDirectory;

                if (perfOperation == ProjectPerfOperation.CleanBuild)
                {
                    perfTest.TestName = "Build";
                }
                else if (perfOperation == ProjectPerfOperation.BuildWithNoChanges)
                {
                    //  Build once before taking folder snaspshot
                    commandToTest.Execute().Should().Pass();

                    perfTest.TestName = "Build (no changes)";
                }
                else
                {
                    throw new ArgumentException("Unexpected perf operation: " + perfOperation);
                }
            }

            perfTest.ProcessToMeasure = commandToTest.GetProcessStartInfo();
            perfTest.TestFolder       = testProjectDirectory;

            perfTest.Run();
        }