Exemplo n.º 1
0
        private static void DeleteOutputFileIfExist(string output)
        {
            string outputPath = Path.Combine(PathUtils.GetTestResultsPath(), output);

            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }
        }
        public static void DiffResultToBaseline(string output, string baseline)
        {
            string outputPath = Path.Combine(PathUtils.GetTestResultsPath(), output);
            string baselinePath = Path.Combine(PathUtils.GetBaselinesPath(), baseline);

            string baselineStr;
            StringBuilder outputStrBuilder = new StringBuilder();
            string outputStr;

            using (StreamReader baselineStream = new StreamReader(baselinePath))
            {
                using (StreamReader outputStream = new StreamReader(outputPath))
                {
                    baselineStr = baselineStream.ReadToEnd();
                    string tmpStr;
                    while ((tmpStr = outputStream.ReadLine()) != null)
                    {
                        if (!string.IsNullOrEmpty(tmpStr) &&
                            !tmpStr.StartsWith("[TestIgnore]"))
                        {
                            outputStrBuilder.Append(tmpStr);
                        }
                    }
                    outputStr = outputStrBuilder.ToString();
                }
            }

            string[] baselineDocs = SplitXmlDocuments(baselineStr);
            string[] outputDocs = SplitXmlDocuments(outputStr);

            Assert.AreEqual(baselineDocs.Length, outputDocs.Length);
            for (int docIdx = 0; docIdx < baselineDocs.Length; docIdx++)
            {

                string baselineXmlDocStr = baselineDocs[docIdx];
                string outputXmlDocStr = outputDocs[docIdx];

                XmlDocument baselineDocument = new XmlDocument();
                baselineDocument.LoadXml(baselineXmlDocStr);

                XmlDocument outputDocument = new XmlDocument();
                outputDocument.LoadXml(outputXmlDocStr);

                Assert.AreEqual(baselineDocument.ChildNodes.Count, outputDocument.ChildNodes.Count);

                for (int i = 0; i < baselineDocument.ChildNodes.Count; i++)
                {
                    XmlNode currBaselineNode = baselineDocument.ChildNodes[i];
                    XmlNode currOutputNode = outputDocument.ChildNodes[i];

                    DiffResultToBaselineNode(currBaselineNode, currOutputNode);
                }
            }
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public static void DiffResultToBaseline(string output, string baseline, bool regexCompare = false)
        {
            string outputPath   = Path.Combine(PathUtils.GetTestResultsPath(), output);
            string baselinePath = Path.Combine(PathUtils.GetBaselinesPath(), baseline);

            try
            {
                string baselineStr;
                string outputStr;

                List <string> baselineStrList = new List <string>();
                List <string> outputStrList   = new List <string>();

                using (StreamReader baselineStream = new StreamReader(baselinePath))
                    using (StreamReader outputStream = new StreamReader(outputPath))
                    {
                        string tmpStr;

                        StringBuilder strBuilder = new StringBuilder();
                        while ((tmpStr = baselineStream.ReadLine()) != null)
                        {
                            if (!string.IsNullOrEmpty(tmpStr))
                            {
                                strBuilder.Append(tmpStr);
                                baselineStrList.Add($"^{tmpStr}$");
                            }
                        }
                        baselineStr = strBuilder.ToString();

                        strBuilder = new StringBuilder();
                        while ((tmpStr = outputStream.ReadLine()) != null)
                        {
                            if (!string.IsNullOrEmpty(tmpStr) &&
                                !tmpStr.StartsWith("[TestIgnore]"))
                            {
                                strBuilder.Append(tmpStr);
                                outputStrList.Add(tmpStr);
                            }
                        }
                        outputStr = strBuilder.ToString();
                    }

                if (regexCompare)
                {
                    Assert.IsTrue(baselineStrList.Count == outputStrList.Count, "Baseline file line count does not match output file line count.");

                    for (int i = 0; i < baselineStrList.Count; i++)
                    {
                        Match match = Regex.Match(outputStrList[i], baselineStrList[i]);
                        if (!match.Success)
                        {
                            Assert.Fail("Baseline file regex failed to match output file:\n" + baselineStrList[i] + "\n" + outputStrList[i]);
                        }
                    }
                }
                else
                {
                    // Use XML comparison
                    string[] baselineDocs = SplitXmlDocuments(baselineStr);
                    string[] outputDocs   = SplitXmlDocuments(outputStr);

                    Assert.AreEqual(baselineDocs.Length, outputDocs.Length);
                    for (int docIdx = 0; docIdx < baselineDocs.Length; docIdx++)
                    {
                        string baselineXmlDocStr = baselineDocs[docIdx];
                        string outputXmlDocStr   = outputDocs[docIdx];

                        XmlDocument baselineDocument = new XmlDocument();
                        baselineDocument.LoadXml(baselineXmlDocStr);

                        XmlDocument outputDocument = new XmlDocument();
                        outputDocument.LoadXml(outputXmlDocStr);

                        Assert.AreEqual(baselineDocument.ChildNodes.Count, outputDocument.ChildNodes.Count);

                        for (int i = 0; i < baselineDocument.ChildNodes.Count; i++)
                        {
                            XmlNode currBaselineNode = baselineDocument.ChildNodes[i];
                            XmlNode currOutputNode   = outputDocument.ChildNodes[i];

                            DiffResultToBaselineNode(currBaselineNode, currOutputNode);
                        }
                    }
                }
            }
            catch (AssertFailedException)
            {
                Console.WriteLine($"Baseline FilePath: {baselinePath}");
                Console.WriteLine();
                Console.WriteLine($"Output FilePath: {outputPath}");
                throw;
            }
        }