Beispiel #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="trace">ScheduleTrace</param>
 public ReplayStrategy(Configuration configuration, ScheduleTrace trace)
 {
     this.Configuration = configuration;
     this.ScheduleTrace = trace;
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplayStrategy"/> class.
 /// </summary>
 internal ReplayStrategy(Configuration configuration, IRandomValueGenerator generator,
                         ScheduleTrace trace, bool isFair)
     : base(configuration, generator, isFair)
 {
     this.ScheduleTrace = trace;
     this.ErrorText     = string.Empty;
 }
Beispiel #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="trace">ScheduleTrace</param>
 /// <param name="isFair">Is scheduler fair</param>
 public ReplayStrategy(Configuration configuration, ScheduleTrace trace, bool isFair)
 {
     this.Configuration    = configuration;
     this.ScheduleTrace    = trace;
     this.MaxExploredSteps = 0;
     this.ExploredSteps    = 0;
     this.IsSchedulerFair  = isFair;
 }
Beispiel #4
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 #5
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 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> >();
        }
        /// <summary>
        /// Creates a <see cref="InterleavingStrategy"/> from the specified configuration.
        /// </summary>
        internal static InterleavingStrategy Create(Configuration configuration, IRandomValueGenerator generator)
        {
            InterleavingStrategy strategy = null;
            if (configuration.SchedulingStrategy is "replay")
            {
                var trace = ScheduleTrace.Deserialize(configuration, out bool isFair);
                strategy = new ReplayStrategy(configuration, generator, trace, isFair);
            }
            else if (configuration.SchedulingStrategy is "random")
            {
                strategy = new RandomStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "prioritization")
            {
                strategy = new PrioritizationStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "fair-prioritization")
            {
                var prefixStrategy = new PrioritizationStrategy(configuration, generator);
                var suffixStrategy = new RandomStrategy(configuration, generator);
                strategy = new ComboStrategy(configuration, generator, prefixStrategy, suffixStrategy);
            }
            else if (configuration.SchedulingStrategy is "probabilistic")
            {
                strategy = new ProbabilisticRandomStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "rl")
            {
                strategy = new QLearningStrategy(configuration, generator);
            }
            else if (configuration.SchedulingStrategy is "dfs")
            {
                strategy = new DFSStrategy(configuration, generator);
            }

            return strategy;
        }
Beispiel #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="trace">ScheduleTrace</param>
 /// <param name="isFair">Is scheduler fair</param>
 public ReplayStrategy(Configuration configuration, ScheduleTrace trace, bool isFair)
     : this(configuration, trace, isFair, null)
 {
 }
        /// <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 #10
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);
            }
        }
        /// <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;
        }