public static int Run(string profileePath, string testName, Guid profilerClsid, string profileeArguments = "", ProfileeOptions profileeOptions = ProfileeOptions.None, Dictionary <string, string> envVars = null, string reverseServerName = null) { string arguments; string program; string profileeAppDir = Path.GetDirectoryName(profileePath); if (envVars == null) { envVars = new Dictionary <string, string>(); } arguments = profileePath + " RunTest " + profileeArguments; program = GetCorerunPath(); string profilerPath = GetProfilerPath(); if (!profileeOptions.HasFlag(ProfileeOptions.NoStartupAttach)) { envVars.Add("CORECLR_ENABLE_PROFILING", "1"); envVars.Add("CORECLR_PROFILER_PATH", profilerPath); envVars.Add("CORECLR_PROFILER", "{" + profilerClsid + "}"); } if (profileeOptions.HasFlag(ProfileeOptions.OptimizationSensitive)) { Console.WriteLine("Disabling tiered compilation, jitstress, and minopts."); envVars.Add("COMPlus_TieredCompilation", "0"); envVars.Add("COMPlus_JitStress", "0"); envVars.Add("COMPlus_JITMinOpts", "0"); } if (profileeOptions.HasFlag(ProfileeOptions.ReverseDiagnosticsMode)) { Console.WriteLine("Launching profilee in reverse diagnostics port mode."); if (String.IsNullOrEmpty(reverseServerName)) { throw new ArgumentException(); } envVars.Add("DOTNET_DiagnosticPorts", reverseServerName); } envVars.Add("Profiler_Test_Name", testName); if (!File.Exists(profilerPath)) { FailFastWithMessage("Profiler library not found at expected path: " + profilerPath); } ProfileeOutputVerifier verifier = new ProfileeOutputVerifier(); Process process = new Process(); process.StartInfo.FileName = program; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; foreach (string key in Environment.GetEnvironmentVariables().Keys) { process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key); } foreach (string key in envVars.Keys) { process.StartInfo.EnvironmentVariables[key] = envVars[key]; } process.OutputDataReceived += (sender, args) => { Console.WriteLine(args.Data); verifier.WriteLine(args.Data); }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); // There are two conditions for profiler tests to pass, the output of the profiled program // must contain the phrase "PROFILER TEST PASSES" and the return code must be 100. This is // because lots of verification happen in the profiler code, where it is hard to change the // program return value. if (!verifier.HasPassingOutput) { FailFastWithMessage("Profiler tests are expected to contain the text \'" + verifier.SuccessPhrase + "\' in the console output " + "of the profilee app to indicate a passing test. Usually it is printed from the Shutdown() method of the profiler implementation. This " + "text was not found in the output above."); } if (process.ExitCode != 100) { FailFastWithMessage($"Profilee returned exit code {process.ExitCode} instead of expected exit code 100."); } return(100); }
public static int Run(string profileePath, string testName, Guid profilerClsid, string profileeArguments = "", ProfileeOptions profileeOptions = ProfileeOptions.None) { string arguments; string program; Dictionary <string, string> envVars = new Dictionary <string, string>(); string profileeAppDir = Path.GetDirectoryName(profileePath); arguments = profileePath + " RunTest " + profileeArguments; program = GetCorerunPath(); if (!profileeOptions.HasFlag(ProfileeOptions.NoStartupAttach)) { envVars.Add("CORECLR_ENABLE_PROFILING", "1"); envVars.Add("CORECLR_PROFILER_PATH", GetProfilerPath()); envVars.Add("CORECLR_PROFILER", "{" + profilerClsid + "}"); } if (profileeOptions.HasFlag(ProfileeOptions.OptimizationSensitive)) { Console.WriteLine("Disabling tiered compilation, jitstress, and minopts."); envVars.Add("COMPlus_TieredCompilation", "0"); envVars.Add("COMPlus_JitStress", "0"); envVars.Add("COMPlus_JITMinOpts", "0"); } string profilerPath = GetProfilerPath(); if (!File.Exists(profilerPath)) { LogTestFailure("Profiler library not found at expected path: " + profilerPath); } ProfileeOutputVerifier verifier = new ProfileeOutputVerifier(); Process process = new Process(); process.StartInfo.FileName = program; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; foreach (string key in Environment.GetEnvironmentVariables().Keys) { process.StartInfo.EnvironmentVariables[key] = Environment.GetEnvironmentVariable(key); } foreach (string key in envVars.Keys) { process.StartInfo.EnvironmentVariables[key] = envVars[key]; } process.OutputDataReceived += (sender, args) => { Console.WriteLine(args.Data); verifier.WriteLine(args.Data); }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); if (process.ExitCode == 100 && verifier.HasPassingOutput) { return(100); } else { LogTestFailure("Profiler tests are expected to contain the text \'" + verifier.SuccessPhrase + "\' in the console output " + "of the profilee app to indicate a passing test. Usually it is printed from the Shutdown() method of the profiler implementation. This " + "text was not found in the output above."); return(process.ExitCode == 100 ? process.ExitCode : -1); } }