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)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(LivenessMonitor)); runtime.CreateMachine(typeof(Environment)); runtime.Wait(); Console.WriteLine("Done!"); }
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)); }
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); }
public void TestAssertFailureNoEventHandler() { PSharpRuntime runtime = PSharpRuntime.Create(); var tcs = new TaskCompletionSource <bool>(); runtime.CreateMachine(typeof(M), new Configure(tcs)); tcs.Task.Wait(); }
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)); }
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); }
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); }
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); }
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); }
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))); }
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))); }
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)); }
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); }
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(); }
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); }
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(); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(LivenessMonitor)); runtime.CreateMachine(typeof(M)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(Safety)); runtime.CreateMachine(typeof(Driver)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(ValidityCheck)); runtime.CreateMachine(typeof(GodMachine)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Employee)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(LivenessMonitor)); runtime.CreateMachine(typeof(Environment)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(TwoPhaseCommit)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(InvariantMonitor)); runtime.RegisterMonitor(typeof(ServerResponseSeqMonitor)); runtime.CreateMachine(typeof(Environment)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(TwoPhaseCommit)); }
public static void PSharpEntryPoint() { PSharpRuntime.CreateMachine(typeof(TablesMachine)); }
public static void Execute(PSharpRuntime runtime) { // The type "A" is visible to IntelliSense // (after building once) runtime.CreateMachine(typeof(A)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Broker), new Broker.Config(10)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(EventHandler)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(ClusterManager)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Scheduler), new Scheduler.Config(3)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(WatchDog)); runtime.CreateMachine(typeof(EventHandler)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Simulation), new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Driver), new Driver.Config(30)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Environment), new Environment.Config(Test.NumOfNodes)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Simulation), new Simulation.Config(Test.NumOfBodies, Test.NumOfSteps)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(M)); runtime.CreateMachine(typeof(Environment)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Program)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(WatchDog)); runtime.CreateMachine(typeof(EventHandler)); }
public static void Execute() { PSharpRuntime.CreateMachine(typeof(Host)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Server), "TheUltimateServerMachine"); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(ValMachineCheck)); runtime.CreateMachine(typeof(GodMachine)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Environment)); }
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)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Receiver)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Server)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(TaskCreator)); }
public static void Execute(PSharpRuntime runtime) { runtime.CreateMachine(typeof(Program)); }
public static void Execute(PSharpRuntime runtime) { runtime.RegisterMonitor(typeof(SafetyMonitor)); runtime.CreateMachine(typeof(ClusterManager)); }