/// <summary> /// Initialize blame. /// </summary> /// <param name="enableDump">Enable dump.</param> /// <param name="blameParameters">Blame parameters.</param> private void InitializeBlame(bool enableDump, Dictionary <string, string> collectDumpParameters) { // Add Blame Logger LoggerUtilities.AddLoggerToRunSettings(BlameFriendlyName, null, this.runSettingsManager); // Add Blame Data Collector CollectArgumentExecutor.AddDataCollectorToRunSettings(BlameFriendlyName, this.runSettingsManager, this.fileHelper); // Add default run settings if required. if (this.runSettingsManager.ActiveRunSettings?.SettingsXml == null) { this.runSettingsManager.AddDefaultRunSettings();; } var settings = this.runSettingsManager.ActiveRunSettings?.SettingsXml; // Get results directory from RunSettingsManager var resultsDirectory = GetResultsDirectory(settings); // Get data collection run settings. Create if not present. var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings); if (dataCollectionRunSettings == null) { dataCollectionRunSettings = new DataCollectionRunSettings(); } // Create blame configuration element. var XmlDocument = new XmlDocument(); var outernode = XmlDocument.CreateElement("Configuration"); var node = XmlDocument.CreateElement("ResultsDirectory"); outernode.AppendChild(node); node.InnerText = resultsDirectory; // Add collect dump node in configuration element. if (enableDump) { AddCollectDumpNode(collectDumpParameters, XmlDocument, outernode); } // Add blame configuration element to blame collector. foreach (var item in dataCollectionRunSettings.DataCollectorSettingsList) { if (item.FriendlyName.Equals(BlameFriendlyName)) { item.Configuration = outernode; } } // Update run settings. runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml); }
/// <summary> /// Updates with code coverage settings if not configured. /// </summary> /// <param name="runSettingsDocument"> The run settings document. </param> private void UpdateWithCodeCoverageSettingsIfNotConfigured() { var runsettingsXml = this.runSettingsManager.ActiveRunSettings?.SettingsXml; if (runsettingsXml == null) { this.runSettingsManager.AddDefaultRunSettings(); runsettingsXml = this.runSettingsManager.ActiveRunSettings?.SettingsXml; } IXPathNavigable runSettingsDocument; using (var stream = new StringReader(runsettingsXml)) using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings)) { var document = new XmlDocument(); document.Load(reader); runSettingsDocument = document; } var runSettingsNavigator = runSettingsDocument.CreateNavigator(); if (ContainsDataCollectorWithFriendlyName(runSettingsNavigator, FriendlyName)) { // runsettings already has Code coverage data collector, just enable it. CollectArgumentExecutor.AddDataCollectorToRunSettings(FriendlyName, this.runSettingsManager); } else { var existingPath = string.Empty; var xpaths = new string[] { string.Join(xPathSeperator, nodeNames, 0, 1), string.Join(xPathSeperator, nodeNames, 0, 2), string.Join(xPathSeperator, nodeNames, 0, 3) }; foreach (var xpath in xpaths) { if (runSettingsNavigator.SelectSingleNode(xpath) != null) { existingPath = xpath; } else { break; } } // If any nodes are missing to add code coverage deafult settings, add the missing xml nodes. XPathNavigator dataCollectorsNavigator; if (existingPath.Equals(xpaths[2]) == false) { dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(existingPath); var missingNodesText = GetMissingNodesTextIfAny(existingPath, xpaths[2]); dataCollectorsNavigator.AppendChild(missingNodesText); } dataCollectorsNavigator = runSettingsNavigator.SelectSingleNode(xpaths[2]); dataCollectorsNavigator.AppendChild(codeCoverageCollectorSettingsTemplate); this.runSettingsManager.UpdateRunSettings(runSettingsDocument.CreateNavigator().OuterXml); } }
/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { // Add Blame Logger this.loggerManager.UpdateLoggerList(BlameFriendlyName, BlameFriendlyName, null); // Add Blame Data Collector CollectArgumentExecutor.AddDataCollectorToRunSettings(BlameFriendlyName, this.runSettingsManager); // Get results directory from RunSettingsManager var runSettings = this.runSettingsManager.ActiveRunSettings; string resultsDirectory = null; if (runSettings != null) { try { RunConfiguration runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings.SettingsXml); resultsDirectory = RunSettingsUtilities.GetTestResultsDirectory(runConfiguration); } catch (SettingsException se) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("EnableBlameArgumentProcessor: Unable to get the test results directory: Error {0}", se); } } } // Add configuration element var settings = runSettings?.SettingsXml; if (settings == null) { runSettingsManager.AddDefaultRunSettings(); settings = runSettings?.SettingsXml; } var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings); if (dataCollectionRunSettings == null) { dataCollectionRunSettings = new DataCollectionRunSettings(); } var XmlDocument = new XmlDocument(); var outernode = XmlDocument.CreateElement("Configuration"); var node = XmlDocument.CreateElement("ResultsDirectory"); outernode.AppendChild(node); node.InnerText = resultsDirectory; foreach (var item in dataCollectionRunSettings.DataCollectorSettingsList) { if (item.FriendlyName.Equals(BlameFriendlyName)) { item.Configuration = outernode; } } runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml); }
/// <summary> /// Initialize blame. /// </summary> /// <param name="enableCrashDump">Enable dump.</param> /// <param name="blameParameters">Blame parameters.</param> private void InitializeBlame(bool enableCrashDump, bool enableHangDump, Dictionary <string, string> collectDumpParameters) { // Add Blame Logger LoggerUtilities.AddLoggerToRunSettings(BlameFriendlyName, null, this.runSettingsManager); // Add Blame Data Collector CollectArgumentExecutor.AddDataCollectorToRunSettings(BlameFriendlyName, this.runSettingsManager, this.fileHelper); // Add default run settings if required. if (this.runSettingsManager.ActiveRunSettings?.SettingsXml == null) { this.runSettingsManager.AddDefaultRunSettings();; } var settings = this.runSettingsManager.ActiveRunSettings?.SettingsXml; // Get results directory from RunSettingsManager var resultsDirectory = GetResultsDirectory(settings); // Get data collection run settings. Create if not present. var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings); if (dataCollectionRunSettings == null) { dataCollectionRunSettings = new DataCollectionRunSettings(); } // Create blame configuration element. var XmlDocument = new XmlDocument(); var outernode = XmlDocument.CreateElement("Configuration"); var node = XmlDocument.CreateElement("ResultsDirectory"); outernode.AppendChild(node); node.InnerText = resultsDirectory; // Add collect dump node in configuration element. if (enableCrashDump) { var dumpParameters = collectDumpParameters .Where(p => new[] { "CollectAlways", "DumpType" }.Contains(p.Key)) .ToDictionary(p => p.Key, p => p.Value); if (!dumpParameters.ContainsKey("DumpType")) { dumpParameters.Add("DumpType", "Full"); } AddCollectDumpNode(dumpParameters, XmlDocument, outernode); } // Add collect hang dump node in configuration element. if (enableHangDump) { var hangDumpParameters = collectDumpParameters .Where(p => new[] { "TestTimeout", "HangDumpType" }.Contains(p.Key)) .ToDictionary(p => p.Key, p => p.Value); if (!hangDumpParameters.ContainsKey("TestTimeout")) { hangDumpParameters.Add("TestTimeout", TimeSpan.FromHours(1).TotalMilliseconds.ToString()); } if (!hangDumpParameters.ContainsKey("HangDumpType")) { hangDumpParameters.Add("HangDumpType", "Full"); } AddCollectHangDumpNode(hangDumpParameters, XmlDocument, outernode); } // Add blame configuration element to blame collector. foreach (var item in dataCollectionRunSettings.DataCollectorSettingsList) { if (item.FriendlyName.Equals(BlameFriendlyName)) { item.Configuration = outernode; } } // Update run settings. runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml); }
/// <inheritdoc /> public void Initialize(string argument) { // Add this enabled data collectors list, this will ensure Code Coverage isn't disabled when other DCs are configured using /Collect. CollectArgumentExecutor.AddDataCollectorToRunSettings(argument, this.runSettingsManager); }
/// <summary> /// Initializes with the argument that was provided with the command. /// </summary> /// <param name="argument">Argument that was provided with the command.</param> public void Initialize(string argument) { bool isDumpEnabled = false; if (!string.IsNullOrWhiteSpace(argument) && argument.Equals(Constants.BlameCollectDumpKey, StringComparison.OrdinalIgnoreCase)) { if (this.environment.OperatingSystem == PlatformOperatingSystem.Windows && this.environment.Architecture != PlatformArchitecture.ARM64 && this.environment.Architecture != PlatformArchitecture.ARM) { isDumpEnabled = true; } else { Output.Warning(false, CommandLineResources.BlameCollectDumpNotSupportedForPlatform); } } // Add Blame Logger EnableLoggerArgumentExecutor.AddLoggerToRunSettings(BlameFriendlyName, this.runSettingsManager); // Add Blame Data Collector CollectArgumentExecutor.AddDataCollectorToRunSettings(BlameFriendlyName, this.runSettingsManager); // Get results directory from RunSettingsManager var runSettings = this.runSettingsManager.ActiveRunSettings; string resultsDirectory = null; if (runSettings != null) { try { RunConfiguration runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings.SettingsXml); resultsDirectory = RunSettingsUtilities.GetTestResultsDirectory(runConfiguration); } catch (SettingsException se) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("EnableBlameArgumentProcessor: Unable to get the test results directory: Error {0}", se); } } } // Add configuration element var settings = runSettings?.SettingsXml; if (settings == null) { runSettingsManager.AddDefaultRunSettings(); settings = runSettings?.SettingsXml; } var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings); if (dataCollectionRunSettings == null) { dataCollectionRunSettings = new DataCollectionRunSettings(); } var XmlDocument = new XmlDocument(); var outernode = XmlDocument.CreateElement("Configuration"); var node = XmlDocument.CreateElement("ResultsDirectory"); outernode.AppendChild(node); node.InnerText = resultsDirectory; if (isDumpEnabled) { var dumpNode = XmlDocument.CreateElement(Constants.BlameCollectDumpKey); outernode.AppendChild(dumpNode); } foreach (var item in dataCollectionRunSettings.DataCollectorSettingsList) { if (item.FriendlyName.Equals(BlameFriendlyName)) { item.Configuration = outernode; } } runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml); }