// Copyright Keysight Technologies 2012-2019 // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, you can obtain one at http://mozilla.org/MPL/2.0/. using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using System.Xml.Serialization; using OpenTap.Translation; namespace OpenTap { /// /// Settings class containing user-configurable platform options. /// [Display("Engine", "Engine Settings")] [HelpLink(@"EditorHelp.chm::/Configurations/Engine Configuration.html")] public class EngineSettings : ComponentSettings { /// /// Enum to represent choices for setting. /// [Flags] public enum AbortTestPlanType { /// If a step completes with verdict 'Fail', the test plan execution should be aborted. [Display("Break On Fail", "Issue a break when step completes with verdict 'Fail'.")] Step_Fail = 1, /// If a step completes with verdict 'Error', the test plan execution should be aborted. [Display("Break On Error", "Issue a break when step completes with an error.")] Step_Error = 2, /// If a step completes with verdict 'Inconclusive', the test plan execution should be aborted. [Display("Break On Inconclusive", "Issue a break when step completes with an inconclusive verdict.")] Step_Inconclusive = 4, /// If a step completes with verdict 'Pass', the test plan execution should be aborted. [Display("Break On Pass", "Issue a break when step completes with a pass verdict.")] Step_Pass = 8, } /// /// Where the session logs are saved. Must be a valid path. /// [Display("Log Path", Group: "General", Order: 1, Description: "Where to save the session log file. This setting only takes effect after restart.")] [FilePath(FilePathAttribute.BehaviorChoice.Save)] [HelpLink(@"EditorHelp.chm::/Configurations/Using Tags and Variables in File Names.html")] public MacroString SessionLogPath { get; set; } /// /// Controls whether the engine should propagate a request for metadata. /// [Display("Allow Metadata Prompt", Group: "General", Order: 2, Description: "When the test plan starts, prompt the user for data specified by the plugin to associate with the results.")] public bool PromptForMetaData { get; set; } /// /// Configures the engine to stop the test plan run if a step fails or causes an error. /// [Display("Test Plan Break Conditions", Group: "General", Order: 1, Description: "Specifies break conditions for the test plan execution. Break Conditions can also be specified on each test step.")] public AbortTestPlanType AbortTestPlan { get; set; } /// /// Gets or sets the limit for step runs to be added to the summary. /// [Display("Summary Test Step Limit", Group: "General", Order: 0, Description: "The maximum number of steps to include in the test plan summary")] public int SummaryTestStepLimit { get; set; } = 10_000; /// /// Name of the operator. This name will be saved along with the results. /// [Display("Name", Group: "Operator", Order: 20, Description: "Name of the operator. This name will be saved along with the results.")] [MetaData] public string OperatorName { get; set; } /// /// Name of the test station. This name will be saved along with the results. /// [Display("Station", Group: "Operator", Order: 21, Description: "Name of the test station. This name will be saved along with the results.")] [MetaData] public string StationName { get; set; } /// /// Gets or sets the maximum allowed latency for result propagation. When the limit is reached, the test plan run pauses while the results are propagated to the Result Listeners. /// Result processing time is an estimated value based on previous processing delays. /// [Display("Result Latency Limit", Group: "Advanced", Collapsed: true, Order: 100.1, Description: "The maximum allowed latency for result propagation. Reaching this limit will result in a temporary pause in the test plan while the results are being propagated to the ResultListeners. Result processing time is an estimated value based on previous processing delays.")] [Unit("s")] [Browsable(false)] public double ResultLatencyLimit { get; set; } /// /// True, if there is more than one log timestamping type. /// [XmlIgnore] [Browsable(false)] public bool HasMultipleTimestampers { get { return PluginManager.GetPlugins().Count > 1; } } /// /// Sets the log timestamp mechanism. /// [Display("Log Timestamping", Group: "General", Order: 10, Description: "Which timestamping mechanism to use in the log.")] [PluginTypeSelector] [EnabledIf("HasMultipleTimestampers", true, HideIfDisabled = true)] public Diagnostic.ILogTimestampProvider LogTimestamper { get { return Log.Timestamper; } set { Log.Timestamper = value; } } /// /// Sets up some default values for the various settings. /// User code should use EngineSettings.Current to access the singleton instead of constructing a new object. /// public EngineSettings() { SessionLogPath = new MacroString { Text = "SessionLogs/SessionLog .txt" }; ResultLatencyLimit = 3.0; OperatorName = Environment.GetEnvironmentVariable("USERNAME") ?? Environment.GetEnvironmentVariable("USER") ?? ""; StationName = Environment.MachineName; // Set OpenTAP to abort on step error by default. AbortTestPlan = AbortTestPlanType.Step_Error; PromptForMetaData = false; ResourceManagerType = new ResourceTaskManager(); } /// Where the test executive was started from. public static string StartupDir { get { return Environment.GetEnvironmentVariable("STARTUP_DIR"); } set { Environment.SetEnvironmentVariable("STARTUP_DIR", value); } } /// /// /// [PluginTypeSelector] [Display("Resource Strategy", Group: "General", Order: 12, Description: "Selects which strategy to use for opening resources while the test plan is executing.")] public IResourceManager ResourceManagerType { get; set; } /// Loads a new working directory and sets up environment variables important to OpenTAP. /// public static void LoadWorkingDirectory(string newWorkingDirectory) { EngineSettings.StartupDir = System.IO.Directory.GetCurrentDirectory(); System.IO.Directory.SetCurrentDirectory(newWorkingDirectory); } static EngineSettings() { StartupDir = System.IO.Directory.GetCurrentDirectory(); Environment.SetEnvironmentVariable("ENGINE_DIR", System.IO.Path.GetDirectoryName(typeof(TestPlan).Assembly.Location)); } /// /// The currently selected language. Defaults to Invariant. /// [Browsable(false)] [XmlIgnore] public CultureInfo Language { get => language; set => language = value ?? throw new ArgumentNullException(nameof(value)); } private CultureInfo language = TranslationManager.NeutralLanguage; /// /// The list of available languages. This is based on the currently installed .resx files. /// [Browsable(false)] [XmlIgnore] public IEnumerable AvailableLanguages => TranslationManager.SupportedLanguages.Select(TranslationManager.CultureAsString); /// /// Whether or not the language selector should be visible. /// [Browsable(false)] [XmlIgnore] public bool LanguageSelectorEnabled => TranslationManager.SupportedLanguages.Any(x => !TranslationManager.NeutralLanguage.Equals(x)); /// /// The currently selected language. Defaults to Invariant. /// [Display("Language", "The currently selected language.", Group: "Language", Order: 1000)] [AvailableValues(nameof(AvailableLanguages))] [EnabledIf(nameof(LanguageSelectorEnabled), HideIfDisabled = true)] public string LanguageString { get => TranslationManager.CultureAsString(Language); set { if (TranslationManager.SupportedLanguages.FirstOrDefault(x => TranslationManager.CultureAsString(x) == value) is { } newLanguage) Language = newLanguage; } } } }