Esempio n. 1
0
        public void TestAssertFailureEventHandler()
        {
            var tcsFail = new TaskCompletionSource <bool>();
            int count   = 0;

            PSharpRuntime runtime = PSharpRuntime.Create();

            runtime.OnFailure += delegate(Exception exception)
            {
                if (!(exception is MachineActionExceptionFilterException))
                {
                    count++;
                    tcsFail.SetException(exception);
                }
            };

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();
            Task.Delay(10).Wait(); // give it some time

            AggregateException ex = Assert.Throws <AggregateException>(() => tcsFail.Task.Wait());

            Assert.IsType <AssertionFailureException>(ex.InnerException);
            Assert.Equal(1, count);
        }
        /// <summary>
        /// Creates a new machine of the given type with an optional payload.
        /// </summary>
        /// <param name="type">Type of the machine</param>
        /// <param name="payload">Optional payload</param>
        /// <returns>Machine id</returns>
        MachineId IRemoteCommunication.CreateMachine(string type, params Object[] payload)
        {
            Output.PrintLine("Received request to create machine of type {0}", type);
            var resolvedType = PSharpRuntime.AppAssembly.GetType(type);

            return(PSharpRuntime.CreateMachine(resolvedType, payload));
        }
Esempio n. 3
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(Environment));
     runtime.Wait();
     Console.WriteLine("Done!");
 }
Esempio n. 4
0
        public static void Execute(PSharpRuntime runtime)
        {
            var s = (StateImpl)PTesterCommandLine.main_s.Clone();

            s.UserBooleanChoice = delegate()
            {
                return(runtime.Random());
            };

            s.CreateMachineCallback = delegate(PrtImplMachine machine)
            {
                PTesterCommandLine.coverage.DeclareMachine(machine);
            };

            s.DequeueCallback = delegate(PrtImplMachine machine, string evName, string senderMachineName, string senderMachineStateName)
            {
                PTesterCommandLine.coverage.ReportDequeue(machine, evName, senderMachineName, senderMachineStateName);
            };

            s.StateTransitionCallback = delegate(PrtImplMachine machine, PrtState from, PrtState to, string reason)
            {
                PTesterCommandLine.coverage.ReportStateTransition(machine, from, to, reason);
            };

            PTesterCommandLine.currentImpl = s;

            runtime.CreateMachine(typeof(PSharpMachine), new MachineInitEvent(s));
        }
Esempio n. 5
0
        public void TestUnhandledExceptionEventHandler()
        {
            var  tcsFail            = new TaskCompletionSource <bool>();
            int  count              = 0;
            bool sawFilterException = false;

            PSharpRuntime runtime = PSharpRuntime.Create();

            runtime.OnFailure += delegate(Exception exception)
            {
                // This test throws an exception that we should receive a filter call for
                if (exception is MachineActionExceptionFilterException)
                {
                    sawFilterException = true;
                    return;
                }
                count++;
                tcsFail.SetException(exception);
            };

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(N), new Configure(tcs));
            tcs.Task.Wait();
            Task.Delay(10).Wait(); // give it some time

            AggregateException ex = Assert.Throws <AggregateException>(() => tcsFail.Task.Wait());

            Assert.IsType <AssertionFailureException>(ex.InnerException);
            Assert.IsType <InvalidOperationException>(ex.InnerException.InnerException);
            Assert.Equal(1, count);
            Assert.True(sawFilterException);
        }
Esempio n. 6
0
        public void TestAssertFailureNoEventHandler()
        {
            PSharpRuntime runtime = PSharpRuntime.Create();
            var           tcs     = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();
        }
Esempio n. 7
0
 public static void Execute(PSharpRuntime runtime)
 {
     // Monitors must be registered before the first P# machine
     // gets created (which will kickstart the runtime).
     runtime.RegisterMonitor(typeof(Safety));
     runtime.RegisterMonitor(typeof(Liveness));
     runtime.CreateMachine(typeof(Driver), new Driver.Config(2));
 }
Esempio n. 8
0
        public async Task IllegalPeriodSpecificationTest()
        {
            PSharpRuntime runtime = PSharpRuntime.Create();
            var           tcs     = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(T4), new ConfigureWithPeriod(tcs, -1));
            var result = await tcs.Task;

            Assert.True(result);
        }
Esempio n. 9
0
        public async Task IllegalTimerStoppageTest()
        {
            PSharpRuntime runtime = PSharpRuntime.Create();
            var           tcs     = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(T2), new Configure(tcs, true));
            var result = await tcs.Task;

            Assert.True(result);
        }
Esempio n. 10
0
        public async Task InboxFlushOperationTest()
        {
            PSharpRuntime runtime = PSharpRuntime.Create();
            var           tcs     = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(FlushingClient), new Configure(tcs, true));
            var result = await tcs.Task;

            Assert.True(result);
        }
Esempio n. 11
0
        public async Task BasicSingleTimerOperationTest()
        {
            PSharpRuntime runtime = PSharpRuntime.Create();
            var           tcs     = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(T1), new Configure(tcs, false));
            var result = await tcs.Task;

            Assert.True(result);
        }
Esempio n. 12
0
File: Hello.cs Progetto: jzhang919/P
 public static void Execute(PSharpRuntime runtime)
 {
     PModule.runtime = runtime;
     PHelper.InitializeInterfaces();
     PHelper.InitializeEnums();
     InitializeLinkMap();
     InitializeInterfaceDefMap();
     InitializeMonitorMap(runtime);
     InitializeMonitorObserves();
     runtime.CreateMachine(typeof(_GodMachine), new _GodMachine.Config(typeof(Hello)));
 }
Esempio n. 13
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.SetLogger(new PLogger());
     PModule.runtime = runtime;
     PHelper.InitializeInterfaces();
     InitializeLinkMap();
     InitializeInterfaceDefMap();
     InitializeMonitorMap(runtime);
     InitializeMonitorObserves();
     runtime.CreateMachine(typeof(_GodMachine), new _GodMachine.Config(typeof(TestDriver)));
 }
Esempio n. 14
0
 public static void Execute(PSharpRuntime runtime)
 {
     /*
      * By default, StartTimer would create a machine of type TimerProduction, when running in production mode,
      * and a machine of type TimerModel, when running in test. You can change the type of the timer using:
      *
      * runtime.SetTimerMachineType(<YourTimerMachineType>);
      *
      * Currently, YourTimerMachineType must be a subclass of Machine.
      *
      */
     runtime.CreateMachine(typeof(Client));
 }
Esempio n. 15
0
        public static MachineId NewMachine(this PSharpRuntime @this, Type type, Event e)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            var machineId = @this.CreateMachine(type);

            if (e != null)
            {
                @this.SendEvent(machineId, e);
            }
            return(machineId);
        }
Esempio n. 16
0
        public void TestCustomLoggerNoVerbosity()
        {
            CustomLogger logger = new CustomLogger();

            PSharpRuntime runtime = PSharpRuntime.Create();

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();

            Assert.Equal("", logger.ToString());

            logger.Dispose();
        }
Esempio n. 17
0
        public void TestAssertFailureEventHandler()
        {
            var tcsFail = new TaskCompletionSource <bool>();

            PSharpRuntime runtime = PSharpRuntime.Create();

            runtime.OnFailure += delegate(Exception exception)
            {
                tcsFail.SetException(exception);
            };

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();

            AggregateException ex = Assert.Throws <AggregateException>(() => tcsFail.Task.Wait());

            Assert.IsType <AssertionFailureException>(ex.InnerException);
        }
Esempio n. 18
0
        public void TestCustomLogger()
        {
            CustomLogger logger = new CustomLogger();

            Configuration config  = Configuration.Create().WithVerbosityEnabled(2);
            PSharpRuntime runtime = PSharpRuntime.Create(config);

            runtime.SetLogger(logger);

            var tcs = new TaskCompletionSource <bool>();

            runtime.CreateMachine(typeof(M), new Configure(tcs));
            tcs.Task.Wait();

            string expected = @"<CreateLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' is created.
<StateLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' enters state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' invoked action 'InitOnEntry' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init'.
<CreateLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' is created.
<StateLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' enters state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init'.
<SendLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' sent event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E' to 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()'.
<EnqueueLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' enqueued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<DequeueLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' dequeued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' invoked action 'Act' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N.Init'.
<SendLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+N()' sent event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E' to 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()'.
<EnqueueLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' enqueued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<DequeueLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' dequeued event 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+E'.
<ActionLog> Machine 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M()' invoked action 'Act' in state 'Microsoft.PSharp.Core.Tests.Unit.CustomLoggerTest+M.Init'.
";

            string actual = Regex.Replace(logger.ToString(), "[0-9]", "");

            HashSet <string> expectedSet = new HashSet <string>(Regex.Split(expected, "\r\n|\r|\n"));
            HashSet <string> actualSet   = new HashSet <string>(Regex.Split(actual, "\r\n|\r|\n"));

            Assert.True(expectedSet.SetEquals(actualSet));

            logger.Dispose();
        }
Esempio n. 19
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(M));
 }
Esempio n. 20
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(Safety));
     runtime.CreateMachine(typeof(Driver));
 }
Esempio n. 21
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(ValidityCheck));
     runtime.CreateMachine(typeof(GodMachine));
 }
Esempio n. 22
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Employee));
 }
Esempio n. 23
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
Esempio n. 24
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TwoPhaseCommit));
 }
Esempio n. 25
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(InvariantMonitor));
     runtime.RegisterMonitor(typeof(ServerResponseSeqMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
Esempio n. 26
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TwoPhaseCommit));
 }
Esempio n. 27
0
 public static void PSharpEntryPoint()
 {
     PSharpRuntime.CreateMachine(typeof(TablesMachine));
 }
Esempio n. 28
0
 public static void Execute(PSharpRuntime runtime)
 {
     // The type "A" is visible to IntelliSense
     // (after building once)
     runtime.CreateMachine(typeof(A));
 }
Esempio n. 29
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Broker), new Broker.Config(10));
 }
Esempio n. 30
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(EventHandler));
 }
Esempio n. 31
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(ClusterManager));
 }
Esempio n. 32
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Scheduler), new Scheduler.Config(3));
 }
Esempio n. 33
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(WatchDog));
     runtime.CreateMachine(typeof(EventHandler));
 }
Esempio n. 34
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Simulation),
         new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps));
 }
Esempio n. 35
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Driver), new Driver.Config(30));
 }
Esempio n. 36
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Environment),
         new Environment.Config(Test.NumOfNodes));
 }
Esempio n. 37
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Simulation),
                           new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps));
 }
Esempio n. 38
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(M));
     runtime.CreateMachine(typeof(Environment));
 }
Esempio n. 39
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Program));
 }
Esempio n. 40
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(WatchDog));
     runtime.CreateMachine(typeof(EventHandler));
 }
Esempio n. 41
0
 public static void Execute()
 {
     PSharpRuntime.CreateMachine(typeof(Host));
 }
Esempio n. 42
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Server), "TheUltimateServerMachine");
 }
Esempio n. 43
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(ValMachineCheck));
     runtime.CreateMachine(typeof(GodMachine));
 }
Esempio n. 44
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Environment));
 }
Esempio n. 45
0
 public static void Execute(PSharpRuntime runtime)
 {
     // This is the root machine to the P# PingPong program. CreateMachine
     // executes asynchronously (i.e. non-blocking).
     runtime.CreateMachine(typeof(NetworkEnvironment));
 }
Esempio n. 46
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Receiver));
 }
Esempio n. 47
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Server));
 }
Esempio n. 48
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TaskCreator));
 }
Esempio n. 49
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Program));
 }
Esempio n. 50
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(SafetyMonitor));
     runtime.CreateMachine(typeof(ClusterManager));
 }