Ejemplo n.º 1
0
        protected void SetupCscBinDir(string sdkDirPath, string runtimeVersion, string intermediateOutputDir, bool useExistingSetup, ITestOutputHelper output)
        {
            // copy the SDK version of csc into a private directory so we can safely retarget it
            string cscBinaryDirPath = Path.Combine(sdkDirPath, "Roslyn", "bincore");
            string localCscDir      = Path.Combine(intermediateOutputDir, "csc");

            ExePath = Path.Combine(localCscDir, "csc.dll");

            if (useExistingSetup)
            {
                return;
            }

            FileTasks.DirectoryCopy(cscBinaryDirPath, localCscDir, output);
            //overwrite csc.runtimeconfig.json to point at the runtime version we want to use
            string runtimeConfigPath = Path.Combine(localCscDir, "csc.runtimeconfig.json");

            File.Delete(runtimeConfigPath);
            File.WriteAllLines(runtimeConfigPath, new string[] {
                "{",
                "  \"runtimeOptions\": {",
                "    \"tfm\": \"netcoreapp2.0\",",
                "    \"framework\": {",
                "        \"name\": \"Microsoft.NETCore.App\",",
                "        \"version\": \"" + runtimeVersion + "\"",
                "    }",
                "  }",
                "}"
            });
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task SetupSourceToCompile(string intermediateOutputDir, string runtimeDirPath, bool useExistingSetup, ITestOutputHelper output)
#pragma warning restore CS1998
        {
            string helloWorldDir            = Path.Combine(intermediateOutputDir, "helloWorldSource");
            string helloWorldPath           = Path.Combine(helloWorldDir, "hello.cs");
            string systemPrivateCoreLibPath = Path.Combine(runtimeDirPath, "System.Private.CoreLib.dll");
            string systemRuntimePath        = Path.Combine(runtimeDirPath, "System.Runtime.dll");
            string systemConsolePath        = Path.Combine(runtimeDirPath, "System.Console.dll");

            CommandLineArguments = "hello.cs /nostdlib /r:" + systemPrivateCoreLibPath + " /r:" + systemRuntimePath + " /r:" + systemConsolePath;
            WorkingDirPath       = helloWorldDir;
            if (useExistingSetup)
            {
                return;
            }

            FileTasks.DeleteDirectory(helloWorldDir, output);
            FileTasks.CreateDirectory(helloWorldDir, output);
            File.WriteAllLines(helloWorldPath, new string[]
            {
                "using System;",
                "public static class Program",
                "{",
                "    public static void Main(string[] args)",
                "    {",
                "        Console.WriteLine(\"Hello World!\");",
                "    }",
                "}"
            });
        }
Ejemplo n.º 3
0
        protected async Task SetupHelloWorldProject(string dotNetExePath, string intermediateOutputDir, bool useExistingSetup, ITestOutputHelper output)
        {
            string helloWorldProjectDir = Path.Combine(intermediateOutputDir, "helloworld");

            //the 'exePath' gets passed as an argument to dotnet.exe
            //in this case it isn't an executable at all, its a CLI command
            //a little cheap, but it works
            ExePath        = "build";
            WorkingDirPath = helloWorldProjectDir;

            // This disables using the shared build server. I was told using it interferes with the ability to delete folders after the
            // test is complete though I haven't encountered that particular issue myself. I imagine this meaningfully changes the
            // performance of this benchmark, so if we ever want to do real perf testing on the shared scenario we have to resolve this
            // issue another way.
            EnvironmentVariables["UseSharedCompilation"] = "false";

            if (!useExistingSetup)
            {
                FileTasks.DeleteDirectory(helloWorldProjectDir, output);
                FileTasks.CreateDirectory(helloWorldProjectDir, output);
                await new ProcessRunner(dotNetExePath, "new console")
                .WithWorkingDirectory(helloWorldProjectDir)
                .WithLog(output)
                .Run();
            }
        }
Ejemplo n.º 4
0
        private async Task <string> Publish(DotNetInstallation dotNetInstall, string outputDir, ITestOutputHelper output)
        {
            string tfm        = DotNetSetup.GetTargetFrameworkMonikerForFrameworkVersion(dotNetInstall.FrameworkVersion);
            string publishDir = GetWord2VecNetPublishDirectory(dotNetInstall, outputDir, tfm);

            if (publishDir != null)
            {
                FileTasks.DeleteDirectory(publishDir, output);
            }
            string dotNetExePath = dotNetInstall.DotNetExe;

            await new ProcessRunner(dotNetExePath, $"publish -c Release -f {tfm}")
            .WithWorkingDirectory(GetWord2VecNetSrcDirectory(outputDir))
            .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0")
            .WithEnvironmentVariable("WORD2VEC_FRAMEWORK_VERSION", dotNetInstall.FrameworkVersion)
            .WithEnvironmentVariable("UseSharedCompilation", "false")
            .WithLog(output)
            .Run();

            publishDir = GetWord2VecNetPublishDirectory(dotNetInstall, outputDir, tfm);
            if (publishDir == null)
            {
                throw new DirectoryNotFoundException("Could not find 'publish' directory");
            }
            return(publishDir);
        }
Ejemplo n.º 5
0
        async Task CloneWord2VecNetRepo(string outputDir, ITestOutputHelper output)
        {
            // If the repo already exists, we delete it and extract it again.
            string word2VecNetRepoRootDir = GetWord2VecNetRepoRootDir(outputDir);

            FileTasks.DeleteDirectory(word2VecNetRepoRootDir, output);

            await GitTasks.Clone(Word2VecNetRepoUrl, word2VecNetRepoRootDir, output);

            await GitTasks.Checkout(Word2VecNetCommitSha1Id, output, word2VecNetRepoRootDir);
        }
Ejemplo n.º 6
0
        async Task DownloadAndExtractTextCorpus(DotNetInstallation dotNetInstall, string outputDir, ITestOutputHelper output)
        {
            // If the file already exists, exit
            string word2VecNetRepoRootDir = GetWord2VecNetRepoRootDir(outputDir);
            string tfm = DotNetSetup.GetTargetFrameworkMonikerForFrameworkVersion(dotNetInstall.FrameworkVersion);
            string word2VecNetPublishDir = GetWord2VecNetPublishDirectory(dotNetInstall, outputDir, tfm);

            // Download the corpus of text. This is a zip file that contains a text file of 100M of text from Wikipedia
            var url = "https://perfbenchmarkstorage.blob.core.windows.net/corpus/Corpus10.zip";
            await FileTasks.DownloadAndUnzip(url, word2VecNetRepoRootDir + "_temp", output);

            FileTasks.MoveFile(Path.Combine(word2VecNetRepoRootDir + "_temp", "Corpus.txt"),
                               Path.Combine(word2VecNetPublishDir, "Corpus.txt"), output);
        }
        protected override async Task SetupSourceToCompile(string intermediateOutputDir, string runtimeDirPath, bool useExistingSetup, ITestOutputHelper output)
        {
            string cscSourceDownloadLink = "https://roslyninfra.blob.core.windows.net/perf-artifacts/CodeAnalysisRepro" +
                                           (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".zip" : ".tar.gz");
            string sourceDownloadDir = Path.Combine(intermediateOutputDir, "roslynSource");
            string sourceDir         = Path.Combine(sourceDownloadDir, "CodeAnalysisRepro");

            CommandLineArguments = "@repro.rsp";
            WorkingDirPath       = sourceDir;
            if (useExistingSetup)
            {
                return;
            }

            await FileTasks.DownloadAndUnzip(cscSourceDownloadLink, sourceDownloadDir, output);
        }
Ejemplo n.º 8
0
        public static async Task Unzip(string zipPath, string expandedDirPath, ITestOutputHelper output, bool deleteZippedFiles = true, string tempTarPath = null)
        {
            if (zipPath.EndsWith(".zip"))
            {
                await FileTasks.UnWinZip(zipPath, expandedDirPath, output);

                if (deleteZippedFiles)
                {
                    File.Delete(zipPath);
                }
            }
            else if (zipPath.EndsWith(".tar.gz"))
            {
                bool deleteTar = deleteZippedFiles;
                if (tempTarPath == null)
                {
                    string tempFileNameBase = Guid.NewGuid().ToString();
                    tempTarPath = Path.Combine(Path.GetTempPath(), tempFileNameBase + ".tar");
                    deleteTar   = true;
                }
                await UnGZip(zipPath, tempTarPath, output);
                await UnTar(tempTarPath, expandedDirPath, output);

                if (deleteZippedFiles)
                {
                    File.Delete(zipPath);
                }
                if (deleteTar)
                {
                    File.Delete(tempTarPath);
                }
            }
            else
            {
                output.WriteLine("Unsupported compression format: " + zipPath);
                throw new NotSupportedException("Unsupported compression format: " + zipPath);
            }
        }
Ejemplo n.º 9
0
        async public Task <DotNetInstallation> Run(ITestOutputHelper output)
        {
            using (var acquireOutput = new IndentedTestOutputHelper("Acquiring DotNet", output))
            {
                string remoteSdkPath = GetSDKDownloadLink();
                if (remoteSdkPath != null)
                {
                    await FileTasks.DownloadAndUnzip(remoteSdkPath, DotNetDirPath, acquireOutput);
                }
                string remoteRuntimePath = GetFrameworkDownloadLink();
                if (remoteRuntimePath != null)
                {
                    await FileTasks.DownloadAndUnzip(remoteRuntimePath, DotNetDirPath, acquireOutput);

                    // the SDK may have included another runtime version, but to help prevent mistakes
                    // where a test might run against a different version than we intended all other
                    // versions will be deleted.
                    string mnappDirPath = Path.Combine(DotNetDirPath, "shared", "Microsoft.NETCore.App");
                    foreach (string dir in Directory.GetDirectories(mnappDirPath))
                    {
                        string versionDir = Path.GetFileName(dir);
                        if (versionDir != FrameworkVersion)
                        {
                            FileTasks.DeleteDirectory(dir, acquireOutput);
                        }
                    }
                }
                string actualFrameworkVersion = FrameworkVersion;
                if (actualFrameworkVersion == null)
                {
                    //if Framework version is being infered from an SDK then snoop the filesystem to see what got installed
                    foreach (string dirPath in Directory.EnumerateDirectories(Path.Combine(DotNetDirPath, "shared", "Microsoft.NETCore.App")))
                    {
                        actualFrameworkVersion = Path.GetFileName(dirPath);
                        break;
                    }
                }


                DotNetInstallation result = new DotNetInstallation(DotNetDirPath, actualFrameworkVersion, SdkVersion, Architecture);
                acquireOutput.WriteLine("Dotnet path: " + result.DotNetExe);
                if (!File.Exists(result.DotNetExe))
                {
                    throw new FileNotFoundException(result.DotNetExe + " not found");
                }
                if (result.SdkVersion != null)
                {
                    if (!Directory.Exists(result.SdkDir))
                    {
                        throw new DirectoryNotFoundException("Sdk directory " + result.SdkDir + " not found");
                    }
                }
                if (result.FrameworkVersion != null)
                {
                    if (!Directory.Exists(result.FrameworkDir))
                    {
                        throw new DirectoryNotFoundException("Framework directory " + result.FrameworkDir + " not found");
                    }

                    //overlay private binaries if needed
                    if (PrivateRuntimeBinaryDirPath != null)
                    {
                        foreach (string fileName in GetPrivateRuntimeOverlayBinaryNames(OS))
                        {
                            string backupPath     = Path.Combine(result.FrameworkDir, fileName + ".original");
                            string overwritePath  = Path.Combine(result.FrameworkDir, fileName);
                            string privateBinPath = Path.Combine(PrivateRuntimeBinaryDirPath, fileName);
                            if (!File.Exists(backupPath))
                            {
                                File.Copy(overwritePath, backupPath);
                            }
                            if (!File.Exists(privateBinPath))
                            {
                                throw new FileNotFoundException("Private binary " + privateBinPath + " not found");
                            }
                            File.Copy(privateBinPath, overwritePath, true);
                        }
                    }
                }
                return(result);
            }
        }