Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="context">AnalysisContext</param>
        private SCTEngine(AnalysisContext context)
        {
            this.AnalysisContext = context;

            this.NumOfFoundBugs = 0;
            this.BugReport = "";
            this.ExploredDepth = 0;
            this.ExploredSchedules = 0;
            this.PrintGuard = 1;

            if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.AnalysisContext);
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration = false;
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration = false;
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.MaceMC)
            {
                this.Strategy = new MaceMCStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration = false;
                this.AnalysisContext.Configuration.CheckLiveness = true;
                this.AnalysisContext.Configuration.CacheProgramState = false;
            }

            this.HasRedirectedConsoleOutput = false;
        }
Beispiel #2
0
        /// <summary>
        /// Setups the P# systematic testing engine.
        /// </summary>
        public static void Setup()
        {
            SCTEngine.NumOfFoundBugs    = 0;
            SCTEngine.BugReport         = "";
            SCTEngine.ExploredDepth     = 0;
            SCTEngine.ExploredSchedules = 0;
            SCTEngine.PrintGuard        = 1;

            if (AnalysisContext.Strategy == SchedulingStrategy.Random)
            {
                SCTEngine.Strategy = new RandomSchedulingStrategy(DateTime.Now.Millisecond);
            }
            else if (AnalysisContext.Strategy == SchedulingStrategy.DFS)
            {
                SCTEngine.Strategy            = new DFSSchedulingStrategy();
                Configuration.FullExploration = false;
            }

            if (!Configuration.Debug.Contains(DebugType.All) &&
                !Configuration.Debug.Contains(DebugType.Runtime))
            {
                Configuration.Debug.Add(DebugType.Runtime);
                SCTEngine.HasSwitchedRuntimeDebuggingOn = true;
            }
            else
            {
                SCTEngine.HasSwitchedRuntimeDebuggingOn = false;
            }

            SCTEngine.HasRedirectedOutput = false;
        }
Beispiel #3
0
        /// <summary>
        /// Switches the scheduler to the specified scheduling strategy,
        /// and returns the previously installed strategy.
        /// </summary>
        /// <param name="strategy">ISchedulingStrategy</param>
        /// <returns>ISchedulingStrategy</returns>
        internal ISchedulingStrategy SwitchSchedulingStrategy(ISchedulingStrategy strategy)
        {
            ISchedulingStrategy previous = this.Strategy;

            this.Strategy = strategy;
            return(previous);
        }
Beispiel #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(ISchedulingStrategy strategy)
 {
     this.Strategy = strategy;
     this.Tasks    = new List <TaskInfo>();
     this.TaskMap  = new Dictionary <int, TaskInfo>();
     this.BugFound = false;
 }
Beispiel #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="context">AnalysisContext</param>
        private SCTEngine(AnalysisContext context)
        {
            this.AnalysisContext = context;

            this.NumOfFoundBugs    = 0;
            this.BugReport         = "";
            this.ExploredDepth     = 0;
            this.ExploredSchedules = 0;
            this.PrintGuard        = 1;

            if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.AnalysisContext);
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration = false;
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration = false;
            }
            else if (this.AnalysisContext.Configuration.SchedulingStrategy == SchedulingStrategy.MaceMC)
            {
                this.Strategy = new MaceMCStrategy(this.AnalysisContext);
                this.AnalysisContext.Configuration.FullExploration   = false;
                this.AnalysisContext.Configuration.CheckLiveness     = true;
                this.AnalysisContext.Configuration.CacheProgramState = false;
            }

            this.HasRedirectedConsoleOutput = false;
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlledRuntime"/> class.
        /// </summary>
        internal ControlledRuntime(Configuration configuration, ISchedulingStrategy strategy,
                                   IRandomValueGenerator valueGenerator)
            : base(configuration, valueGenerator)
        {
            IsExecutionControlled = true;

            this.RootTaskId         = Task.CurrentId;
            this.NameValueToActorId = new ConcurrentDictionary <string, ActorId>();

            this.CoverageInfo = new CoverageInfo();

            var scheduleTrace = new ScheduleTrace();

            if (configuration.IsLivenessCheckingEnabled)
            {
                strategy = new TemperatureCheckingStrategy(configuration, this.Monitors, strategy);
            }

            this.Scheduler      = new OperationScheduler(this, strategy, scheduleTrace, this.Configuration);
            this.TaskController = new TaskController(this, this.Scheduler);

            // Update the current asynchronous control flow with this runtime instance,
            // allowing future retrieval in the same asynchronous call stack.
            AssignAsyncControlFlowRuntime(this);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(ISchedulingStrategy strategy)
 {
     this.Strategy = strategy;
     this.Tasks = new List<TaskInfo>();
     this.TaskMap = new Dictionary<int, TaskInfo>();
     this.BugFound = false;
 }
        public Flow_asynchronously(ISchedulingStrategy schedule)
        {
            // Build
            var throttle         = new Throttle_message_flow();
            var handle_exception = new Handle_exception();

            _processMessage = new Process_message();

            // Bind
            _process                            += schedule.ProcessExternalMessage;
            schedule.Result                     += throttle.Process;
            throttle.Continue                   += handle_exception.Process;
            handle_exception.Continue           += _processMessage.Process;
            handle_exception.UnhandledException += _ => UnhandledException(_);
            _processMessage.Message             += _ => Message(_);
            _processMessage.Continue            += schedule.ProcessInternalMessage;
            _processMessage.Result              += _ => Result(_);
            _processMessage.UnhandledException  += _ => UnhandledException(_);

            _execute += _processMessage.Execute;

            _start    += schedule.Start;
            _stop     += schedule.Stop;
            _throttle += throttle.Delay;
        }
Beispiel #9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="prefixStrategy">Prefix strategy </param>
 /// <param name="suffixStrategy">Suffix strategy</param>
 public ComboStrategy(Configuration configuration, ISchedulingStrategy prefixStrategy, ISchedulingStrategy suffixStrategy)
 {
     this.Configuration     = configuration;
     this.SafetyPrefixDepth = this.Configuration.SafetyPrefixBound == 0 ? this.Configuration.MaxUnfairSchedulingSteps
         : this.Configuration.SafetyPrefixBound;
     this.PrefixStrategy = prefixStrategy;
     this.SuffixStrategy = suffixStrategy;
 }
Beispiel #10
0
        public FlowRuntime(FlowRuntimeConfiguration config, ISchedulingStrategy schedule)
        {
            // Build
            var regStream = new Register_stream();
            var regOp     = new Register_operation();
            var configOp  = new Create_activation_task();

            var flow = new Flow_asynchronously(schedule);

            var opStart = new Start_async_operations();
            var opStop  = new Stop_async_operations();

            // Bind
            _addStream      += regStream.Process;
            _addOperation   += regOp.Process;
            _addOperation   += configOp.Process;
            configOp.Result += flow.Execute;

            _process                += flow.Process;
            flow.Message            += _ => Message(_);
            flow.Result             += Pass_result_to_environment;
            flow.UnhandledException += ex =>
            {
                if (UnhandledException == null)
                {
                    throw new UnhandledFlowRuntimeException(ex);
                }
                UnhandledException(ex);
            };

            _start += opStart.Process;
            _start += flow.Start;

            _stop += flow.Stop;
            _stop += opStop.Process;

            _throttle += flow.Throttle;

            // Inject
            var streams = new List <IStream>();

            regStream.Inject(streams);

            var operations = new Dictionary <string, IOperation>();

            regOp.Inject(operations);

            flow.Inject(streams, operations);
            opStart.Inject(operations);
            opStop.Inject(operations);

            // Config
            Configure(config);

            // Run
            Start();
        }
Beispiel #11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">PSharpBugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(PSharpBugFindingRuntime runtime, ISchedulingStrategy strategy)
 {
     this.Runtime                  = runtime;
     this.Strategy                 = strategy;
     this.TaskMap                  = new ConcurrentDictionary <int, MachineInfo>();
     this.IsSchedulerRunning       = true;
     this.BugFound                 = false;
     this.HasFullyExploredSchedule = false;
 }
Beispiel #12
0
        public ProcessingGroup(string name, ProcessingGroupInfo processingGroupInfo)
        {
            Name = name;
            m_ConcurrencyLevel = Math.Max(processingGroupInfo.ConcurrencyLevel, 0);

            m_SchedulingStrategy = (m_ConcurrencyLevel == 0)
                ? (ISchedulingStrategy) new CurrentThreadSchedulingStrategy()
                : (ISchedulingStrategy) new QueuedSchedulingStrategy(m_ConcurrencyLevel, processingGroupInfo.QueueCapacity, $"ProcessingGroup '{Name}' thread");
        }
Beispiel #13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">BugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(BugFindingRuntime runtime, ISchedulingStrategy strategy)
 {
     this.Runtime                  = runtime;
     this.Strategy                 = strategy;
     this.SchedulableInfoMap       = new Dictionary <ulong, SchedulableInfo>();
     this.CompletionSource         = new TaskCompletionSource <bool>();
     this.IsSchedulerRunning       = true;
     this.BugFound                 = false;
     this.HasFullyExploredSchedule = false;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BugFindingScheduler"/> class.
 /// </summary>
 internal BugFindingScheduler(SystematicTestingRuntime runtime, ISchedulingStrategy strategy)
 {
     this.Runtime                  = runtime;
     this.Strategy                 = strategy;
     this.OperationMap             = new Dictionary <ulong, AsyncOperation>();
     this.CompletionSource         = new TaskCompletionSource <bool>();
     this.IsSchedulerRunning       = true;
     this.BugFound                 = false;
     this.HasFullyExploredSchedule = false;
 }
Beispiel #15
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="trace">ScheduleTrace</param>
 /// <param name="isFair">Is scheduler fair</param>
 /// <param name="suffixStrategy">The suffix strategy.</param>
 public ReplayStrategy(Configuration configuration, ScheduleTrace trace, bool isFair, ISchedulingStrategy suffixStrategy)
 {
     Configuration   = configuration;
     ScheduleTrace   = trace;
     ScheduledSteps  = 0;
     IsSchedulerFair = isFair;
     IsReplaying     = true;
     SuffixStrategy  = suffixStrategy;
     ErrorText       = "";
 }
Beispiel #16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">PSharpBugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(PSharpBugFindingRuntime runtime, ISchedulingStrategy strategy)
 {
     this.Runtime = runtime;
     this.Strategy = strategy;
     this.MachineInfos = new ConcurrentBag<MachineInfo>();
     this.TaskMap = new ConcurrentDictionary<int, MachineInfo>();
     this.IsSchedulerRunning = true;
     this.BugFound = false;
     this.HasFullyExploredSchedule = false;
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplayStrategy"/> class.
 /// </summary>
 public ReplayStrategy(Configuration configuration, ScheduleTrace trace, bool isFair, ISchedulingStrategy suffixStrategy)
 {
     this.Configuration   = configuration;
     this.ScheduleTrace   = trace;
     this.ScheduledSteps  = 0;
     this.IsSchedulerFair = isFair;
     this.IsReplaying     = true;
     this.SuffixStrategy  = suffixStrategy;
     this.ErrorText       = string.Empty;
 }
 /// <summary>
 /// Creates a reduction strategy that reduces the choice-space for a child strategy.
 /// </summary>
 /// <param name="childStrategy">Child strategy.</param>
 /// <param name="reductionStrategy">The reduction strategy used.</param>
 /// <param name="stepLimit">The step limit.</param>
 public BasicReductionStrategy(
     ISchedulingStrategy childStrategy,
     ReductionStrategy reductionStrategy,
     int stepLimit = 0)
 {
     ChildStrategy              = childStrategy;
     Reduction                  = reductionStrategy;
     ScheduledSteps             = 0;
     StepLimit                  = stepLimit;
     ReportActualScheduledSteps = StepLimit != 0;
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BasicReductionStrategy"/> class.
 /// </summary>
 public BasicReductionStrategy(
     ISchedulingStrategy childStrategy,
     ReductionStrategy reductionStrategy,
     int stepLimit = 0)
 {
     this.ChildStrategy              = childStrategy;
     this.Reduction                  = reductionStrategy;
     this.ScheduledSteps             = 0;
     this.StepLimit                  = stepLimit;
     this.ReportActualScheduledSteps = this.StepLimit != 0;
 }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationScheduler"/> class.
 /// </summary>
 internal OperationScheduler(ControlledRuntime runtime, ISchedulingStrategy strategy,
                             ScheduleTrace trace, Configuration configuration)
 {
     this.Configuration            = configuration;
     this.Runtime                  = runtime;
     this.Strategy                 = strategy;
     this.OperationMap             = new Dictionary <ulong, AsyncOperation>();
     this.ScheduleTrace            = trace;
     this.SyncObject               = new object();
     this.CompletionSource         = new TaskCompletionSource <bool>();
     this.IsAttached               = true;
     this.BugFound                 = false;
     this.HasFullyExploredSchedule = false;
 }
Beispiel #21
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="runtime">BugFindingRuntime</param>
        /// <param name="schedulingStrategy">ISchedulingStrategy</param>
        internal LivenessChecker(BugFindingRuntime runtime, ISchedulingStrategy schedulingStrategy)
        {
            this.Runtime = runtime;

            this.Monitors       = new List <Monitor>();
            this.PotentialCycle = new List <Tuple <ScheduleStep, State> >();
            this.HotMonitors    = new HashSet <Monitor>();

            this.LivenessTemperature = 0;
            this.EndOfCycleIndex     = 0;
            this.CurrentCycleIndex   = 0;
            this.SchedulingStrategy  = schedulingStrategy;

            this.Seed   = this.Runtime.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
            this.Random = new DefaultRandomNumberGenerator(this.Seed);
        }
        /// <summary>
        /// Creates a liveness strategy that checks the specific monitors
        /// for liveness property violations, and uses the specified
        /// strategy for scheduling decisions.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        /// <param name="cache">StateCache</param>
        /// <param name="trace">ScheduleTrace</param>
        /// <param name="monitors">List of monitors</param>
        /// <param name="strategy">ISchedulingStrategy</param>
        internal CycleDetectionStrategy(Configuration configuration, StateCache cache, ScheduleTrace trace,
                                        List <Monitor> monitors, ISchedulingStrategy strategy)
            : base(configuration, monitors, strategy)
        {
            StateCache    = cache;
            ScheduleTrace = trace;

            HotMonitors                = new HashSet <Monitor>();
            PotentialCycle             = new List <ScheduleStep>();
            PotentialCycleFingerprints = new HashSet <Fingerprint>();

            LivenessTemperature = 0;
            EndOfCycleIndex     = 0;
            CurrentCycleIndex   = 0;

            Seed   = Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
            Random = new DefaultRandomNumberGenerator(Seed);

            FingerprintIndexMap = new Dictionary <Fingerprint, List <int> >();
        }
Beispiel #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlledRuntime"/> class.
        /// </summary>
        internal ControlledRuntime(Configuration configuration, ISchedulingStrategy strategy,
                                   IRandomValueGenerator valueGenerator)
            : base(configuration, valueGenerator)
        {
            IncrementExecutionControlledUseCount();

            this.RootTaskId         = Task.CurrentId;
            this.NameValueToActorId = new ConcurrentDictionary <string, ActorId>();

            this.CoverageInfo = new CoverageInfo();

            var scheduleTrace = new ScheduleTrace();

            if (configuration.IsLivenessCheckingEnabled)
            {
                strategy = new TemperatureCheckingStrategy(configuration, this.Monitors, strategy);
            }

            this.Scheduler      = new OperationScheduler(this, strategy, scheduleTrace, this.Configuration);
            this.TaskController = new TaskController(this, this.Scheduler);
        }
        public Flow_asynchronously(ISchedulingStrategy schedule)
        {
            // Build
            var throttle = new Throttle_message_flow();
            var handle_exception = new Handle_exception();
            _processMessage = new Process_message();

            // Bind
            _process += schedule.ProcessExternalMessage;
            schedule.Result += throttle.Process;
            throttle.Continue += handle_exception.Process;
            handle_exception.Continue += _processMessage.Process;
            handle_exception.UnhandledException += _ => UnhandledException(_);
            _processMessage.Message += _ => Message(_);
            _processMessage.Continue += schedule.ProcessInternalMessage;
            _processMessage.Result += _ => Result(_);
            _processMessage.UnhandledException += _ => UnhandledException(_);

            _execute += _processMessage.Execute;

            _start += schedule.Start;
            _stop += schedule.Stop;
            _throttle += throttle.Delay;
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="strategy">SchedulingStrategy</param>
 internal TaskAwareBugFindingScheduler(ISchedulingStrategy strategy)
     : base(strategy)
 {
     this.UserTasks = new List<Task>();
     this.WrappedTaskMap = new Dictionary<int, TaskInfo>();
 }
Beispiel #26
0
        /// <summary>
        /// Initialized the testing engine.
        /// </summary>
        private void Initialize()
        {
            this.CancellationTokenSource = new CancellationTokenSource();

            this.TestReport = new TestReport();
            this.PrintGuard = 1;

            if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Interactive)
            {
                this.Strategy = new InteractiveStrategy(this.Configuration);
                this.Configuration.SchedulingIterations   = 1;
                this.Configuration.PerformFullExploration = false;
                this.Configuration.Verbose = 2;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Replay)
            {
                string[] scheduleDump = File.ReadAllLines(this.Configuration.ScheduleFile);
                bool     isFair       = false;

                foreach (var line in scheduleDump)
                {
                    if (!line.StartsWith("--"))
                    {
                        break;
                    }

                    if (line.Equals("--fair-scheduling"))
                    {
                        isFair = true;
                    }
                    else if (line.Equals("--state-caching"))
                    {
                        this.Configuration.CacheProgramState = true;
                    }
                    else if (line.StartsWith("--liveness-temperature-threshold:"))
                    {
                        this.Configuration.LivenessTemperatureThreshold =
                            Int32.Parse(line.Substring("--liveness-temperature-threshold:".Length));
                    }
                    else if (line.StartsWith("--test-method:"))
                    {
                        this.Configuration.TestMethodName =
                            line.Substring("--test-method:".Length);
                    }
                }

                ScheduleTrace schedule = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(this.Configuration, schedule, isFair);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.Configuration);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.ProbabilisticRandom)
            {
                this.Strategy = new ProbabilisticRandomStrategy(this.Configuration,
                                                                this.Configuration.CoinFlipBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DelayBounding)
            {
                this.Strategy = new ExhaustiveDelayBoundingStrategy(this.Configuration,
                                                                    this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomDelayBounding)
            {
                this.Strategy = new RandomDelayBoundingStrategy(this.Configuration,
                                                                this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PCT)
            {
                this.Strategy = new PCTStrategy(this.Configuration, this.Configuration.PrioritySwitchBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomOperationBounding)
            {
                this.Strategy = new RandomOperationBoundingStrategy(this.Configuration);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PrioritizedOperationBounding)
            {
                this.Strategy = new PrioritizedOperationBoundingStrategy(this.Configuration,
                                                                         this.Configuration.PrioritySwitchBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.MaceMC)
            {
                this.Strategy = new MaceMCStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
                this.Configuration.CacheProgramState      = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Portfolio)
            {
                IO.Error.ReportAndExit("Portfolio testing strategy in only " +
                                       "available in parallel testing.");
            }

            if (this.Configuration.PrintTrace)
            {
                this.Configuration.SchedulingIterations   = 1;
                this.Configuration.PerformFullExploration = false;
            }

            this.HasRedirectedConsoleOutput = false;
        }
Beispiel #27
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="runtime">PSharpBugFindingRuntime</param>
        /// <param name="bugFindingSchedulingStrategy">ISchedulingStrategy</param>
        internal LivenessChecker(PSharpBugFindingRuntime runtime,
            ISchedulingStrategy bugFindingSchedulingStrategy)
        {
            this.Runtime = runtime;

            this.Monitors = new List<Monitor>();
            this.PotentialCycle = new List<Tuple<ScheduleStep, State>>();
            this.HotMonitors = new HashSet<Monitor>();

            this.LivenessTemperature = 0;
            this.EndOfCycleIndex = 0;
            this.CurrentCycleIndex = 0;
            this.BugFindingSchedulingStrategy = bugFindingSchedulingStrategy;

            this.Seed = this.Runtime.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
            this.Random = new Random(this.Seed);
        }
Beispiel #28
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">PSharpBugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal BugFindingScheduler(PSharpBugFindingRuntime runtime, ISchedulingStrategy strategy)
 {
     this.Runtime = runtime;
     this.Strategy = strategy;
     this.MachineInfos = new List<MachineInfo>();
     this.TaskMap = new Dictionary<int, MachineInfo>();
     this.BugFound = false;
 }
Beispiel #29
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="strategy">SchedulingStrategy</param>
 internal TaskAwareBugFindingScheduler(ISchedulingStrategy strategy)
     : base(strategy)
 {
     this.UserTasks      = new List <Task>();
     this.WrappedTaskMap = new Dictionary <int, TaskInfo>();
 }
 /// <summary>
 /// Creates a liveness strategy that checks the specific monitors
 /// for liveness property violations, and uses the specified
 /// strategy for scheduling decisions.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="monitors">List of monitors</param>
 /// <param name="strategy">ISchedulingStrategy</param>
 internal LivenessCheckingStrategy(Configuration configuration, List <Monitor> monitors, ISchedulingStrategy strategy)
 {
     Configuration      = configuration;
     Monitors           = monitors;
     SchedulingStrategy = strategy;
 }
Beispiel #31
0
        /// <summary>
        /// Setups the P# systematic testing engine.
        /// </summary>
        public static void Setup()
        {
            SCTEngine.NumOfFoundBugs = 0;
            SCTEngine.BugReport = "";
            SCTEngine.ExploredDepth = 0;
            SCTEngine.ExploredSchedules = 0;
            SCTEngine.PrintGuard = 1;

            if (AnalysisContext.Strategy == SchedulingStrategy.Random)
            {
                SCTEngine.Strategy = new RandomSchedulingStrategy(DateTime.Now.Millisecond);
            }
            else if (AnalysisContext.Strategy == SchedulingStrategy.DFS)
            {
                SCTEngine.Strategy = new DFSSchedulingStrategy();
                Configuration.FullExploration = false;
            }

            if (!Configuration.Debug.Contains(DebugType.All) &&
                !Configuration.Debug.Contains(DebugType.Runtime))
            {
                Configuration.Debug.Add(DebugType.Runtime);
                SCTEngine.HasSwitchedRuntimeDebuggingOn = true;
            }
            else
            {
                SCTEngine.HasSwitchedRuntimeDebuggingOn = false;
            }

            SCTEngine.HasRedirectedOutput = false;
        }
Beispiel #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestingEngine"/> class.
        /// </summary>
        private TestingEngine(Configuration configuration, TestMethodInfo testMethodInfo)
        {
            this.Configuration  = configuration;
            this.TestMethodInfo = testMethodInfo;

            this.Logger        = new ConsoleLogger();
            this.ErrorReporter = new ErrorReporter(configuration, this.Logger);
            this.Profiler      = new Profiler();

            this.PerIterationCallbacks = new HashSet <Action <int> >();

            // Initializes scheduling strategy specific components.
            this.RandomValueGenerator = new RandomValueGenerator(configuration);

            this.TestReport        = new TestReport(configuration);
            this.ReadableTrace     = string.Empty;
            this.ReproducableTrace = string.Empty;

            this.CancellationTokenSource = new CancellationTokenSource();
            this.PrintGuard = 1;

            if (!configuration.UserExplicitlySetLivenessTemperatureThreshold &&
                configuration.MaxFairSchedulingSteps > 0)
            {
                configuration.LivenessTemperatureThreshold = configuration.MaxFairSchedulingSteps / 2;
            }

            if (configuration.SchedulingStrategy is "replay")
            {
                var           scheduleDump = this.GetScheduleForReplay(out bool isFair);
                ScheduleTrace schedule     = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(configuration, schedule, isFair);
            }
            else if (configuration.SchedulingStrategy is "interactive")
            {
                configuration.TestingIterations      = 1;
                configuration.PerformFullExploration = false;
                configuration.IsVerbose = true;
                this.Strategy           = new InteractiveStrategy(configuration, this.Logger);
            }
            else if (configuration.SchedulingStrategy is "random")
            {
                this.Strategy = new RandomStrategy(configuration.MaxFairSchedulingSteps, this.RandomValueGenerator);
            }
            else if (configuration.SchedulingStrategy is "pct")
            {
                this.Strategy = new PCTStrategy(configuration.MaxUnfairSchedulingSteps, configuration.StrategyBound,
                                                this.RandomValueGenerator);
            }
            else if (configuration.SchedulingStrategy is "fairpct")
            {
                var prefixLength = configuration.SafetyPrefixBound == 0 ?
                                   configuration.MaxUnfairSchedulingSteps : configuration.SafetyPrefixBound;
                var prefixStrategy = new PCTStrategy(prefixLength, configuration.StrategyBound, this.RandomValueGenerator);
                var suffixStrategy = new RandomStrategy(configuration.MaxFairSchedulingSteps, this.RandomValueGenerator);
                this.Strategy = new ComboStrategy(prefixStrategy, suffixStrategy);
            }
            else if (configuration.SchedulingStrategy is "probabilistic")
            {
                this.Strategy = new ProbabilisticRandomStrategy(configuration.MaxFairSchedulingSteps,
                                                                configuration.StrategyBound, this.RandomValueGenerator);
            }
            else if (configuration.SchedulingStrategy is "dfs")
            {
                this.Strategy = new DFSStrategy(configuration.MaxUnfairSchedulingSteps);
            }
            else if (configuration.SchedulingStrategy is "portfolio")
            {
                Error.ReportAndExit("Portfolio testing strategy is only " +
                                    "available in parallel testing.");
            }

            if (configuration.SchedulingStrategy != "replay" &&
                configuration.ScheduleFile.Length > 0)
            {
                var           scheduleDump = this.GetScheduleForReplay(out bool isFair);
                ScheduleTrace schedule     = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(configuration, schedule, isFair, this.Strategy);
            }
        }
Beispiel #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComboStrategy"/> class.
 /// </summary>
 public ComboStrategy(ISchedulingStrategy prefixStrategy, ISchedulingStrategy suffixStrategy)
 {
     this.PrefixStrategy = prefixStrategy;
     this.SuffixStrategy = suffixStrategy;
 }
Beispiel #34
0
        /// <summary>
        /// Initialized the testing engine.
        /// </summary>
        private void Initialize()
        {
            this.NumOfFoundBugs = 0;
            this.BugReport = "";
            this.ExploredDepth = 0;
            this.ExploredSchedules = 0;
            this.PrintGuard = 1;

            if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Interactive)
            {
                this.Strategy = new InteractiveStrategy(this.Configuration);
                this.Configuration.SchedulingIterations = 1;
                this.Configuration.FullExploration = false;
                this.Configuration.Verbose = 2;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.Configuration);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.Configuration);
                this.Configuration.FullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.Configuration);
                this.Configuration.FullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DelayBounding)
            {
                this.Strategy = new ExhaustiveDelayBoundingStrategy(this.Configuration,
                    this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomDelayBounding)
            {
                this.Strategy = new RandomDelayBoundingStrategy(this.Configuration,
                    this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PCT)
            {
                this.Strategy = new PCTStrategy(this.Configuration, this.Configuration.BugDepth);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomOperationBounding)
            {
                this.Strategy = new RandomOperationBoundingStrategy(this.Configuration);
                this.Configuration.BoundOperations = true;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PrioritizedOperationBounding)
            {
                this.Strategy = new PrioritizedOperationBoundingStrategy(this.Configuration,
                    this.Configuration.BugDepth);
                this.Configuration.BoundOperations = true;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.MaceMC)
            {
                this.Strategy = new MaceMCStrategy(this.Configuration);
                this.Configuration.FullExploration = false;
                this.Configuration.CheckLiveness = true;
                this.Configuration.CacheProgramState = false;
            }

            this.HasRedirectedConsoleOutput = false;
        }
        /// <summary>
        /// Initialized the testing engine.
        /// </summary>
        private void Initialize()
        {
            this.CancellationTokenSource = new CancellationTokenSource();

            this.BugReport = "";
            this.NumOfFoundBugs = 0;
            this.ExploredDepth = 0;
            this.PrintGuard = 1;

            if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Interactive)
            {
                this.Strategy = new InteractiveStrategy(this.Configuration);
                this.Configuration.SchedulingIterations = 1;
                this.Configuration.PerformFullExploration = false;
                this.Configuration.Verbose = 2;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Replay)
            {
                string[] scheduleDump = File.ReadAllLines(this.Configuration.ScheduleFile);
                ScheduleTrace schedule = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(this.Configuration, schedule);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.Configuration);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.ProbabilisticRandom)
            {
                this.Strategy = new ProbabilisticRandomStrategy(this.Configuration,
                    this.Configuration.CoinFlipBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DelayBounding)
            {
                this.Strategy = new ExhaustiveDelayBoundingStrategy(this.Configuration,
                    this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomDelayBounding)
            {
                this.Strategy = new RandomDelayBoundingStrategy(this.Configuration,
                    this.Configuration.DelayBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PCT)
            {
                this.Strategy = new PCTStrategy(this.Configuration, this.Configuration.PrioritySwitchBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomOperationBounding)
            {
                this.Strategy = new RandomOperationBoundingStrategy(this.Configuration);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PrioritizedOperationBounding)
            {
                this.Strategy = new PrioritizedOperationBoundingStrategy(this.Configuration,
                    this.Configuration.PrioritySwitchBound);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.MaceMC)
            {
                this.Strategy = new MaceMCStrategy(this.Configuration);
                this.Configuration.PerformFullExploration = false;
                this.Configuration.CacheProgramState = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Portfolio)
            {
                IO.Error.ReportAndExit("Portfolio testing strategy in only " +
                    "available in parallel testing.");
            }

            if (this.Configuration.EnableVisualization)
            {
                this.InitializeVisualizer();
            }

            if (this.Configuration.PrintTrace)
            {
                this.Configuration.SchedulingIterations = 1;
                this.Configuration.PerformFullExploration = false;
            }

            this.HasRedirectedConsoleOutput = false;
        }
Beispiel #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemperatureCheckingStrategy"/> class.
 /// </summary>
 internal TemperatureCheckingStrategy(Configuration configuration, List <Monitor> monitors, ISchedulingStrategy strategy)
     : base(configuration, monitors, strategy)
 {
 }
Beispiel #37
0
        /// <summary>
        /// Initialized the testing engine.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        private void Initialize(Configuration configuration)
        {
            this.Configuration = configuration;
            this.Logger        = new ConsoleLogger();
            this.ErrorReporter = new ErrorReporter(this.Configuration, this.Logger);
            this.Profiler      = new Profiler();

            this.PerIterationCallbacks = new HashSet <Action <int> >();

            // Initializes scheduling strategy specific components.
            this.SchedulingStrategyLogger = new SchedulingStrategyLogger(this.Configuration);
            this.SetRandomNumberGenerator();

            this.TestReport = new TestReport(this.Configuration);
            this.CancellationTokenSource = new CancellationTokenSource();
            this.PrintGuard = 1;

            if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Interactive)
            {
                this.Strategy = new InteractiveStrategy(this.Configuration, this.Logger);
                this.Configuration.SchedulingIterations   = 1;
                this.Configuration.PerformFullExploration = false;
                this.Configuration.Verbose = 2;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Replay)
            {
                var           scheduleDump = this.GetScheduleForReplay(out bool isFair);
                ScheduleTrace schedule     = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(this.Configuration, schedule, isFair);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Random)
            {
                this.Strategy = new RandomStrategy(this.Configuration.MaxFairSchedulingSteps, this.RandomNumberGenerator);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.ProbabilisticRandom)
            {
                this.Strategy = new ProbabilisticRandomStrategy(this.Configuration.MaxFairSchedulingSteps,
                                                                this.Configuration.CoinFlipBound, this.RandomNumberGenerator);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.PCT)
            {
                this.Strategy = new PCTStrategy(this.Configuration.MaxUnfairSchedulingSteps, this.Configuration.PrioritySwitchBound,
                                                this.SchedulingStrategyLogger, this.RandomNumberGenerator);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.FairPCT)
            {
                var prefixLength = this.Configuration.SafetyPrefixBound == 0 ?
                                   this.Configuration.MaxUnfairSchedulingSteps : this.Configuration.SafetyPrefixBound;
                var prefixStrategy = new PCTStrategy(prefixLength, this.Configuration.PrioritySwitchBound,
                                                     this.SchedulingStrategyLogger, this.RandomNumberGenerator);
                var suffixStrategy = new RandomStrategy(this.Configuration.MaxFairSchedulingSteps, this.RandomNumberGenerator);
                this.Strategy = new ComboStrategy(prefixStrategy, suffixStrategy);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DFS)
            {
                this.Strategy = new DFSStrategy(this.Configuration.MaxUnfairSchedulingSteps, this.SchedulingStrategyLogger);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.IDDFS)
            {
                this.Strategy = new IterativeDeepeningDFSStrategy(this.Configuration.MaxUnfairSchedulingSteps,
                                                                  this.SchedulingStrategyLogger);
                this.Configuration.PerformFullExploration = false;
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DPOR)
            {
                this.Strategy = new DPORStrategy(
                    new ContractAsserter(),
                    null,
                    -1,
                    this.Configuration.MaxUnfairSchedulingSteps);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RDPOR)
            {
                this.Strategy = new DPORStrategy(
                    new ContractAsserter(),
                    this.RandomNumberGenerator,
                    -1,
                    this.Configuration.MaxFairSchedulingSteps);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.DelayBounding)
            {
                this.Strategy = new ExhaustiveDelayBoundingStrategy(this.Configuration.MaxUnfairSchedulingSteps,
                                                                    this.Configuration.DelayBound, this.SchedulingStrategyLogger, this.RandomNumberGenerator);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.RandomDelayBounding)
            {
                this.Strategy = new RandomDelayBoundingStrategy(this.Configuration.MaxUnfairSchedulingSteps,
                                                                this.Configuration.DelayBound, this.SchedulingStrategyLogger, this.RandomNumberGenerator);
            }
            else if (this.Configuration.SchedulingStrategy == SchedulingStrategy.Portfolio)
            {
                Error.ReportAndExit("Portfolio testing strategy is only " +
                                    "available in parallel testing.");
            }

            if (this.Configuration.SchedulingStrategy != SchedulingStrategy.Replay &&
                this.Configuration.ScheduleFile.Length > 0)
            {
                var           scheduleDump = this.GetScheduleForReplay(out bool isFair);
                ScheduleTrace schedule     = new ScheduleTrace(scheduleDump);
                this.Strategy = new ReplayStrategy(this.Configuration, schedule, isFair, this.Strategy);
            }
        }
Beispiel #38
0
 /// <summary>
 /// Switches the scheduler to the specified scheduling strategy,
 /// and returns the previously installed strategy.
 /// </summary>
 /// <param name="strategy">ISchedulingStrategy</param>
 /// <returns>ISchedulingStrategy</returns>
 internal ISchedulingStrategy SwitchSchedulingStrategy(ISchedulingStrategy strategy)
 {
     ISchedulingStrategy previous = this.Strategy;
     this.Strategy = strategy;
     return previous;
 }
Beispiel #39
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">PSharpBugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal TaskAwareBugFindingScheduler(PSharpBugFindingRuntime runtime, ISchedulingStrategy strategy)
     : base(runtime, strategy)
 {
     this.UserTasks      = new ConcurrentBag <Task>();
     this.WrappedTaskMap = new ConcurrentDictionary <int, MachineInfo>();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="runtime">PSharpBugFindingRuntime</param>
 /// <param name="strategy">SchedulingStrategy</param>
 internal TaskAwareBugFindingScheduler(PSharpBugFindingRuntime runtime, ISchedulingStrategy strategy)
     : base (runtime, strategy)
 {
     this.UserTasks = new List<Task>();
     this.WrappedTaskMap = new Dictionary<int, MachineInfo>();
 }