Beispiel #1
0
 public override void Run()
 {
     // Delay was added so that behavior could be observed in the Timing Analyzer.
     TapThread.Sleep(100);
     RunChildSteps(); // If step has child steps.
     UpgradeVerdict(Verdict.Pass);
 }
 public override void Open()
 {
     base.Open();
     TapThread.Sleep(50);
     isOpen = true;
     Log.Info(Name + " Opened.");
 }
Beispiel #3
0
        public override void Run()
        {
            // There are four levels of log messages Info, Warning, Error, Debug.
            MyLog.Info("Info from Run");
            for (int i = 0; i < 10; i++)
            {
                MyLog.Debug("Debug {0} from Run", i); // MyLog.X works like string.Format with regards to arguments.
            }
            MyLog.Warning("Warning from Run");
            MyLog.Error("Error from Run");

            // The Log can accept a Stopwatch Object to be used for timing analysis.
            Stopwatch sw1 = Stopwatch.StartNew();

            TapThread.Sleep(100);
            MyLog.Info(sw1, "Info from Run");

            Stopwatch sw2 = Stopwatch.StartNew();

            TapThread.Sleep(200);
            MyLog.Error(sw2, "Error from step");

            // Tracebar can be used to show results in the MyLog.
            var traceBar = new TraceBar();

            traceBar.LowerLimit = -3.0;
            for (var i = -2; i < 11; i++)
            {
                traceBar.UpperLimit = i < 5 ? 3 : 15;
                // GetBar returns a string with value, low limit, a dashed line
                // indicating magnitude, the upper limit, and (if failing), a fail indicator.
                string temp = traceBar.GetBar(i);
                MyLog.Info("MyResult: " + temp);
                TapThread.Sleep(200);
            }
            // Sample output shown below.
            //   MyResult: 2.00 - 3-------------------------|-----  3
            //   MyResult: 3.00 - 3------------------------------ | 3
            //   MyResult: 4.00 - 3------------------------------ > 3  Fail
            //   MyResult: 5.00 - 3------------ -| -----------------15
            //   MyResult: 6.00 - 3-------------- -| ---------------15

            // TraceBar remembers if any results failed, so it can be used for the verdict.
            UpgradeVerdict(traceBar.CombinedVerdict);

            // The log also supports showing stack traces.
            // Useful for debugging.
            try
            {
                throw new Exception("My exception");
            }
            catch (Exception e)
            {
                MyLog.Error("Caught exception: '{0}'", e.Message);
                MyLog.Debug(e); // Prints the stack trace to the MyLog.
            }
        }
Beispiel #4
0
 public override void Run()
 {
     TapThread.Sleep((int)(1000 * Duration));
     for (double i = 0; i < NResults; i++)
     {
         Results.Publish("UnitTest", new List <string> {
             "Channel", "Power [dBm]"
         }, Math.Sin(i) /*,Math.Cos(i)*/);
     }
     Verdict = Verdict.Pass;
 }
Beispiel #5
0
        public override void Run()
        {
            TapThread.Sleep(RunDelay * 1000);
            Results.Defer(() =>
            {
                TapThread.Sleep(DeferDelay * 1000);

                // You can also publish results here for example.
                Results.Publish("MyTestResult", new List <string> {
                    "Test"
                }, 1);
            });
        }
Beispiel #6
0
        public override void Run()
        {
            for (var i = 0; i < Count; i++)
            {
                // Do work.
                TapThread.Sleep(TimeSpan.FromSeconds(DelaySecs));

                // Offer GUI to break at this point.
                OfferBreak();
            }

            // GUI can automatically break when running its child steps.
            RunChildSteps();
        }
Beispiel #7
0
        public override void Run()
        {
            Random rand   = new Random();
            var    watch2 = System.Diagnostics.Stopwatch.StartNew();

            Log.Info("{2} [{0}/{1}]", 0, Fraction, PreMessage);
            for (int i = Start; i < Fraction; i += Step)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                TapThread.Sleep((int)(1000 * Sleep + rand.Next() % 100));
                Log.Debug("{2} [{0}/{1}]", i, Fraction, PreMessage);
            }
            Log.Debug("{1} [{0}/{0}] Completed", Fraction, PreMessage);
            Log.Info(watch2, "Simulating progress...");
        }
Beispiel #8
0
 public override void Run()
 {
     Results.Defer(() =>
     {
         TapThread.Sleep(WaitMs);
         if (Throw)
         {
             throw new InvalidOperationException("Intentional");
         }
         else
         {
             UpgradeVerdict(Verdict.Error);
         }
     });
 }
Beispiel #9
0
        public (string Stdout, string Stderr, int ExitCode) Build()
        {
            using (var writer = new StreamWriter(Path.Combine(ProjectBuildTest.WorkingDirectory, Filename)))
                writer.Write(this.ToString());

            if (OperatingSystem.Current != OperatingSystem.Windows)
            {
                // // The MSBuild generator is sometimes too eager to skip steps on Linux -- make sure targets are run
                if (File.Exists(ProjectBuildTest.OutputFile))
                {
                    File.Delete(ProjectBuildTest.OutputFile);
                }
            }

            var process = new Process
            {
                StartInfo =
                {
                    FileName               = "dotnet",
                    Arguments              = $"build {Filename} --verbosity normal",
                    WorkingDirectory       = ProjectBuildTest.WorkingDirectory,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            process.Start();
            var timeLimit = TimeSpan.FromSeconds(60);

            var stdout = new StringBuilder();
            var stderr = new StringBuilder();

            // For some reason, the process doesn't exit properly with WaitForExit
            while (process.HasExited == false)
            {
                if (DateTime.Now - process.StartTime > timeLimit)
                {
                    break;
                }

                TapThread.Sleep(TimeSpan.FromSeconds(1));
            }


            return(process.StandardOutput.ReadToEnd(), process.StandardError.ReadToEnd(), process.ExitCode);
        }
Beispiel #10
0
        public static TapProcessContainer StartFromArgs(string args, TimeSpan timeOutAfter)
        {
            Process proc = new Process();

            var container = new TapProcessContainer {
                TapProcess = proc
            };


            var file  = Path.GetDirectoryName(typeof(PluginManager).Assembly.Location);
            var files = new[] { Path.Combine(file, "tap.exe"), Path.Combine(file, "tap"), Path.Combine(file, "tap.dll") };

            global::OpenTap.Log.CreateSource("test").Debug($"location: {file}");
            var program = files.First(File.Exists);

            if (program.Contains(".dll"))
            {
                program = "dotnet";
                args    = $"\"{file}/tap.dll\" " + args;
            }

            proc.StartInfo = new ProcessStartInfo(program, args)
            {
                UseShellExecute        = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
            };
            proc.StartInfo.UseShellExecute = false;

            container.go();
            TapThread.Start(() =>
            {
                TapThread.Sleep(timeOutAfter);
                proc.Kill();
            });
            return(container);
        }
Beispiel #11
0
 public override void Run()
 {
     TapThread.Sleep(TimeSpan.FromSeconds(DelaySec));
 }
Beispiel #12
0
        /// <summary> Enqueue a new piece of work to be handled in the future. </summary>
        /// <param name="f"></param>
        public void EnqueueWork(Action f)
        {
            void threadGo()
            {
                try
                {
                    var awaitArray = new WaitHandle[] { addSemaphore.AvailableWaitHandle, cancel.Token.WaitHandle };
                    while (true)
                    {
retry:
                        awaitArray[1] = cancel.Token.WaitHandle;
                        int thing = 0;
                        if (longRunning)
                        {
                            thing = WaitHandle.WaitAny(awaitArray);
                        }
                        else
                        {
                            thing = WaitHandle.WaitAny(awaitArray, Timeout);
                        }
                        if (thing == 0 && !addSemaphore.Wait(0))
                        {
                            goto retry;
                        }
                        bool ok = thing == 0;

                        if (!ok)
                        {
                            if (cancel.IsCancellationRequested == false && longRunning)
                            {
                                continue;
                            }
                            lock (threadCreationLock)
                            {
                                if (workItems.Count > 0)
                                {
                                    goto retry;
                                }
                                break;
                            }
                        }


                        Action run = null;
                        while (!workItems.TryDequeue(out run))
                        {
                            Thread.Yield();
                        }
                        if (average != null)
                        {
                            var sw = Stopwatch.StartNew();
                            run();
                            average.PushTimeSpan(sw.Elapsed);
                        }
                        else
                        {
                            run();
                        }
                        Interlocked.Decrement(ref countdown);
                    }
                }
                finally
                {
                    lock (threadCreationLock)
                    {
                        threadCount--;
                    }
                }
            }

            while (addSemaphore.CurrentCount >= semaphoreMaxCount - 10)
            {
                // #4246: this is incredibly rare, but can happen if millions of results are pushed at once.
                //        the solution is to just slow a bit down when it happens.
                //        100 ms sleep is OK, because it needs to do around 1M things before it's idle.
                TapThread.Sleep(100);
            }
            Interlocked.Increment(ref countdown);
            workItems.Enqueue(f);
            addSemaphore.Release();

            if (threadCount == 0)
            {
                lock (threadCreationLock)
                {
                    if (threadCount == 0)
                    {
                        TapThread.Start(threadGo, Name);
                        threadCount++;
                    }
                }
            }
        }
Beispiel #13
0
 public override void PostPlanRun()
 {
     // Delay was added so that behavior could be observed in the Timing Analyzer.
     TapThread.Sleep(100);
     base.PostPlanRun();
 }
Beispiel #14
0
 public override void Run()
 {
     TapThread.Sleep(Convert.ToInt32(Delay * 1000));
 }
Beispiel #15
0
 public override void PrePlanRun()
 {
     base.PrePlanRun();
     TapThread.Sleep(PrePlanDelay * 1000);
 }
Beispiel #16
0
 public override void PostPlanRun()
 {
     TapThread.Sleep(PostPlanDelay * 1000);
     base.PostPlanRun();
 }
Beispiel #17
0
 public override void Run()
 {
     TapThread.Sleep(DelayMs);
 }
Beispiel #18
0
 public override void PostPlanRun()
 {
     base.PostPlanRun();
     TapThread.Sleep(TimeSpan.FromSeconds(PostRunDelay));
 }
Beispiel #19
0
 public override void Run()
 {
     Sem.Release();
     TapThread.Sleep(TimeSpan.MaxValue);
 }
Beispiel #20
0
 public override void Run()
 {
     TapThread.Sleep(TimeSpan.FromSeconds(RunDelay));
     Results.Defer(() => TapThread.Sleep(TimeSpan.FromSeconds(DeferDelay)));
 }