From: Egor Chesakov Date: Mon, 17 Dec 2018 19:11:25 +0000 (-0800) Subject: Switch to using resources in BenchmarksGames tests (dotnet/coreclr#21554) X-Git-Tag: submit/tizen/20210909.063632~11030^2~3054 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=641a28bf1d01373d58947cd03dfe4f1cf0bd5a54;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Switch to using resources in BenchmarksGames tests (dotnet/coreclr#21554) Embed the following test files as the resources in their corresponding test assemblies: * regexdna-input25.txt regexdna-input25000.txt in BenchmarksGame/regex-redux * knucleotide-input.txt knucleotide-input-big.txt in BenchmarksGame/k-nucleotide * revcomp-input25.txt revcomp-input25000.txt in BenchmarksGame/reverse-complement Commit migrated from https://github.com/dotnet/coreclr/commit/7c2d9aa7e35ab119eaf907514fa1ff765317ec11 --- diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/harness-helpers.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/harness-helpers.cs index d7b9a57..bae1698 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/harness-helpers.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/harness-helpers.cs @@ -7,96 +7,41 @@ using System; using System.IO; -using System.Text; +using System.Reflection; namespace BenchmarksGame { class TestHarnessHelpers { - public string InputFile; public int[] expectedCountLetter; public int[] expectedCountPairs; public int[] expectedCountFragments; public int[][] expectedFrequencies; + private readonly string resourceName; - public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "") + public TestHarnessHelpers(bool bigInput) { if (bigInput) { - InputFile = FindInputFile("knucleotide-input-big.txt", csFileName); expectedCountLetter = new int[] { 302923, 301375, 198136, 197566 }; expectedCountPairs = new int[] { 91779, 91253, 91225, 90837, 60096, 60030, 59889, 59795, 59756, 59713, 59572, 59557, 39203, 39190, 39081, 39023 }; expectedCountFragments = new int[] { 11765, 3572, 380, 7, 7 }; + resourceName = "knucleotide-input-big.txt"; } else { - InputFile = FindInputFile("knucleotide-input.txt", csFileName); expectedCountLetter = new int[] { 1576, 1480, 974, 970 }; expectedCountPairs = new int[] { 496, 480, 470, 420, 316, 315, 310, 302, 298, 292, 273, 272, 202, 201, 185, 167 }; expectedCountFragments = new int[] { 54, 24, 4, 0, 0 }; + resourceName = "knucleotide-input.txt"; } expectedFrequencies = new int[][] { expectedCountLetter, expectedCountPairs }; } - public string FindInputFile(string inputFile, string csFileName) + public Stream GetInputStream() { - string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT"); - - if (CoreRoot == null) - { - Console.WriteLine("This benchmark requries CORE_ROOT to be set"); - return null; - } - - // The convention is that the csproj file has the same name as the cs file. - string projectName = Path.GetFileNameWithoutExtension(csFileName); - int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' }); - if (slashIndex != -1) - { - // csFileName was generated by the C# compiler, which may have run on - // a different host system with different path separator than the - // currently executing host, which dictates GetFileNameWithoutExtension's - // behavior... so hope that the slash here is a cross-host path separator, - // and chop of what were likely direcotires. - projectName = projectName.Substring(slashIndex + 1); - } - - // Normal testing -- input file will end up next to the assembly - // and CoreRoot points at the test overlay dir - string[] pathPartsNormal = new string[] { - CoreRoot, "..", "..", "JIT", "Performance", - "CodeQuality", "BenchmarksGame", "k-nucleotide", projectName, inputFile - }; - - string inputPathNormal = Path.Combine(pathPartsNormal); - - // Perf testing -- input file will end up next to the assembly - // and CoreRoot points at this directory - string[] pathPartsPerf = new string[] { CoreRoot, inputFile }; - - string inputPathPerf = Path.Combine(pathPartsPerf); - - string inputPath = null; - - if (File.Exists(inputPathNormal)) - { - inputPath = inputPathNormal; - } - else if (File.Exists(inputPathPerf)) - { - inputPath = inputPathPerf; - } - - if (inputPath != null) - { - Console.WriteLine("Using input file {0}", inputFile); - } - else - { - throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}."); - } - - return inputPath; + var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly; + return assembly.GetManifestResourceStream(resourceName); } } } diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.cs index 96d49f7..449baa2 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.cs @@ -92,9 +92,9 @@ namespace BenchmarksGame { var helpers = new TestHarnessHelpers(bigInput: false); - using (var inputFile = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) { - if (!Bench(inputFile, helpers, true)) + if (!Bench(inputStream, helpers, true)) { return -1; } @@ -111,9 +111,9 @@ namespace BenchmarksGame Benchmark.Iterate(() => { - using (var inputFile = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) { - ok &= Bench(inputFile, helpers, false); + ok &= Bench(inputStream, helpers, false); } }); Assert.True(ok); diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.csproj index d65aaae..f796668 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-1.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + + diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.cs index e6dd212..0b787bf 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.cs @@ -291,7 +291,7 @@ namespace BenchmarksGame tonum['t'] = 3; tonum['T'] = 3; tonum['\n'] = 255; tonum['>'] = 255; tonum[255] = 255; - using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) { loadThreeData(inputStream); } diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.csproj index 9e72ba4..e9942d9 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/k-nucleotide/k-nucleotide-9.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + + diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/harness-helpers.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/harness-helpers.cs index 25627ba..5f8cd95 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/harness-helpers.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/harness-helpers.cs @@ -7,88 +7,33 @@ using System; using System.IO; -using System.Text; +using System.Reflection; namespace BenchmarksGame { class TestHarnessHelpers { - public string InputFile; - public int ExpectedLength; + public readonly int ExpectedLength; + private readonly string resourceName; - public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "") + public TestHarnessHelpers(bool bigInput) { if (bigInput) { - InputFile = FindInputFile("regexdna-input25000.txt", csFileName); ExpectedLength = 136381; + resourceName = "regexdna-input25000.txt"; } else { - InputFile = FindInputFile("regexdna-input25.txt", csFileName); ExpectedLength = 152; + resourceName = "regexdna-input25.txt"; } } - public string FindInputFile(string inputFile, string csFileName) + public Stream GetInputStream() { - string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT"); - - if (CoreRoot == null) - { - Console.WriteLine("This benchmark requries CORE_ROOT to be set"); - return null; - } - - // The convention is that the csproj file has the same name as the cs file. - string projectName = Path.GetFileNameWithoutExtension(csFileName); - int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' }); - if (slashIndex != -1) - { - // csFileName was generated by the C# compiler, which may have run on - // a different host system with different path separator than the - // currently executing host, which dictates GetFileNameWithoutExtension's - // behavior... so hope that the slash here is a cross-host path separator, - // and chop of what were likely direcotires. - projectName = projectName.Substring(slashIndex + 1); - } - - // Normal testing -- input file will end up next to the assembly - // and CoreRoot points at the test overlay dir - string[] pathPartsNormal = new string[] { - CoreRoot, "..", "..", "JIT", "Performance", - "CodeQuality", "BenchmarksGame", "regex-redux", projectName, inputFile - }; - - string inputPathNormal = Path.Combine(pathPartsNormal); - - // Perf testing -- input file will end up next to the assembly - // and CoreRoot points at this directory - string[] pathPartsPerf = new string[] { CoreRoot, inputFile }; - - string inputPathPerf = Path.Combine(pathPartsPerf); - - string inputPath = null; - - if (File.Exists(inputPathNormal)) - { - inputPath = inputPathNormal; - } - else if (File.Exists(inputPathPerf)) - { - inputPath = inputPathPerf; - } - - if (inputPath != null) - { - Console.WriteLine("Using input file {0}", inputFile); - } - else - { - throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}."); - } - - return inputPath; + var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly; + return assembly.GetManifestResourceStream(resourceName); } } } diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.cs index 7301002..12c3529 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.cs @@ -31,7 +31,7 @@ namespace BenchmarksGame { var helpers = new TestHarnessHelpers(bigInput: false); - using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) using (var input = new StreamReader(inputStream)) { if (Bench(input, true) != helpers.ExpectedLength) @@ -50,7 +50,7 @@ namespace BenchmarksGame Benchmark.Iterate(() => { - using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) using (var input = new StreamReader(inputStream)) { Assert.Equal(helpers.ExpectedLength, Bench(input, false)); diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.csproj index a2acf1f..326811b 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-1.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + + diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.cs index 8eb5f9e..841db08 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.cs @@ -45,7 +45,7 @@ namespace BenchmarksGame { var helpers = new TestHarnessHelpers(bigInput: false); - using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) using (var input = new StreamReader(inputStream)) { if (Bench(input, true) != helpers.ExpectedLength) @@ -64,7 +64,7 @@ namespace BenchmarksGame Benchmark.Iterate(() => { - using (var inputStream = new FileStream(helpers.InputFile, FileMode.Open)) + using (var inputStream = helpers.GetInputStream()) using (var input = new StreamReader(inputStream)) { Assert.Equal(helpers.ExpectedLength, Bench(input, false)); diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.csproj index cd45a09..f96f2e8 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/regex-redux/regex-redux-5.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + + diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/harness-helpers.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/harness-helpers.cs index c494982..0024f56 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/harness-helpers.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/harness-helpers.cs @@ -7,91 +7,36 @@ using System; using System.IO; -using System.Text; +using System.Reflection; namespace BenchmarksGame { class TestHarnessHelpers { - public string InputFile; public int FileLength; public string CheckSum; + private readonly string resourceName; public TestHarnessHelpers(bool bigInput, [System.Runtime.CompilerServices.CallerFilePath] string csFileName = "") { if (bigInput) { - InputFile = FindInputFile("revcomp-input25000.txt", csFileName); FileLength = 254245; CheckSum = "61-A4-CC-6D-15-8D-26-77-88-93-4F-E2-29-A2-8D-FB"; + resourceName = "revcomp-input25000.txt"; } else { - InputFile = FindInputFile("revcomp-input25.txt", csFileName); FileLength = 333; CheckSum = "62-45-8E-09-2E-89-A0-69-8C-17-F5-D8-C7-63-5B-50"; + resourceName = "revcomp-input25.txt"; } } - public string FindInputFile(string inputFile, string csFileName) + public Stream GetInputStream() { - string CoreRoot = System.Environment.GetEnvironmentVariable("CORE_ROOT"); - - if (CoreRoot == null) - { - Console.WriteLine("This benchmark requries CORE_ROOT to be set"); - return null; - } - - // The convention is that the csproj file has the same name as the cs file. - string projectName = Path.GetFileNameWithoutExtension(csFileName); - int slashIndex = projectName.LastIndexOfAny(new char[] { '/', '\\' }); - if (slashIndex != -1) - { - // csFileName was generated by the C# compiler, which may have run on - // a different host system with different path separator than the - // currently executing host, which dictates GetFileNameWithoutExtension's - // behavior... so hope that the slash here is a cross-host path separator, - // and chop of what were likely direcotires. - projectName = projectName.Substring(slashIndex + 1); - } - - // Normal testing -- input file will end up next to the assembly - // and CoreRoot points at the test overlay dir - string[] pathPartsNormal = new string[] { - CoreRoot, "..", "..", "JIT", "Performance", - "CodeQuality", "BenchmarksGame", "reverse-complement", projectName, inputFile - }; - - string inputPathNormal = Path.Combine(pathPartsNormal); - - // Perf testing -- input file will end up next to the assembly - // and CoreRoot points at this directory - string[] pathPartsPerf = new string[] { CoreRoot, inputFile }; - - string inputPathPerf = Path.Combine(pathPartsPerf); - - string inputPath = null; - - if (File.Exists(inputPathNormal)) - { - inputPath = inputPathNormal; - } - else if (File.Exists(inputPathPerf)) - { - inputPath = inputPathPerf; - } - - if (inputPath != null) - { - Console.WriteLine("Using input file {0}", inputFile); - } - else - { - throw new Exception($"Unable to find input file {inputFile}. Tried {inputPathNormal} and {inputPathPerf}; csFileName was {csFileName}, so projectName was {projectName}."); - } - - return inputPath; + var assembly = typeof(TestHarnessHelpers).GetTypeInfo().Assembly; + return assembly.GetManifestResourceStream(resourceName); } } } diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.cs index 902aee3..edf405d 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.cs @@ -53,10 +53,10 @@ namespace BenchmarksGame { var helpers = new TestHarnessHelpers(bigInput: false); var outBytes = new byte[helpers.FileLength]; - using (var input = new FileStream(helpers.InputFile, FileMode.Open)) - using (var output = new MemoryStream(outBytes)) + using (var inputStream = helpers.GetInputStream()) + using (var outputStream = new MemoryStream(outBytes)) { - Bench(input, output); + Bench(inputStream, outputStream); } Console.WriteLine(System.Text.Encoding.UTF8.GetString(outBytes)); if (!MatchesChecksum(outBytes, helpers.CheckSum)) @@ -74,10 +74,10 @@ namespace BenchmarksGame Benchmark.Iterate(() => { - using (var input = new FileStream(helpers.InputFile, FileMode.Open)) - using (var output = new MemoryStream(outBytes)) + using (var inputStream = helpers.GetInputStream()) + using (var outputStream = new MemoryStream(outBytes)) { - Bench(input, output); + Bench(inputStream, outputStream); } }); diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.csproj index 5e0c567..756177f 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-1.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + + diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.cs index 70d84d4..4ce5634 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.cs @@ -236,10 +236,10 @@ namespace BenchmarksGame { var helpers = new TestHarnessHelpers(bigInput: false); var outBytes = new byte[helpers.FileLength]; - using (var input = new FileStream(helpers.InputFile, FileMode.Open)) - using (var output = new MemoryStream(outBytes)) + using (var inputStream = helpers.GetInputStream()) + using (var outputStream = new MemoryStream(outBytes)) { - Bench(input, output); + Bench(inputStream, outputStream); } Console.WriteLine(System.Text.Encoding.UTF8.GetString(outBytes)); if (!MatchesChecksum(outBytes, helpers.CheckSum)) @@ -257,10 +257,10 @@ namespace BenchmarksGame Benchmark.Iterate(() => { - var input = new FileStream(helpers.InputFile, FileMode.Open); - var output = new MemoryStream(outBytes); + using (var inputStream = helpers.GetInputStream()) + using (var outputStream = new MemoryStream(outBytes)) { - Bench(input, output); + Bench(inputStream, outputStream); } }); diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.csproj b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.csproj index b1be51c..f15f473 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.csproj +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/reverse-complement/reverse-complement-6.csproj @@ -34,12 +34,8 @@ - - Always - - - Always - + +