From c7c02a5c739326fbafa81da21542965daddcceb5 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Thu, 3 Aug 2023 15:57:33 -0700 Subject: [PATCH 1/5] Added my first draft for the JIT methods counter tests. --- .../HelloWorld/HelloWorld.cs | 10 +++ .../HelloWorld/HelloWorld.csproj | 9 ++ .../JittedMethodsCounter.cs | 85 +++++++++++++++++++ .../JittedMethodsCounter.csproj | 8 ++ 4 files changed, 112 insertions(+) create mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs create mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj create mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs create mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs new file mode 100644 index 00000000000000..ba93410199c3a9 --- /dev/null +++ b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs @@ -0,0 +1,10 @@ +using System; + +internal class HelloWorld +{ + static int Main(string[] args) + { + Console.WriteLine("Hello World!"); + return 512; + } +} diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj new file mode 100644 index 00000000000000..7830f15e274fd4 --- /dev/null +++ b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj @@ -0,0 +1,9 @@ + + + + Exe + net8.0 + true + + + diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs new file mode 100644 index 00000000000000..64c4a7e1839dae --- /dev/null +++ b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs @@ -0,0 +1,85 @@ +// TODO: Add the Microsoft License header here. + +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; + +public class JittedMethodsCounter +{ + static int Main(string[] args) + { + // Let's draft what we need to do for this test in plain terms. + // + // ! 1) We need to build and publish the HelloWorld app. (MSBuild maybe?) + // * 2) We need to run the HelloWorld app's executable. + // * 3) We need to capture its output. + // * 4) We need to read said output. More precisely, the last line. + // * 5) We need to parse the last line to get the last JIT'd method's number. + // * 6) We need to compare this number against a preset expected result. + // * 7) From there, decide whether the test passed or not. + + string appName = "HelloWorld"; + string jitOutputFile = "jits.txt"; + int testReturnCode = 0; + + int appResult = RunHelloWorldApp(appName, jitOutputFile); + int jits = GetNumberOfJittedMethods(jitOutputFile); + + Console.WriteLine($"\nApp's Exit Code: {appResult}"); + Console.WriteLine($"App's Total Jitted Methods: {jits}"); + + if (jits < 100) + { + testReturnCode = 100; + Console.WriteLine("Less than 100 methods were Jitted so the test" + + " has passed!"); + } + else + { + testReturnCode = 101; + Console.WriteLine("More than 100 methods were Jitted so the test" + + " does not pass."); + } + + return testReturnCode; + } + + private static int RunHelloWorldApp(string appName, string jitOutputFile) + { + int exitCode = -1; + + using (Process app = new Process()) + { + var startInfo = new ProcessStartInfo + { + FileName = appName, + CreateNoWindow = true, + UseShellExecute = false, + }; + + startInfo.EnvironmentVariables.Add("DOTNET_JitDisasmSummary", "1"); + startInfo.EnvironmentVariables.Add("DOTNET_TieredCompilation", "0"); + startInfo.EnvironmentVariables.Add("DOTNET_ReadyToRun", "1"); + startInfo.EnvironmentVariables.Add("DOTNET_JitStdOutFile", jitOutputFile); + + app.StartInfo = startInfo; + app.Start(); + app.WaitForExit(); + + exitCode = app.ExitCode; + } + + return exitCode; + } + + private static int GetNumberOfJittedMethods(string jitOutputFile) + { + string[] tokens = File.ReadLines(jitOutputFile) + .Last() + .Split(":"); + + int numJittedMethods = Int32.Parse(tokens[0]); + return numJittedMethods; + } +} diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj new file mode 100644 index 00000000000000..a269962b552f00 --- /dev/null +++ b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj @@ -0,0 +1,8 @@ + + + + Exe + net8.0 + + + From c7df7573ee97fd3cf20104feb76e4d04fc8572c5 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Fri, 11 Aug 2023 15:20:59 -0700 Subject: [PATCH 2/5] Began incorporating the HelloWorld with the test builds. --- .../HelloWorld/HelloWorld.cs | 2 +- src/tests/Common/HelloWorld/HelloWorld.csproj | 13 +++++++++++++ .../JittedMethodsCounter.cs | 14 +++----------- .../JittedMethodsCounter.csproj | 14 ++++++++++++++ .../JittedMethodsCountingTest.cs | 19 +++++++++++++++++++ .../JittedMethodsCountingTest.csproj | 15 +++++++++++++++ src/tests/build.proj | 15 +++++++++++++++ .../HelloWorld/HelloWorld.csproj | 9 --------- .../JittedMethodsCounter.csproj | 8 -------- 9 files changed, 80 insertions(+), 29 deletions(-) rename src/tests/{ivdiazsa_drafts/JittedMethodsCounter => Common}/HelloWorld/HelloWorld.cs (87%) create mode 100644 src/tests/Common/HelloWorld/HelloWorld.csproj rename src/tests/{ivdiazsa_drafts/JittedMethodsCounter => JittedMethodsCountingTest}/JittedMethodsCounter/JittedMethodsCounter.cs (77%) create mode 100644 src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.csproj create mode 100644 src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.cs create mode 100644 src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj delete mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj delete mode 100644 src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs b/src/tests/Common/HelloWorld/HelloWorld.cs similarity index 87% rename from src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs rename to src/tests/Common/HelloWorld/HelloWorld.cs index ba93410199c3a9..dbcbb49173655a 100644 --- a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.cs +++ b/src/tests/Common/HelloWorld/HelloWorld.cs @@ -5,6 +5,6 @@ internal class HelloWorld static int Main(string[] args) { Console.WriteLine("Hello World!"); - return 512; + return 0; } } diff --git a/src/tests/Common/HelloWorld/HelloWorld.csproj b/src/tests/Common/HelloWorld/HelloWorld.csproj new file mode 100644 index 00000000000000..a5c9bc95e9f289 --- /dev/null +++ b/src/tests/Common/HelloWorld/HelloWorld.csproj @@ -0,0 +1,13 @@ + + + + Exe + $(NetCoreAppToolCurrent) + true + + + + + + + diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs b/src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.cs similarity index 77% rename from src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs rename to src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.cs index 64c4a7e1839dae..476f66afdd3e01 100644 --- a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.cs +++ b/src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.cs @@ -4,21 +4,13 @@ using System.Diagnostics; using System.IO; using System.Linq; +using Xunit; public class JittedMethodsCounter { - static int Main(string[] args) + [Fact] + public static int TestEntryPoint() { - // Let's draft what we need to do for this test in plain terms. - // - // ! 1) We need to build and publish the HelloWorld app. (MSBuild maybe?) - // * 2) We need to run the HelloWorld app's executable. - // * 3) We need to capture its output. - // * 4) We need to read said output. More precisely, the last line. - // * 5) We need to parse the last line to get the last JIT'd method's number. - // * 6) We need to compare this number against a preset expected result. - // * 7) From there, decide whether the test passed or not. - string appName = "HelloWorld"; string jitOutputFile = "jits.txt"; int testReturnCode = 0; diff --git a/src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.csproj b/src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.csproj new file mode 100644 index 00000000000000..06a24f0403040b --- /dev/null +++ b/src/tests/JittedMethodsCountingTest/JittedMethodsCounter/JittedMethodsCounter.csproj @@ -0,0 +1,14 @@ + + + + pdbonly + true + + + + + + $(JitPackagesConfigFileDirectory)benchmark\obj\project.assets.json + + + diff --git a/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.cs b/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.cs new file mode 100644 index 00000000000000..b3790049e83e46 --- /dev/null +++ b/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.cs @@ -0,0 +1,19 @@ +// TODO: Add the Microsoft License header here. + +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Xunit; + +public class JittedMethodsCountingTest +{ + [Fact] + public static int TestEntryPoint() + { + int testReturnCode = 0; + return testReturnCode; + } + +} + diff --git a/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj b/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj new file mode 100644 index 00000000000000..228d5ba375851a --- /dev/null +++ b/src/tests/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj @@ -0,0 +1,15 @@ + + + pdbonly + true + + + + + + + + $(JitPackagesConfigFileDirectory)benchmark/obj/project.assets.json + + + diff --git a/src/tests/build.proj b/src/tests/build.proj index cca44fe29bf880..4c2378a1587c9b 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -28,6 +28,15 @@ + + + + + + @@ -612,6 +621,12 @@ Targets="EmitTestExclusionList" Properties="XunitTestBinBase=$(XunitTestBinBase)" /> + + + + diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj deleted file mode 100644 index 7830f15e274fd4..00000000000000 --- a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/HelloWorld/HelloWorld.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - net8.0 - true - - - diff --git a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj b/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj deleted file mode 100644 index a269962b552f00..00000000000000 --- a/src/tests/ivdiazsa_drafts/JittedMethodsCounter/JittedMethodsCounter/JittedMethodsCounter.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - net8.0 - - - From 9b9bb108e5e17de7ec6f8f70f31b67e2ace9ccd7 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Fri, 11 Aug 2023 15:53:19 -0700 Subject: [PATCH 3/5] Added the Jitted Methods counting test to JIT/Performance. --- src/tests/Common/HelloWorld/HelloWorld.cs | 2 + .../JittedMethodsCountingTest.cs | 64 +++++++++++++++++++ .../JittedMethodsCountingTest.csproj | 16 +++++ 3 files changed, 82 insertions(+) create mode 100644 src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs create mode 100644 src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj diff --git a/src/tests/Common/HelloWorld/HelloWorld.cs b/src/tests/Common/HelloWorld/HelloWorld.cs index dbcbb49173655a..112361afc462ae 100644 --- a/src/tests/Common/HelloWorld/HelloWorld.cs +++ b/src/tests/Common/HelloWorld/HelloWorld.cs @@ -1,3 +1,5 @@ +// TODO: Add the Microsoft License header here. + using System; internal class HelloWorld diff --git a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs new file mode 100644 index 00000000000000..fd57239ff18b03 --- /dev/null +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs @@ -0,0 +1,64 @@ +// TODO: Add the Microsoft License header here. + +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Xunit; + +public class JittedMethodsCountingTest +{ + private const int MAX_JITTED_METHODS_ACCEPTED = 50; + + [Fact] + public static int TestEntryPoint() + { + string appName = "HelloWorld.dll"; + string jitOutputFile = "jits.txt"; + + int appResult = RunHelloWorldApp(appName, jitOutputFile); + int jits = GetNumberOfJittedMethods(jitOutputFile); + + return jits < MAX_JITTED_METHODS_ACCEPTED ? 100 : 101; + } + + private static int RunHelloWorldApp(string appName, string jitOutputFile) + { + int appExitCode = -1; + + using (Process app = new Process()) + { + var startInfo = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = appName, + CreateNoWindow = true, + UseShellExecute = false, + }; + + startInfo.EnvironmentVariables.Add("DOTNET_JitDisasmSummary", 1); + startInfo.EnvironmentVariables.Add("DOTNET_TieredCompilation", 0); + startInfo.EnvironmentVariables.Add("DOTNET_ReadyToRun", 1); + startInfo.EnvironmentVariables.Add("DOTNET_JitStdOutFile", jitOutputFile); + + app.StartInfo = startInfo; + app.Start(); + app.WaitForExit(); + + appExitCode = app.ExitCode; + } + + return appExitCode; + } + + private static int GetNumberOfJittedMethods(string jitOutputFile) + { + string[] tokens = File.ReadLines(jitOutputFile) + .Last() + .Split(":"); + + int numJittedMethods = Int32.Parse(tokens[0]); + return numJittedMethods; + } +} + diff --git a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj new file mode 100644 index 00000000000000..ef6e6690bdd231 --- /dev/null +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj @@ -0,0 +1,16 @@ + + + + pdbonly + true + + + + + + + + $(JitPackagesConfigFileDirectory)benchmark/obj/project.assets.json + + + From 1713f4506ce3087366379f8ee0f78572aa55a92c Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Mon, 14 Aug 2023 16:01:26 -0700 Subject: [PATCH 4/5] Made more progress. Still doesn't work. --- src/tests/JIT/Performance/JIT.performance.csproj | 1 + .../HelloWorld/HelloWorld.cs | 3 ++- .../HelloWorld/HelloWorld.csproj | 2 +- .../JittedMethodsCountingTest.cs | 3 ++- .../JittedMethodsCountingTest.csproj | 10 +++++++++- src/tests/build.proj | 8 ++++---- 6 files changed, 19 insertions(+), 8 deletions(-) rename src/tests/{Common => JIT/Performance/JittedMethodsCountingTest}/HelloWorld/HelloWorld.cs (52%) rename src/tests/{Common => JIT/Performance/JittedMethodsCountingTest}/HelloWorld/HelloWorld.csproj (73%) diff --git a/src/tests/JIT/Performance/JIT.performance.csproj b/src/tests/JIT/Performance/JIT.performance.csproj index f751282d127da4..2f2930ecae9f6c 100644 --- a/src/tests/JIT/Performance/JIT.performance.csproj +++ b/src/tests/JIT/Performance/JIT.performance.csproj @@ -1,6 +1,7 @@ + diff --git a/src/tests/Common/HelloWorld/HelloWorld.cs b/src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.cs similarity index 52% rename from src/tests/Common/HelloWorld/HelloWorld.cs rename to src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.cs index 112361afc462ae..1ca273d0f84576 100644 --- a/src/tests/Common/HelloWorld/HelloWorld.cs +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.cs @@ -1,4 +1,5 @@ -// TODO: Add the Microsoft License header here. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. using System; diff --git a/src/tests/Common/HelloWorld/HelloWorld.csproj b/src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.csproj similarity index 73% rename from src/tests/Common/HelloWorld/HelloWorld.csproj rename to src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.csproj index a5c9bc95e9f289..b3f848e705c07e 100644 --- a/src/tests/Common/HelloWorld/HelloWorld.csproj +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/HelloWorld/HelloWorld.csproj @@ -3,7 +3,7 @@ Exe $(NetCoreAppToolCurrent) - true + diff --git a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs index fd57239ff18b03..83db1ba66abb2a 100644 --- a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs @@ -1,4 +1,5 @@ -// TODO: Add the Microsoft License header here. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. using System; using System.Diagnostics; diff --git a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj index ef6e6690bdd231..56935f0be39469 100644 --- a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj @@ -6,7 +6,15 @@ - + + + + + + false + Content + Always + diff --git a/src/tests/build.proj b/src/tests/build.proj index 4c2378a1587c9b..3fb21b56d88fbf 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -35,7 +35,7 @@ test depends on. Merged Test Groups don't like separate apps being built together with the test projects. --> - + @@ -623,9 +623,9 @@ - + + + Date: Wed, 16 Aug 2023 01:11:54 +0200 Subject: [PATCH 5/5] Infra fixes for Ivan's new JIT count test This change combines Ivan's private branch 'jit-participants' with a couple of infra fixes to make his test work. The fundamental remaining piece is figuring out how to get rid of the commented out line in XUnitWrapperGenerator.cs, @jkoritzinsky please advise how to check the ProjectReference item for the ReferenceOutputAssembly so that we ignore the reference in the merged wrapper generator when it's set to false - i.o.w. when the project doesn't intend to use the reference as a direct component of its managed executable, it's rather intented as a payload that's manipulated in a special manner at runtime. I assume that, once we clarify this one remaining problem, I'll send out the PR for the build script changes; that should subsequently let Ivan adapt my changes to his test case based on his discretion and make it fully functional both locally and in the lab. Thanks Tomas --- .../XUnitWrapperGenerator.cs | 2 + src/tests/Directory.Build.targets | 1 + .../HelloWorld/HelloWorld.csproj | 1 + .../JittedMethodsCountingTest.cs | 37 ++++++++++++++----- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs index ce0d9d9de14994..8e0676d5285dc7 100644 --- a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs +++ b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs @@ -184,10 +184,12 @@ private static void AddRunnerSource(SourceProductionContext context, ImmutableAr private static void CheckNoEntryPoint(SourceProductionContext context, CompData compData) { + /* foreach (IMethodSymbol entryPoint in compData.PossibleEntryPoints) { context.ReportDiagnostic(Diagnostic.Create(Descriptors.XUWG1001, entryPoint.Locations[0])); } + */ } private static void AppendAliasMap(CodeBuilder builder, ImmutableDictionary aliasMap) diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 7c0dbf9e492ffa..1c4dc62b1abbb6 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -153,6 +153,7 @@ Exe + BuildOnly $(NetCoreAppToolCurrent) diff --git a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs index 83db1ba66abb2a..ae4b77277278d4 100644 --- a/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs +++ b/src/tests/JIT/Performance/JittedMethodsCountingTest/JittedMethodsCountingTest.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using Xunit; public class JittedMethodsCountingTest @@ -14,32 +15,39 @@ public class JittedMethodsCountingTest [Fact] public static int TestEntryPoint() { - string appName = "HelloWorld.dll"; - string jitOutputFile = "jits.txt"; + string testAppFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + string appName = Path.Combine(testAppFolder, "HelloWorld.dll"); + string jitOutputFile = Path.Combine(testAppFolder, "jits.txt"); int appResult = RunHelloWorldApp(appName, jitOutputFile); int jits = GetNumberOfJittedMethods(jitOutputFile); - return jits < MAX_JITTED_METHODS_ACCEPTED ? 100 : 101; + return jits > 0 && jits <= MAX_JITTED_METHODS_ACCEPTED ? 100 : 101; } private static int RunHelloWorldApp(string appName, string jitOutputFile) { int appExitCode = -1; + string osExeSuffix = (OperatingSystem.IsWindows() ? ".exe" : ""); + string coreRootPath = Environment.GetEnvironmentVariable("CORE_ROOT"); + string coreRunPath = Path.Combine(coreRootPath, "corerun" + osExeSuffix); using (Process app = new Process()) { var startInfo = new ProcessStartInfo { - FileName = "dotnet", + FileName = coreRunPath, Arguments = appName, CreateNoWindow = true, UseShellExecute = false, }; - startInfo.EnvironmentVariables.Add("DOTNET_JitDisasmSummary", 1); - startInfo.EnvironmentVariables.Add("DOTNET_TieredCompilation", 0); - startInfo.EnvironmentVariables.Add("DOTNET_ReadyToRun", 1); + Console.WriteLine("Launching: {0} {1}", startInfo.FileName, startInfo.Arguments); + + startInfo.EnvironmentVariables.Add("DOTNET_JitDisasmSummary", "1"); + startInfo.EnvironmentVariables.Add("DOTNET_TieredCompilation", "0"); + startInfo.EnvironmentVariables.Add("DOTNET_ReadyToRun", "1"); startInfo.EnvironmentVariables.Add("DOTNET_JitStdOutFile", jitOutputFile); app.StartInfo = startInfo; @@ -47,6 +55,8 @@ private static int RunHelloWorldApp(string appName, string jitOutputFile) app.WaitForExit(); appExitCode = app.ExitCode; + Console.WriteLine("Exit code: {0}", appExitCode); + Console.WriteLine("JIT file: {0} ({1} B)", jitOutputFile, new FileInfo(jitOutputFile).Length); } return appExitCode; @@ -54,9 +64,16 @@ private static int RunHelloWorldApp(string appName, string jitOutputFile) private static int GetNumberOfJittedMethods(string jitOutputFile) { - string[] tokens = File.ReadLines(jitOutputFile) - .Last() - .Split(":"); + string[] lines = File.ReadAllLines(jitOutputFile); + + Console.WriteLine("=========== App standard output ==========="); + foreach (string line in lines) + { + Console.WriteLine(line); + } + Console.WriteLine("=========== End of app standard output ==========="); + + string[] tokens = lines.Last().Split(":"); int numJittedMethods = Int32.Parse(tokens[0]); return numJittedMethods;