/// <summary> /// Process the output of the vertarget command. /// </summary> /// <param name="analysis">The results structure to update.</param> /// <param name="commandOutput">The result data to analyze.</param> private static void processVerTargetResults(StackHashDumpAnalysis analysis, StackHashScriptLineResult commandOutput) { foreach (String line in commandOutput.ScriptLineOutput) { String value = null; if ((value = GetColonOption(line, "System Uptime")) != null) { analysis.SystemUpTime = value; } else if ((value = GetColonOption(line, "Process Uptime")) != null) { analysis.ProcessUpTime = value; } else if (line.StartsWith("Windows", StringComparison.OrdinalIgnoreCase)) { if (line.Contains("x64") || line.Contains("X64")) { analysis.OSVersion = line; analysis.MachineArchitecture = "x64"; } else if (line.Contains("x86") || line.Contains("X86")) { analysis.OSVersion = line; analysis.MachineArchitecture = "x86"; } } } }
/// <summary> /// Analyzes the output generated when running the autoscript against a dump file. /// Various details are extracted and presented in object form in StackHashDumpAnalysis. /// </summary> /// <param name="analysis">The analysis results so far.</param> /// <param name="results">The results file to analyze.</param> /// <returns>The results of the analysis. Null fields are underined.</returns> public override StackHashDumpAnalysis AnalyzeScriptResults(StackHashDumpAnalysis analysis, StackHashScriptResult results) { if (analysis == null) { throw new ArgumentNullException("analysis"); } if (results == null) { throw new ArgumentNullException("results"); } // Work through all of the command output looking for useful data. foreach (StackHashScriptLineResult commandOutput in results.ScriptResults) { if (commandOutput.ScriptLine.Comment.Contains(s_VerTargetComment)) { // Get the version information. processVerTargetResults(analysis, commandOutput); } else if (commandOutput.ScriptLine.Comment.Contains(s_MscoreModuleComment)) { // Get the .NET version information. For V3.5 and below the CLR version is in mscorwks.dll processMscorwksResults(analysis, commandOutput); } else if (commandOutput.ScriptLine.Comment.Contains(s_MscoreModuleComment2)) { // Get the .NET version information. For V4.0 and above (so far) the CLR version is in clr.dll processMscorwksResults(analysis, commandOutput); } } return(analysis); }
/// <summary> /// Process the output of the lm v m mscorwks command. /// This gives the .NET version loaded in the dump. /// </summary> /// <param name="analysis">The results structure to update.</param> /// <param name="commandOutput">The result data to analyze</param> private static void processMscorwksResults(StackHashDumpAnalysis analysis, StackHashScriptLineResult commandOutput) { foreach (String line in commandOutput.ScriptLineOutput) { String value = null; if ((value = GetColonOption(line, "Product version")) != null) { analysis.DotNetVersion = value; } } }
public void RunAllAutoScripts() { String dumpFileName = m_TempPath + "Cucku.exe.mdmp"; // First make a copy of the test cab file. File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp", dumpFileName, true); FileAttributes attributes = File.GetAttributes(dumpFileName); File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly); ScriptManager scriptManager = new ScriptManager(m_TempPath); // Now execute the script. StackHashDebug.Windbg winDbg = new Windbg(); try { Collection <AutoScriptBase> autoScripts = scriptManager.AutoScripts; foreach (AutoScriptBase autoScript in autoScripts) { // Generate the script settings structure in memory. StackHashScriptSettings scriptSettings = autoScript.GenerateScript(); // Those settings are now used to create a WinDbg script file (wds). This file has a command // to create a log file (the resultsFileName). String resultsFileName = String.Format("{0}.log", Path.Combine(m_TempPath, autoScript.ScriptName)); String scriptFileName = String.Format("{0}.wds", Path.Combine(m_TempPath, autoScript.ScriptName)); String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath); // Run the wds file through the debugger to produce the results.log file. winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath); // Load the results.log file. StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName); // Analyse the results. StackHashDumpAnalysis analysis = new StackHashDumpAnalysis(); analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults); } } finally { scriptManager.RemoveAutoScripts(); } }
public void RunAutoScript() { String dumpFileName = m_TempPath + "Cucku.exe.mdmp"; String scriptFileName = m_TempPath + "AutoScript.wds"; String resultsFileName = m_TempPath + "AutoScript.log"; // First make a copy of the test cab file. File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp", dumpFileName, true); FileAttributes attributes = File.GetAttributes(dumpFileName); File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly); AutoScript autoScript = new AutoScript(m_TempPath); StackHashScriptSettings scriptSettings = autoScript.GenerateScript(); String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(null, symPath); Assert.AreEqual(null, exePath); Assert.AreEqual(null, srcPath); // Now execute the script. StackHashDebug.Windbg winDbg = new Windbg(); winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath); // Load the results file. StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName); // Analyse the results. StackHashDumpAnalysis analysis = new StackHashDumpAnalysis(); analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults); Assert.AreEqual("not available", analysis.SystemUpTime); Assert.AreEqual("0 days 0:02:20.000", analysis.ProcessUpTime); Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion); }
/// <summary> /// Analyzes the output generated when running the script against a dump file. /// Various details are extracted and presented in object form in StackHashDumpAnalysis. /// </summary> /// <param name="analysis">The analysis results so far.</param> /// <param name="results">The results file to analyze.</param> /// <returns>The results of the analysis. Null fields are underined.</returns> public override StackHashDumpAnalysis AnalyzeScriptResults(StackHashDumpAnalysis analysis, StackHashScriptResult results) { if (analysis == null) { throw new ArgumentNullException("analysis"); } if (results == null) { throw new ArgumentNullException("results"); } // Work through all of the command output looking for useful data. foreach (StackHashScriptLineResult commandOutput in results.ScriptResults) { if (commandOutput.ScriptLine.Comment.Contains(s_VerTargetComment)) { // Get the version information. processVerTargetResults(analysis, commandOutput); } } return(analysis); }
public void AutoScriptOnOneCabAlreadyRunButNewerVersion() { // If the auto task sees the AutoScript.log file exists and has the same // version as the current AutoScript.xml then it shouldn't run it again. // Determine this by checking the file time after a second run. // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters(); // Standard task parameters. analyzeParams.IsBackgroundTask = true; analyzeParams.Name = "TestRunOneTask"; analyzeParams.RunInParallel = false; analyzeParams.UseSeparateThread = true; analyzeParams.AnalysisSettings = new StackHashAnalysisSettings(); analyzeParams.AnalysisSettings.ForceRerun = true; analyzeParams.ContextId = 0; analyzeParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); analyzeParams.Debugger = m_Debugger; analyzeParams.DebuggerSettings = m_DebuggerSettings; analyzeParams.TheScriptManager = scriptManager; analyzeParams.TheScriptResultsManager = scriptResultsManager; int productId = 1; analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection(); analyzeParams.ProductsToSynchronize.Add(new StackHashProductSyncData(productId)); analyzeParams.ErrorIndex = errorIndex; // Create the task and run it. AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); StackHashProductCollection products = errorIndex.LoadProductList(); StackHashFileCollection files = errorIndex.LoadFileList(products[0]); StackHashEventCollection events = errorIndex.LoadEventList(products[0], files[0]); StackHashCabCollection cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashScriptResult script1 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); // Wait for 1 second - so file time granularity exceeded. Thread.Sleep(1000); // Change the version on the autoscript. StackHashScriptSettings settings = scriptManager.LoadScript("AutoScript"); settings.LastModifiedDate = DateTime.Now; scriptManager.AddScript(settings, true, true); // Now run the task again. analyzeTask = new AnalyzeTask(analyzeParams); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted); // Refresh the cab list data. cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; Assert.AreEqual("not available", analysis.SystemUpTime); Assert.AreEqual("0 days 0:00:15.000", analysis.ProcessUpTime); Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion); StackHashScriptResult script2 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript"); Assert.AreEqual(true, script2.RunDate > script1.RunDate); }
public void AutoScriptOnOneCabProductNotEnabled() { // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters(); // Standard task parameters. analyzeParams.IsBackgroundTask = true; analyzeParams.Name = "TestRunOneTask"; analyzeParams.RunInParallel = false; analyzeParams.UseSeparateThread = true; analyzeParams.AnalysisSettings = new StackHashAnalysisSettings(); analyzeParams.AnalysisSettings.ForceRerun = true; analyzeParams.ContextId = 0; analyzeParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); analyzeParams.Debugger = m_Debugger; analyzeParams.DebuggerSettings = m_DebuggerSettings; analyzeParams.TheScriptManager = scriptManager; analyzeParams.TheScriptResultsManager = scriptResultsManager; analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection(); analyzeParams.ErrorIndex = errorIndex; // Create the task and run it. AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(analyzeTask); taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout); Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted); StackHashProductCollection products = errorIndex.LoadProductList(); StackHashFileCollection files = errorIndex.LoadFileList(products[0]); StackHashEventCollection events = errorIndex.LoadEventList(products[0], files[0]); StackHashCabCollection cabs = errorIndex.LoadCabList(products[0], files[0], events[0]); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; Assert.AreEqual(null, analysis.DotNetVersion); Assert.AreEqual(null, analysis.MachineArchitecture); Assert.AreEqual(null, analysis.OSVersion); Assert.AreEqual(null, analysis.ProcessUpTime); Assert.AreEqual(null, analysis.SystemUpTime); }
/// <summary> /// Analyzes the output generated when running the autoscript against a dump file. /// Various details are extracted and presented in object form in StackHashDumpAnalysis. /// </summary> /// <param name="analysis">The analysis results so far.</param> /// <param name="results">The results file to analyze.</param> /// <returns>The results of the analysis. Null fields are underined.</returns> public abstract StackHashDumpAnalysis AnalyzeScriptResults(StackHashDumpAnalysis analysis, StackHashScriptResult results);
public void RunScriptOnCorruptCab() { // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); // Delete the cab file. StackHashProduct product = errorIndex.GetProduct(1); StackHashFile file = errorIndex.GetFile(product, 1); StackHashEventPackageCollection events = errorIndex.GetProductEvents(product); String cabFileName = errorIndex.GetCabFileName(product, file, events[0].EventData, events[0].Cabs[0].Cab); if (File.Exists(cabFileName)) { FileStream fileStream = File.Open(cabFileName, FileMode.Open, FileAccess.ReadWrite); try { fileStream.SetLength(100); } finally { fileStream.Close(); } } ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. DebugScriptTaskParameters runScriptParams = new DebugScriptTaskParameters(); // Standard task parameters. runScriptParams.IsBackgroundTask = true; runScriptParams.Name = "TestRunOneTask"; runScriptParams.RunInParallel = false; runScriptParams.UseSeparateThread = true; runScriptParams.ContextId = 0; runScriptParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); runScriptParams.Debugger = m_Debugger; runScriptParams.TheScriptManager = scriptManager; runScriptParams.TheScriptResultsManager = scriptResultsManager; runScriptParams.Product = product; runScriptParams.File = file; runScriptParams.TheEvent = events[0].EventData; runScriptParams.Cab = events[0].Cabs[0].Cab; runScriptParams.ErrorIndex = errorIndex; // Create the task and run it. DebugScriptTask debugScriptTask = new DebugScriptTask(runScriptParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(debugScriptTask); taskManager.WaitForTaskCompletion(debugScriptTask, s_TaskTimeout); Assert.AreEqual(true, debugScriptTask.CurrentTaskState.TaskCompleted); Assert.AreNotEqual(null, debugScriptTask.LastException); Assert.AreEqual(true, debugScriptTask.LastException is StackHashException); StackHashException ex = debugScriptTask.LastException as StackHashException; Assert.AreEqual(StackHashServiceErrorCode.CabIsCorrupt, ex.ServiceErrorCode); StackHashCabCollection cabs = errorIndex.LoadCabList(product, file, events[0].EventData); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; }