internal void HandleDeferredEventStreamInternal(IEnumerable <DeferredEvent> events)
        {
            // now make all those times relative to the active event
            LogStep startStep = m_Stack.Peek();

            m_ShouldOverrideWallTimer = true;
            foreach (DeferredEvent e in events)
            {
                m_WallTimerOverride = e.Time + startStep.StartTime;
                if (e.Type == DeferredEventType.Begin)
                {
                    BeginBuildStep(e.Level, e.Name, false);
                    if (!string.IsNullOrEmpty(e.Context))
                    {
                        AddEntry(e.Level, e.Context);
                    }
                }
                else if (e.Type == DeferredEventType.End)
                {
                    EndBuildStep();
                }
                else
                {
                    AddEntry(e.Level, e.Name);
                }
            }
            m_ShouldOverrideWallTimer = false;

            LogStep stopStep = m_Stack.Peek();

            if (stopStep != startStep)
            {
                throw new Exception("Deferred events did not line up as expected");
            }
        }
示例#2
0
        public void TestNameFormat2()
        {
            var plan   = new TestPlan();
            var repeat = new RepeatStep {
                Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count
            };

            repeat.Name = "Repeat : {Iteration}";
            plan.ChildTestSteps.Add(repeat);
            var logStep = new LogStep();

            repeat.ChildTestSteps.Add(logStep);
            var log = new TestTraceListener();

            Log.AddListener(log);
            var run = plan.Execute();

            Assert.AreEqual(Verdict.NotSet, run.Verdict);
            Log.RemoveListener(log);
            var thelog = log.GetLog();

            for (int i = 0; i < repeat.Count; i++)
            {
                var str = string.Format("Repeat : {0} of {1}", i, repeat.Count);
                Assert.IsTrue(thelog.Contains(str));
            }
        }
        private static void EndBuildStepInternal(BuildLog log)
        {
            Debug.Assert(log.m_Stack.Count > 1);
            LogStep node = log.m_Stack.Pop();

            node.Complete(log.GetWallTime());

            if (node.isThreaded)
            {
                foreach (BuildLog subLog in log.m_ThreadedLogs.Values)
                {
                    if (subLog != log)
                    {
                        OffsetTimesR(subLog.Root, node.StartTime);
                        if (subLog.Root.HasChildren)
                        {
                            node.Children.AddRange(subLog.Root.Children);
                        }

                        if (subLog.Root.HasEntries)
                        {
                            node.Entries.AddRange(subLog.Root.Entries);
                        }
                    }
                }
                log.m_ThreadedLogs.Dispose();
                log.m_ThreadedLogs = null;
            }
        }
示例#4
0
 public BuildLog()
 {
     m_WallTimer = Stopwatch.StartNew();
     m_Root      = new LogStep();
     m_Stack     = new Stack <LogStep>();
     m_Stack.Push(m_Root);
 }
示例#5
0
        public static IntegrationFlowBuilder <TBody> Log <TBody>(IBuildableFlow sourceFlow, IntegrationFlowBuilder <TBody> builder, Action <Integration <TBody>, ILogger> action, IServiceProvider serviceProvider)
        {
            var logStep = new LogStep <TBody>(serviceProvider.GetRequiredService <ILoggerFactory>()
                                              .CreateLogger(typeof(LogStep <TBody>)), action);

            sourceFlow.AddStep(logStep);
            return(builder);
        }
示例#6
0
        public DecisionsFramework.Design.Flow.FlowStep ConvertStep(ConversionData allConvertData, ConvertedStep stepToConvert)
        {
            LogStep logStep = new LogStep();

            logStep.Category = stepToConvert.StepProperties.FirstOrDefault(x => x.Name == "Category").ConstantValue;

            string logLevel = stepToConvert.StepProperties.FirstOrDefault(x => x.Name == "Type").ConstantValue;

            switch (logLevel)
            {
            case "Debug":
                logStep.Type = LogStep.LogType.Debug;
                break;

            case "Error":
                logStep.Type = LogStep.LogType.Error;
                break;

            case "Info":
                logStep.Type = LogStep.LogType.Info;
                break;

            case "Fatal":
                logStep.Type = LogStep.LogType.Fatal;
                break;

            case "Warn":
                logStep.Type = LogStep.LogType.Warn;
                break;

            default:
                logStep.Type = LogStep.LogType.Info;
                break;
            }

            FlowStep result = new FlowStep(logStep);

            result.Name = stepToConvert.StepName;

            MergeStringInputMapping text = new MergeStringInputMapping()
            {
                //ConstantInputMapping text = new ConstantInputMapping();
                InputDataName   = "Value",
                MergeResultType = DecisionsFramework.Utilities.Data.MergeDataType.PlainText,
                MergeString     = stepToConvert.InputData.FirstOrDefault(x => x.Name == "Value").ConstantValue
            };

            result.AddInputMapping(text);

            return(result);
        }
        private static void BeginBuildStepInternal(BuildLog log, LogLevel level, string stepName, bool multiThreaded)
        {
            LogStep node = new LogStep();

            node.Level     = level;
            node.Name      = stepName;
            node.StartTime = log.GetWallTime();
            node.ThreadId  = Thread.CurrentThread.ManagedThreadId;
            log.m_Stack.Peek().Children.Add(node);
            log.m_Stack.Push(node);
            if (multiThreaded)
            {
                Debug.Assert(log.m_ThreadedLogs == null);
                log.m_ThreadedLogs       = new ThreadLocal <BuildLog>(true);
                log.m_ThreadedLogs.Value = log;
                node.isThreaded          = true;
            }
        }
 private static void OffsetTimesR(LogStep step, double offset)
 {
     step.StartTime += offset;
     if (step.HasEntries)
     {
         for (int i = 0; i < step.Entries.Count; i++)
         {
             LogEntry e = step.Entries[i];
             e.Time          = e.Time + offset;
             step.Entries[i] = e;
         }
     }
     if (step.HasChildren)
     {
         foreach (LogStep subStep in step.Children)
         {
             OffsetTimesR(subStep, offset);
         }
     }
 }
        void Init(bool onThread)
        {
            m_WallTimer = Stopwatch.StartNew();
            m_Root      = new LogStep();
            m_Stack     = new Stack <LogStep>();
            m_Stack.Push(m_Root);

            AddMetaData("Date", DateTime.Now.ToString());

            if (!onThread)
            {
                AddMetaData("UnityVersion", UnityEngine.Application.unityVersion);
#if UNITY_2019_2_OR_NEWER // PackageManager package inspection APIs didn't exist until 2019.2
                PackageManager.PackageInfo info = PackageManager.PackageInfo.FindForAssembly(typeof(BuildLog).Assembly);
                if (info != null)
                {
                    AddMetaData(info.name, info.version);
                }
#endif
            }
        }
示例#10
0
        private static void EndBuildStepInternal(BuildLog log)
        {
            Debug.Assert(log.m_Stack.Count > 1);
            LogStep node = log.m_Stack.Pop();

            node.Complete(log.m_WallTimer.Elapsed.TotalMilliseconds);

            if (node.isThreaded)
            {
                foreach (var subLog in log.m_ThreadedLogs.Values)
                {
                    if (subLog != log)
                    {
                        if (subLog.Root.HasChildren)
                        {
                            foreach (LogStep step in subLog.Root.Children)
                            {
                                step.StartTime += node.StartTime;
                            }
                            node.Children.AddRange(subLog.Root.Children);
                        }
                        if (subLog.Root.HasEntries)
                        {
                            for (int i = 0; i < subLog.Root.Entries.Count; i++)
                            {
                                LogEntry e = subLog.Root.Entries[i];
                                e.Time = e.Time + node.StartTime;
                                subLog.Root.Entries[i] = e;
                            }
                            node.Entries.AddRange(subLog.Root.Entries);
                        }
                    }
                }
                log.m_ThreadedLogs.Dispose();
                log.m_ThreadedLogs = null;
            }
        }
示例#11
0
文件: Program.cs 项目: ZHJEE/OpenTAP
        static void Main()
        {
            // If you have plugins in directories different from the location of your TAP_PATH, then add those directories here.
            // PluginManager.DirectoriesToSearch.Add(@"C:\SomeOtherDirectory");

            // Start finding plugins.
            PluginManager.SearchAsync();

            // Point to log file to be used.
            SessionLogs.Initialize("console_log.txt");

            // Create a new Test Plan.
            TestPlan myTestPlan = new TestPlan();

            // All Test Plan steps are added as child steps.
            myTestPlan.ChildTestSteps.Add(new DelayStep {
                DelaySecs = .1, Name = "Delay1"
            });

            // Sequences can be created and added to TestPlan.
            SequenceStep mySequenceStep = new SequenceStep();

            mySequenceStep.ChildTestSteps.Add(new DelayStep {
                DelaySecs = .2, Name = "Delay2"
            });

            LogStep logStep = new LogStep
            {
                Name       = "SomeName",
                LogMessage = "Hello from myTestPlan at " + DateTime.Now.ToLongTimeString(),
                Severity   = LogSeverity.Info
            };

            mySequenceStep.ChildTestSteps.Add(logStep);

            // Sequences are added to the Test Plan like any other step.
            myTestPlan.ChildTestSteps.Add(mySequenceStep);

            // The Test Plan can be saved for later reuse.
            string myFilePath = Path.Combine(AssemblyDirectory, myTestPlan.Name + ".TapPlan");

            myTestPlan.Save(myFilePath);

            // Add any ResultListeners that should be used.
            // If not specified, a list of ResultListeners with a single LogResultListener will be created.
            // Alternatively, the ResultListeners could be defined in settings files.
            List <ResultListener> resultListeners = new List <ResultListener>();

            resultListeners.Add(new LogResultListener());
            //resultListeners.Add(new Keysight.OpenTap.Plugins.Csv.CsvResultListener());

            // Execute the TestPlan. This is the equivalent of the Run button in the TAP GUI.
            myTestPlan.Execute(resultListeners);

            // After the TestPlan has been run Macros, if used, can be expanded.
            SessionLogs.Rename(EngineSettings.Current.SessionLogPath.Expand(date: DateTime.Now));

            Console.WriteLine("This example builds a TestPlan programmatically.");
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
        public void SetValuesTest()
        {
            var delayStep1 = new DelayStep();
            var delayStep2 = new DelayStep();
            var logStep    = new LogStep();
            var logStep2   = new LogStep();
            var fileStep   = new MacroFilePathTestStep();
            var fileStep2  = new MacroFilePathTestStep();
            var ifstep     = new IfStep();

            fileStep.PathToThing.Text = "<TESTPLANDIR>\\asdasd";
            TestPlan plan = new TestPlan();

            plan.ChildTestSteps.Add(delayStep1);
            plan.ChildTestSteps.Add(delayStep2);
            plan.ChildTestSteps.Add(logStep);
            plan.ChildTestSteps.Add(logStep2);
            plan.ChildTestSteps.Add(fileStep);
            plan.ChildTestSteps.Add(fileStep2);
            plan.ChildTestSteps.Add(ifstep);
            ifstep.InputVerdict.Step     = delayStep2;
            ifstep.InputVerdict.Property = TypeData.GetTypeData(delayStep1).GetMember("Verdict");
            var delayInfo    = TypeData.GetTypeData(delayStep1);
            var logInfo      = TypeData.GetTypeData(logStep);
            var fileStepInfo = TypeData.GetTypeData(fileStep);

            plan.ExternalParameters.Add(delayStep1, delayInfo.GetMember("DelaySecs"));
            plan.ExternalParameters.Add(delayStep2, delayInfo.GetMember("DelaySecs"), "Time Delay");
            plan.ExternalParameters.Add(logStep, logInfo.GetMember("Severity"), Name: "Severity");
            plan.ExternalParameters.Add(logStep2, logInfo.GetMember("Severity"), Name: "Severity");
            plan.ExternalParameters.Add(fileStep, fileStepInfo.GetMember("PathToThing"), Name: "Path1");
            plan.ExternalParameters.Add(fileStep2, fileStepInfo.GetMember("PathToThing"), Name: "Path1");
            plan.ExternalParameters.Add(ifstep, TypeData.GetTypeData(ifstep).GetMember(nameof(IfStep.InputVerdict)), Name: "InputVerdict");
            for (int j = 0; j < 5; j++)
            {
                for (double x = 0.01; x < 10; x += 3.14)
                {
                    plan.ExternalParameters.Get("Time Delay").Value = x;
                    Assert.AreEqual(x, delayStep1.DelaySecs);
                    Assert.AreEqual(x, delayStep2.DelaySecs);
                }

                plan.ExternalParameters.Get("Severity").Value = LogSeverity.Error;
                Assert.AreEqual(LogSeverity.Error, logStep.Severity);
                Assert.AreEqual(LogSeverity.Error, logStep2.Severity);

                plan.ExternalParameters.Get("Path1").Value = plan.ExternalParameters.Get("Path1").Value;

                string planstr = null;
                using (var memstream = new MemoryStream())
                {
                    plan.Save(memstream);
                    planstr = Encoding.UTF8.GetString(memstream.ToArray());
                }
                Assert.IsTrue(planstr.Contains(@"Parameter=""Time Delay"""));
                Assert.IsTrue(planstr.Contains(@"Parameter=""Severity"""));
                Assert.IsTrue(planstr.Contains(@"Parameter=""Path1"""));

                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(planstr)))
                    plan = TestPlan.Load(memstream, planstr);

                delayStep1 = (DelayStep)plan.ChildTestSteps[0];
                delayStep2 = (DelayStep)plan.ChildTestSteps[1];
                logStep    = (LogStep)plan.ChildTestSteps[2];
                logStep2   = (LogStep)plan.ChildTestSteps[3];
                fileStep   = (MacroFilePathTestStep)plan.ChildTestSteps[4];
                fileStep2  = (MacroFilePathTestStep)plan.ChildTestSteps[5];
                ifstep     = (IfStep)plan.ChildTestSteps[6];
                Assert.IsTrue(fileStep2.PathToThing.Context == fileStep2);
                Assert.AreEqual(fileStep2.PathToThing.Text, fileStep.PathToThing.Text);
                Assert.AreEqual(delayStep2, ifstep.InputVerdict.Step);
            }
        }
示例#13
0
        public void BeforeOpenExceptionTest(Type managerType, Type exceptionType, Verdict expectedVerdict, bool withParallel)
        {
            EngineSettings.Current.ResourceManagerType = (IResourceManager)Activator.CreateInstance(managerType);
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };

            InstrumentSettings.Current.Add(instr1);
            try
            {
                TestPlan  plan  = new TestPlan();
                ITestStep step1 = new InstrumentTestStep()
                {
                    Instrument = instr1
                };
                if (withParallel)
                {
                    var par = new ParallelStep();
                    par.ChildTestSteps.Add(step1);
                    step1 = par;
                }
                plan.Steps.Add(step1);
                ITestStep lastStep = new LogStep()
                {
                    Name = "Last Step", LogMessage = "Last Step Ran"
                };
                plan.Steps.Add(lastStep);
                UnitTestingLockManager.Enable();
                UnitTestingLockManager.BeforeOpenEffect = r => throw (Exception)Activator.CreateInstance(exceptionType, new string[] { "Custom exception message" });
                var logListener = new TestTraceListener();
                Log.AddListener(logListener);
                //string logFileName = Path.Combine(Path.GetDirectoryName(PluginManager.GetOpenTapAssembly().Location), $"BeforeOpenExceptionTest({managerType},{exceptionType},{withParallel}).txt");
                //if (File.Exists(logFileName)) File.Delete(logFileName);
                //var fileListener = new FileTraceListener(logFileName);
                //Log.AddListener(fileListener);
                try
                {
                    var run = plan.Execute();
                    Assert.AreEqual(expectedVerdict, run.Verdict);
                }
                finally
                {
                    Log.RemoveListener(logListener);
                    //Log.RemoveListener(fileListener);
                    UnitTestingLockManager.Disable();
                }

                // We should have the custom exception message in the log
                StringAssert.Contains("Custom exception message", logListener.GetLog());

                if (expectedVerdict == Verdict.Error)
                {
                    StringAssert.IsMatch(": Error .+Custom exception message", logListener.GetLog());
                }
                else
                {
                    StringAssert.IsMatch(": Warning .+Custom exception message", logListener.GetLog());
                }

                // The last step should not have run:
                if (exceptionType == typeof(OperationCanceledException))
                {
                    StringAssert.DoesNotContain("Last Step Ran", logListener.GetLog());
                }
            }
            finally
            {
                InstrumentSettings.Current.Remove(instr1);
            }
        }