Ejemplo 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);
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(Environment));
     runtime.Wait();
     Console.WriteLine("Done!");
 }
Ejemplo 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));
        }
Ejemplo 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);
        }
Ejemplo 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();
        }
Ejemplo 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));
 }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 12
0
Archivo: Hello.cs Proyecto: 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)));
 }
Ejemplo 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)));
 }
Ejemplo 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));
 }
Ejemplo 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);
        }
Ejemplo 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();
        }
Ejemplo 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);
        }
Ejemplo 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();
        }
Ejemplo n.º 19
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(M));
 }
Ejemplo n.º 20
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(Safety));
     runtime.CreateMachine(typeof(Driver));
 }
Ejemplo n.º 21
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(ValidityCheck));
     runtime.CreateMachine(typeof(GodMachine));
 }
Ejemplo n.º 22
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Employee));
 }
Ejemplo n.º 23
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
Ejemplo n.º 24
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TwoPhaseCommit));
 }
Ejemplo n.º 25
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(InvariantMonitor));
     runtime.RegisterMonitor(typeof(ServerResponseSeqMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
Ejemplo n.º 26
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TwoPhaseCommit));
 }
Ejemplo n.º 27
0
 public static void PSharpEntryPoint()
 {
     PSharpRuntime.CreateMachine(typeof(TablesMachine));
 }
Ejemplo n.º 28
0
 public static void Execute(PSharpRuntime runtime)
 {
     // The type "A" is visible to IntelliSense
     // (after building once)
     runtime.CreateMachine(typeof(A));
 }
Ejemplo n.º 29
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Broker), new Broker.Config(10));
 }
Ejemplo n.º 30
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(EventHandler));
 }
Ejemplo n.º 31
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(ClusterManager));
 }
Ejemplo n.º 32
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Scheduler), new Scheduler.Config(3));
 }
Ejemplo n.º 33
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(WatchDog));
     runtime.CreateMachine(typeof(EventHandler));
 }
Ejemplo n.º 34
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Simulation),
         new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps));
 }
Ejemplo n.º 35
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Driver), new Driver.Config(30));
 }
Ejemplo n.º 36
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Environment),
         new Environment.Config(Test.NumOfNodes));
 }
Ejemplo n.º 37
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Simulation),
                           new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps));
 }
Ejemplo n.º 38
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(M));
     runtime.CreateMachine(typeof(Environment));
 }
Ejemplo n.º 39
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Program));
 }
Ejemplo n.º 40
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(WatchDog));
     runtime.CreateMachine(typeof(EventHandler));
 }
Ejemplo n.º 41
0
 public static void Execute()
 {
     PSharpRuntime.CreateMachine(typeof(Host));
 }
Ejemplo n.º 42
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Server), "TheUltimateServerMachine");
 }
Ejemplo n.º 43
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(ValMachineCheck));
     runtime.CreateMachine(typeof(GodMachine));
 }
Ejemplo n.º 44
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Environment));
 }
Ejemplo 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));
 }
Ejemplo n.º 46
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Receiver));
 }
Ejemplo n.º 47
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Server));
 }
Ejemplo n.º 48
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(TaskCreator));
 }
Ejemplo n.º 49
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.CreateMachine(typeof(Program));
 }
Ejemplo n.º 50
0
 public static void Execute(PSharpRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(SafetyMonitor));
     runtime.CreateMachine(typeof(ClusterManager));
 }