Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MachineId"/> class.
        /// </summary>
        internal MachineId(Type type, string machineName, MachineRuntime runtime, bool useNameForHashing = false)
        {
            this.Runtime  = runtime;
            this.Endpoint = string.Empty;

            if (useNameForHashing)
            {
                this.Value     = 0;
                this.NameValue = machineName;
                this.Runtime.Assert(!string.IsNullOrEmpty(this.NameValue), "Input machine name cannot be null when used as id.");
            }
            else
            {
                // Atomically increments and safely wraps into an unsigned long.
                this.Value     = (ulong)Interlocked.Increment(ref runtime.MachineIdCounter) - 1;
                this.NameValue = string.Empty;

                // Checks for overflow.
                this.Runtime.Assert(this.Value != ulong.MaxValue, "Detected machine id overflow.");
            }

            this.Generation = runtime.Configuration.RuntimeGeneration;

            this.Type = type.FullName;
            if (this.IsNameUsedForHashing)
            {
                this.Name = this.NameValue;
            }
            else
            {
                this.Name = string.Format(CultureInfo.InvariantCulture, "{0}({1})",
                                          string.IsNullOrEmpty(machineName) ? this.Type : machineName, this.Value.ToString());
            }
        }
Exemplo n.º 2
0
 public static void Execute(IMachineRuntime 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));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Static method for safely getting a response from a machine.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <param name="mid">Target machine id.</param>
        /// <param name="ev">Event to send whose respose we're interested in getting.</param>
        public static async Task <T> GetResponse(IMachineRuntime runtime, MachineId mid, Func <MachineId, Event> ev)
        {
            var conf = new Config(mid, ev);
            // This method awaits until the GetResponseMachine finishes its Execute method
            await runtime.CreateMachineAndExecuteAsync(typeof(GetReponseMachine <T>), conf);

            // Safely return the result back (no race condition here)
            return(conf.ReceivedEvent);
        }
Exemplo n.º 4
0
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.SetLogWriter(new PLogger());
     PModule.runtime = runtime;
     PHelper.InitializeInterfaces();
     PHelper.InitializeEnums();
     InitializeLinkMap();
     InitializeInterfaceDefMap();
     InitializeMonitorMap(runtime);
     InitializeMonitorObserves();
     runtime.CreateMachine(typeof(_GodMachine), new _GodMachine.Config(typeof(Main)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new shared counter.
 /// </summary>
 /// <param name="runtime">The machine runtime.</param>
 /// <param name="value">The initial value.</param>
 public static ISharedCounter Create(IMachineRuntime runtime, int value = 0)
 {
     if (runtime is ProductionRuntime)
     {
         return(new ProductionSharedCounter(value));
     }
     else if (runtime is SystematicTestingRuntime testingRuntime)
     {
         return(new MockSharedCounter(value, testingRuntime));
     }
     else
     {
         throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + ".");
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new shared dictionary.
 /// </summary>
 /// <param name="runtime">The machine runtime.</param>
 public static ISharedDictionary <TKey, TValue> Create <TKey, TValue>(IMachineRuntime runtime)
 {
     if (runtime is ProductionRuntime)
     {
         return(new ProductionSharedDictionary <TKey, TValue>());
     }
     else if (runtime is SystematicTestingRuntime testingRuntime)
     {
         return(new MockSharedDictionary <TKey, TValue>(null, testingRuntime));
     }
     else
     {
         throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + ".");
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new shared register.
 /// </summary>
 /// <param name="runtime">The machine runtime.</param>
 /// <param name="value">The initial value.</param>
 public static ISharedRegister <T> Create <T>(IMachineRuntime runtime, T value = default)
     where T : struct
 {
     if (runtime is ProductionRuntime)
     {
         return(new ProductionSharedRegister <T>(value));
     }
     else if (runtime is SystematicTestingRuntime testingRuntime)
     {
         return(new MockSharedRegister <T>(value, testingRuntime));
     }
     else
     {
         throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + ".");
     }
 }
Exemplo n.º 8
0
 public static void Execute(IMachineRuntime runtime)
 {
     // This is the root machine to the P# PingPong program. CreateMachine
     // executes asynchronously (i.e. non-blocking).
     runtime.CreateMachine(typeof(NetworkEnvironment));
 }
Exemplo n.º 9
0
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.CreateMachine(typeof(Scheduler), new Scheduler.Config(3));
 }
Exemplo n.º 10
0
Arquivo: Test.cs Projeto: p-org/PSharp
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.CreateMachine(typeof(Host));
 }
Exemplo n.º 11
0
Arquivo: Test.cs Projeto: p-org/PSharp
        /// <summary>
        /// Gets result from the given machine.
        /// </summary>
        /// <param name="runtime">The P# runtime.</param>
        /// <param name="mid">Machine to get response from.</param>
        static async Task GetDataAndPrint(IMachineRuntime runtime, MachineId mid)
        {
            var resp = await GetReponseMachine <M1.Response> .GetResponse(runtime, mid, m => new M1.Get(m));

            Console.WriteLine("Got response: {0}", resp.v);
        }
Exemplo n.º 12
0
 public static void Execute(IMachineRuntime r)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalNetworkProvider"/> class.
 /// </summary>
 public LocalNetworkProvider(IMachineRuntime runtime)
 {
     this.Runtime       = runtime;
     this.LocalEndpoint = string.Empty;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Bind the machine id.
 /// </summary>
 internal void Bind(MachineRuntime runtime)
 {
     this.Runtime = runtime;
 }
Exemplo n.º 15
0
 public static bool FairRandom(IMachineRuntime runtime)
 {
     return(runtime.FairRandom());
 }
Exemplo n.º 16
0
 public static void InitializeMonitorMap(IMachineRuntime runtime)
 {
     PModule.monitorMap.Clear();
 }
Exemplo n.º 17
0
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(InvariantMonitor));
     runtime.RegisterMonitor(typeof(ServerResponseSeqMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
 public static void Send(IMachineRuntime runtime, MachineId target)
 {
     runtime.SendEvent(target, new E(2));
 }
Exemplo n.º 19
0
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(Environment));
 }
Exemplo n.º 20
0
Arquivo: Test.cs Projeto: p-org/PSharp
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(ValidityCheck));
     runtime.CreateMachine(typeof(GodMachine));
 }
Exemplo n.º 21
0
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.CreateMachine(typeof(TwoPhaseCommit));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Registers the testing runtime.
 /// </summary>
 public void RegisterRuntime(IMachineRuntime runtime)
 {
     runtime.Assert((runtime as SystematicTestingRuntime) != null,
                    "Requires passed runtime to support method GetCurrentMachineId");
     this.Runtime = runtime as SystematicTestingRuntime;
 }
Exemplo n.º 23
0
Arquivo: Test.cs Projeto: p-org/PSharp
 public static void Execute(IMachineRuntime runtime)
 {
     runtime.RegisterMonitor(typeof(LivenessMonitor));
     runtime.CreateMachine(typeof(ClusterManager));
 }
Exemplo n.º 24
0
 public static void Execute(IMachineRuntime runtime)
 {
     // Assigns a user-defined name to this network environment machine.
     runtime.CreateMachine(typeof(NetworkEnvironment), "TheUltimateNetworkEnvironmentMachine");
 }