internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager, IFileHelper fileHelper)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings       = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings) ?? new DataCollectionRunSettings();
            var inProcDataCollectionRunSettings = XmlRunSettingsUtilities.GetInProcDataCollectionRunSettings(settings)
                                                  ?? new DataCollectionRunSettings(
                Constants.InProcDataCollectionRunSettingsName,
                Constants.InProcDataCollectorsSettingName,
                Constants.InProcDataCollectorSettingName);

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);

            if (string.Equals(argument, CoverletConstants.CoverletDataCollectorFriendlyName, StringComparison.OrdinalIgnoreCase))
            {
                // Add in-proc data collector to runsettings if coverlet code coverage is enabled
                EnableCoverletInProcDataCollector(argument, inProcDataCollectionRunSettings, runSettingsManager, fileHelper);
                runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.InProcDataCollectionRunSettingsName, inProcDataCollectionRunSettings.ToXml().InnerXml);
            }
        }
Exemplo n.º 2
0
        internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings);

            if (dataCollectionRunSettings == null)
            {
                dataCollectionRunSettings = new DataCollectionRunSettings();
            }
            else
            {
                // By default, all data collectors present in run settings are enabled, if enabled attribute is not specified.
                // So explicitely disable those data collectors and enable those which are specified.
                DisableUnConfiguredDataCollectors(dataCollectionRunSettings);
            }

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);
        }
        /// <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);
        }
Exemplo n.º 4
0
        internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings);

            if (dataCollectionRunSettings == null)
            {
                dataCollectionRunSettings = new DataCollectionRunSettings();
            }

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);
        }
Exemplo n.º 5
0
        /// <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);
        }
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add logger to runsettings.
        /// </summary>
        /// <param name="loggerArgument"></param>
        /// <param name="runSettingsManager"></param>
        public static void AddLoggerToRunSettings(string loggerArgument, IRunSettingsProvider runSettingsManager)
        {
            if (string.IsNullOrWhiteSpace(loggerArgument))
            {
                HandleInvalidArgument(loggerArgument);
            }

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var    loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(settings) ?? new LoggerRunSettings();
            string loggerIdentifier  = null;
            Dictionary <string, string> parameters = null;
            var parseSucceeded = LoggerUtilities.TryParseLoggerArgument(loggerArgument, out loggerIdentifier, out parameters);

            if (parseSucceeded)
            {
                var logger = default(LoggerSettings);

                try
                {
                    // Logger as uri in command line.
                    var loggerUri = new Uri(loggerIdentifier);
                    logger = new LoggerSettings
                    {
                        Uri       = loggerUri,
                        IsEnabled = true
                    };
                }
                catch (UriFormatException)
                {
                    // Logger as friendlyName in command line.
                    logger = new LoggerSettings
                    {
                        FriendlyName = loggerIdentifier,
                        IsEnabled    = true
                    };
                }

                // Converting logger console params to Configuration element
                if (parameters != null && parameters.Count > 0)
                {
                    var XmlDocument = new XmlDocument();
                    var outerNode   = XmlDocument.CreateElement("Configuration");
                    foreach (KeyValuePair <string, string> entry in parameters)
                    {
                        var node = XmlDocument.CreateElement(entry.Key);
                        node.InnerText = entry.Value;
                        outerNode.AppendChild(node);
                    }

                    logger.Configuration = outerNode;
                }

                // Remove existing logger.
                var existingLoggerIndex = loggerRunSettings.GetExistingLoggerIndex(logger);
                if (existingLoggerIndex >= 0)
                {
                    loggerRunSettings.LoggerSettingsList.RemoveAt(existingLoggerIndex);
                }

                loggerRunSettings.LoggerSettingsList.Add(logger);
            }
            else
            {
                HandleInvalidArgument(loggerArgument);
            }

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.LoggerRunSettingsName, loggerRunSettings.ToXml().InnerXml);
        }