private static XmlDocument LoadTestScript(string testScript)
        {
            string scriptPath = Path.Combine(PathUtils.GetTestScriptsPath(), testScript);

            XmlDocument scriptDocument = new XmlDocument();
            scriptDocument.Load(scriptPath);

            return scriptDocument;
        }
Exemple #2
0
        public static void LaunchAppUnderProfiler(string testApp, string testScript, string output, bool isRejit, string args)
        {
            if (!BinaryRecompiled)
            {
                BinaryRecompiled = true;
                TargetAppCompiler.DeleteExistingBinary(PathUtils.GetAssetsPath());
                TargetAppCompiler.ComplileCSharpTestCode(PathUtils.GetAssetsPath());
            }

            DeleteOutputFileIfExist(output);

            // Ensure test results path exists
            Directory.CreateDirectory(PathUtils.GetTestResultsPath());

            bool   is32bitTest   = Is32bitTest(testScript);
            string bitnessSuffix = is32bitTest ? "x86" : "x64";

            // TODO: call this only for 64bit OS
            SetBitness(is32bitTest);

            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
            psi.UseShellExecute = false;
            psi.EnvironmentVariables.Add("COR_ENABLE_PROFILING", "1");
            psi.EnvironmentVariables.Add("COR_PROFILER", ProfilerGuid.ToString("B"));
            psi.EnvironmentVariables.Add("COR_PROFILER_PATH", Path.Combine(PathUtils.GetAssetsPath(), string.Format("MicrosoftInstrumentationEngine_{0}.dll", bitnessSuffix)));

            if (!TestParameters.DisableLogLevel)
            {
                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_LogLevel", "Dumps");
            }

            // Uncomment this line to debug tests
            //psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_DebugWait", "1");

            if (ThrowMessageBoxAtStartup)
            {
                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_MessageboxAtAttach", @"1");
            }

            if (TestParameters.DisableMethodSignatureValidation)
            {
                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_DisableCodeSignatureValidation", @"1");
            }

            if (TestParameters.DisableMethodPrefix)
            {
                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_DisableLogMethodPrefix", @"1");
            }

            if (TestParameters.MethodLogLevel != LogLevel.Unset)
            {
                StringBuilder methodLogLevelBuilder = new StringBuilder();
                if ((TestParameters.MethodLogLevel & LogLevel.All) == LogLevel.None)
                {
                    methodLogLevelBuilder.Append("|None");
                }
                else
                {
                    if ((TestParameters.MethodLogLevel & LogLevel.All) == LogLevel.All)
                    {
                        methodLogLevelBuilder.Append("|All");
                    }
                    else
                    {
                        if ((TestParameters.MethodLogLevel & LogLevel.Errors) == LogLevel.Errors)
                        {
                            methodLogLevelBuilder.Append("|Errors");
                        }

                        if ((TestParameters.MethodLogLevel & LogLevel.Trace) == LogLevel.Trace)
                        {
                            methodLogLevelBuilder.Append("|Messages");
                        }

                        if ((TestParameters.MethodLogLevel & LogLevel.InstrumentationResults) == LogLevel.InstrumentationResults)
                        {
                            methodLogLevelBuilder.Append("|Dumps");
                        }
                    }
                }

                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_LogLevel_D2959618-F9B6-4CB6-80CF-F3B0E3263888", methodLogLevelBuilder.ToString());
            }
            else
            {
                // This variable overrides ALL logging levels for FileLoggerSink.
                psi.EnvironmentVariables.Add("MicrosoftInstrumentationEngine_FileLog", "Dumps");
            }

            psi.EnvironmentVariables.Add(TestOutputEnvName, PathUtils.GetAssetsPath());
            psi.EnvironmentVariables.Add(
                is32bitTest? HostConfig32PathEnvName : HostConfig64PathEnvName,
                Path.Combine(PathUtils.GetAssetsPath(), string.Format("NaglerInstrumentationMethod_{0}.xml", bitnessSuffix)));

            string scriptPath = Path.Combine(PathUtils.GetTestScriptsPath(), testScript);

            psi.EnvironmentVariables.Add(TestScriptFileEnvName, scriptPath);

            string outputPath = Path.Combine(PathUtils.GetTestResultsPath(), output);

            psi.EnvironmentVariables.Add(TestOutputFileEnvName, outputPath);
            psi.EnvironmentVariables.Add(IsRejitEnvName, isRejit ? "True" : "False");

            psi.FileName  = Path.Combine(PathUtils.GetAssetsPath(), testApp);
            psi.Arguments = args;

            System.Diagnostics.Process testProcess = System.Diagnostics.Process.Start(psi);
            testProcess.WaitForExit();

            Assert.AreEqual(0, testProcess.ExitCode, "Test application failed");
        }