Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates arguments from the specified configuration.
        /// </summary>
        /// <param name="id">Unique process id</param>
        /// <param name="configuration">Configuration</param>
        /// <returns>Arguments</returns>
        private static string CreateArgumentsFromConfiguration(int id, Configuration configuration)
        {
            StringBuilder arguments = new StringBuilder();

            if (configuration.EnableDebugging)
            {
                arguments.Append($"/debug ");
            }

            arguments.Append($"/test:{configuration.AssemblyToBeAnalyzed} ");
            arguments.Append($"/i:{configuration.SchedulingIterations} ");
            arguments.Append($"/timeout:{configuration.Timeout} ");
            arguments.Append($"/max-steps:{configuration.MaxSchedulingSteps} ");

            if (configuration.SchedulingStrategy == SchedulingStrategy.PCT)
            {
                arguments.Append($"/sch:{configuration.SchedulingStrategy}:" +
                    $"{configuration.PrioritySwitchBound} ");
            }
            else if (configuration.SchedulingStrategy == SchedulingStrategy.Random ||
                configuration.SchedulingStrategy == SchedulingStrategy.Portfolio)
            {
                arguments.Append($"/sch:{configuration.SchedulingStrategy} ");
            }

            arguments.Append($"/parallel:{configuration.ParallelBugFindingTasks} ");
            arguments.Append($"/testing-scheduler-process-id:{Process.GetCurrentProcess().Id} ");
            arguments.Append($"/testing-process-id:{id}");

            return arguments.ToString();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 private CompilationContext(Configuration configuration)
 {
     this.Configuration = configuration;
     this.PSharpProjects = new List<PSharpProject>();
     this.CustomCompilerPassAssemblies = new HashSet<Assembly>();
     this.LoadCustomCompilerPasses();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="testingEngine">ITestingEngine</param>
        /// <param name="configuration">Configuration</param>
        public RaceInstrumentationEngine(ITestingEngine testingEngine, Configuration configuration)
            : base(new Container(), new EngineOptions(),
                  new MonitorManager(testingEngine, configuration),
                  new ThreadMonitorManager(configuration))
        {
            if (SingletonEngine != null)
            {
                throw new InvalidOperationException("RaceInstrumentationEngine created more than once.");
            }

            SingletonEngine = this;

            // required?
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomainProcessExit);
            this.GetService<ISymbolManager>().AddStackFrameFilter(new StackFrameFilter());

            if (!ControllerEnvironment.IsMonitoringEnabled)
            {
                Console.WriteLine("ExtendedReflection monitor not enabled");
                throw new NotImplementedException("ExtendedReflection monitor not enabled");
            }

            ((IMonitorManager)this.GetService<MonitorManager>()).RegisterThreadMonitor(
               new ThreadMonitorFactory(this.GetService<ThreadMonitorManager>(),
               testingEngine, configuration));

            ((IMonitorManager)this.GetService<MonitorManager>()).RegisterObjectAccessThreadMonitor();

            this.ExecutionMonitor.Initialize();
            var tid = this.ExecutionMonitor.CreateThread();
            _ThreadContext.Start(this.ExecutionMonitor, tid);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="delays">Max number of delays</param>
 public RandomDelayBoundingStrategy(Configuration configuration, int delays)
     : base(configuration, delays)
 {
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.CurrentIterationDelays = new List<int>();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public InteractiveStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.InputCache = new List<string>();
     this.ExploredSteps = 0;
     this.PrioritizedOperationId = 0;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public RandomStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.ExploredSteps = 0;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public MaceMCStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.SafetyPrefixDepth = this.Configuration.SafetyPrefixBound;
     this.BoundedDFS = new IterativeDeepeningDFSStrategy(configuration);
     this.Random = new RandomStrategy(configuration);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        public RaceDetectionEngine(Configuration configuration)
        {
            this.Configuration = configuration;

            this.AllThreadTraces = new List<ThreadTrace>();
            this.CGraph = new BidirectionalGraph<Node, Edge>();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="numberOfCoinFlips">Number of coin flips</param>
 public ProbabilisticRandomStrategy(Configuration configuration, int numberOfCoinFlips)
 {
     this.Configuration = configuration;
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.NumberOfCoinFlips = numberOfCoinFlips;
     this.ExploredSteps = 0;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="delays">Max number of delays</param>
 public DelayBoundingStrategy(Configuration configuration, int delays)
 {
     this.Configuration = configuration;
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
     this.MaxDelays = delays;
     this.RemainingDelays = new List<int>();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public ThreadMonitorManager(Configuration configuration)
     : base()
 {
     this.Configuration = configuration;
     this.MonitorFactories = new SafeList<IThreadMonitorFactory>();
     this.ThreadExecutionMonitors = new SafeList<ThreadExecutionMonitorMultiplexer>();
     this.DestroyedExecutionMonitorIds = new SafeQueue<int>();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="host">ICopComponent</param>
 /// <param name="configuration">Configuration</param>
 public ThreadMonitorFactory(ICopComponent host, ITestingEngine testingEngine,
     Configuration configuration)
     : base(host)
 {
     this.Configuration = configuration;
     this.TestingEngine = testingEngine;
     this.ThreadMonitors = new ThreadMonitorCollection();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public OperationBoundingStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.Operations = new List<int>();
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public DFSStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.ScheduleStack = new List<List<SChoice>>();
     this.BoolNondetStack = new List<List<NondetBooleanChoice>>();
     this.IntNondetStack = new List<List<NondetIntegerChoice>>();
     this.SchIndex = 0;
     this.NondetIndex = 0;
     this.ExploredSteps = 0;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="delays">Max number of delays</param>
 public DelayBoundingStrategy(Configuration configuration, int delays)
 {
     this.Configuration = configuration;
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
     this.MaxDelays = delays;
     this.RemainingDelays = new List<int>();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public DFSStrategy(Configuration configuration)
 {
     this.Configuration = configuration;
     this.ScheduleStack = new List<List<SChoice>>();
     this.NondetStack = new List<List<NondetChoice>>();
     this.SchIndex = 0;
     this.NondetIndex = 0;
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Configures the container.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        internal static void Configure(Configuration configuration)
        {
            Container.Configuration = configuration;

            Output.PrettyPrintLine(". Setting up");

            Container.LoadApplicationAssembly();
            Container.RegisterSerializableTypes();

            Output.PrettyPrintLine("... Configured as container '{0}'", Configuration.ContainerId);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="depth">Bug depth</param>
 public PCTStrategy(Configuration configuration, int depth)
 {
     this.Configuration = configuration;
     this.MaxExploredSteps = 0;
     this.ExploredSteps = 0;
     this.BugDepth = depth;
     this.Seed = this.Configuration.RandomSchedulingSeed ?? DateTime.Now.Millisecond;
     this.Random = new Random(this.Seed);
     this.PrioritizedMachines = new List<MachineId>();
     this.PriorityChangePoints = new SortedSet<int>();
 }
        /// <summary>
        /// Invokes the P# testing engine.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        public void Execute(Configuration configuration)
        {
            // Creates and runs the P# testing engine to find bugs in the P# program.
            ITestingEngine testingEngine = TestingEngineFactory.CreateBugFindingEngine(configuration);

            var assembly = Assembly.LoadFrom(configuration.AssemblyToBeAnalyzed);
            new RaceInstrumentationEngine(testingEngine, configuration);

            this.TryLoadReferencedAssemblies(new[] { assembly });

            testingEngine.Run();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a new P# testing process.
        /// </summary>
        /// <param name="id">Unique process id</param>
        /// <param name="configuration">Configuration</param>
        /// <returns>Process</returns>
        public static Process Create(int id, Configuration configuration)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo(
                Assembly.GetExecutingAssembly().Location,
                CreateArgumentsFromConfiguration(id, configuration));
            startInfo.UseShellExecute = false;

            Process process = new Process();
            process.StartInfo = startInfo;

            return process;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        private TestingProcess(Configuration configuration)
        {
            if (configuration.ParallelBugFindingTasks > 1 &&
                configuration.SchedulingStrategy == SchedulingStrategy.Portfolio)
            {
                TestingPortfolio.ConfigureStrategyForCurrentProcess(configuration);
            }

            this.Configuration = configuration;
            this.TestingEngine = TestingEngineFactory.CreateBugFindingEngine(
                this.Configuration);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Configures the container.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        internal static void Configure(Configuration configuration)
        {
            configuration.PauseOnAssertionFailure = true;
            Container.Configuration = configuration;

            IO.PrettyPrintLine(". Setting up the runtime container");

            Container.LoadApplicationAssembly();
            Container.RegisterSerializableTypes();

            IO.PrettyPrintLine("... Configured as container '{0}'", Configuration.ContainerId);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Configures the testing strategy for the current
 /// testing process.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 internal static void ConfigureStrategyForCurrentProcess(
     Configuration configuration)
 {
     if (configuration.TestingProcessId % 2 == 0)
     {
         configuration.SchedulingStrategy = SchedulingStrategy.Random;
     }
     else
     {
         configuration.SchedulingStrategy = SchedulingStrategy.PCT;
         configuration.PrioritySwitchBound = configuration.TestingProcessId;
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        private TestingProcessScheduler(Configuration configuration)
        {
            this.TestingProcesses = new Dictionary<int, Process>();
            this.Profiler = new Profiler();
            this.SchedulerLock = new object();
            this.BugFound = false;

            configuration.Verbose = 1;
            configuration.PrintTrace = false;
            configuration.PerformFullExploration = false;
            configuration.EnableDataRaceDetection = false;

            this.Configuration = configuration;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a new P# replaying engine.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="action">Action</param>
 /// <returns>ReplayEngine</returns>
 public static ReplayEngine Create(Configuration configuration, Action<PSharpRuntime> action)
 {
     return new ReplayEngine(configuration, action);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates a new P# replaying engine.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="assembly">Assembly</param>
 /// <returns>ReplayEngine</returns>
 public static ReplayEngine Create(Configuration configuration, Assembly assembly)
 {
     return new ReplayEngine(configuration, assembly);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates a new P# replaying engine.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <returns>ReplayEngine</returns>
 public static ReplayEngine Create(Configuration configuration)
 {
     return new ReplayEngine(configuration);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="action">Action</param>
 private ReplayEngine(Configuration configuration, Action<PSharpRuntime> action)
     : base(configuration, action)
 {
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="assembly">Assembly</param>
 private ReplayEngine(Configuration configuration, Assembly assembly)
     : base(configuration, assembly)
 {
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="args">Array of arguments</param>
 public BaseCommandLineOptions(string[] args)
 {
     this.Configuration = Configuration.Create();
     this.Options       = args;
 }