Beispiel #1
0
        /// <summary>
        /// Explores the P# program for bugs.
        /// </summary>
        private static void FindBugs()
        {
            Output.Print("... Using '{0}' strategy", AnalysisContext.Strategy);

            Task task = new Task(() =>
            {
                for (int i = 0; i < Configuration.SchedulingIterations; i++)
                {
                    if (SCTEngine.ShouldPrintIteration(i + 1))
                    {
                        Output.Print("..... Iteration #{0}", i + 1);
                    }

                    PSharpRuntime.BugFinder = new Scheduler(SCTEngine.Strategy);

                    StringWriter sw = null;
                    if (Configuration.Verbose < 2)
                    {
                        sw = SCTEngine.RedirectOutput();
                        SCTEngine.HasRedirectedOutput = true;
                    }

                    // Start the test and wait for it to terminate.
                    AnalysisContext.TestMethod.Invoke(null, null);
                    PSharpRuntime.WaitMachines();

                    // Runs the liveness checker to find any liveness property violations.
                    // Requires that no bug has been found and the scheduler terminated
                    // before reaching the depth bound.
                    if (Configuration.CheckLiveness &&
                        !PSharpRuntime.BugFinder.BugFound)
                    {
                        PSharpRuntime.LivenessChecker.Run();
                    }

                    if (SCTEngine.HasRedirectedOutput)
                    {
                        SCTEngine.ResetOutput();
                    }

                    SCTEngine.ExploredSchedules++;
                    SCTEngine.ExploredDepth = PSharpRuntime.BugFinder.SchedulingPoints;

                    if (PSharpRuntime.BugFinder.BugFound)
                    {
                        SCTEngine.NumOfFoundBugs++;
                        SCTEngine.BugReport = PSharpRuntime.BugFinder.BugReport;
                    }
                    else
                    {
                        SCTEngine.BugReport = "";
                    }

                    if (SCTEngine.Strategy.HasFinished())
                    {
                        break;
                    }

                    SCTEngine.Strategy.Reset();
                    if (!Configuration.FullExploration &&
                        (SCTEngine.NumOfFoundBugs > 0 || Configuration.PrintTrace))
                    {
                        if (sw != null && !Configuration.SuppressTrace)
                        {
                            SCTEngine.PrintTrace(sw);
                        }

                        break;
                    }
                }
            });

            Profiler.StartMeasuringExecutionTime();
            task.Start();

            try
            {
                if (Configuration.AnalysisTimeout > 0)
                {
                    task.Wait(Configuration.AnalysisTimeout * 1000);
                }
                else
                {
                    task.Wait();
                }
            }
            catch (AggregateException)
            {
                if (SCTEngine.HasRedirectedOutput)
                {
                    SCTEngine.ResetOutput();
                }

                ErrorReporter.ReportAndExit("Internal systematic testing exception. " +
                                            "Please send a bug report to the developers.");
            }
            finally
            {
                Profiler.StopMeasuringExecutionTime();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Runs the P# systematic testing engine.
 /// </summary>
 public static void Run()
 {
     SCTEngine.FindBugs();
     SCTEngine.Report();
     SCTEngine.Cleanup();
 }