Exemplo n.º 1
0
        /// <summary>
        /// Returns a nondeterministic integer choice, that can be
        /// controlled during analysis or testing.
        /// </summary>
        /// <param name="machine">Machine</param>
        /// <param name="maxValue">The max value.</param>
        /// <returns>Integer</returns>
        internal override int GetNondeterministicIntegerChoice(BaseMachine machine, int maxValue)
        {
            Random random = new Random(DateTime.Now.Millisecond);
            var    result = random.Next(maxValue);

            base.Logger.OnRandom(machine?.Id, result);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enqueues an asynchronous <see cref="Event"/> to a machine.
        /// </summary>
        /// <param name="machine">Machine</param>
        /// <param name="e">Event</param>
        /// <param name="sender">Sender machine</param>
        /// <param name="operationGroupId">Operation group id</param>
        /// <param name="runNewHandler">Run a new handler</param>
        private void EnqueueEvent(Machine machine, Event e, BaseMachine sender, Guid operationGroupId, ref bool runNewHandler)
        {
            EventInfo eventInfo = new EventInfo(e, null);

            eventInfo.SetOperationGroupId(operationGroupId);

            var senderState = (sender as Machine)?.CurrentStateName ?? string.Empty;

            base.Logger.OnSend(machine.Id, sender?.Id, senderState,
                               e.GetType().FullName, operationGroupId, isTargetHalted: false);

            machine.Enqueue(eventInfo, ref runNewHandler);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a nondeterministic boolean choice, that can be
        /// controlled during analysis or testing.
        /// </summary>
        /// <param name="machine">Machine</param>
        /// <param name="maxValue">The max value.</param>
        /// <returns>Boolean</returns>
        internal override bool GetNondeterministicBooleanChoice(BaseMachine machine, int maxValue)
        {
            Random random = new Random(DateTime.Now.Millisecond);

            bool result = false;

            if (random.Next(maxValue) == 0)
            {
                result = true;
            }

            base.Logger.OnRandom(machine?.Id, result);

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends an asynchronous <see cref="Event"/> to a machine.
        /// </summary>
        /// <param name="mid">MachineId</param>
        /// <param name="e">Event</param>
        /// <param name="sender">Sender machine</param>
        /// <param name="options">Optional parameters of a send operation.</param>
        internal override void SendEvent(MachineId mid, Event e, BaseMachine sender, SendOptions options)
        {
            var operationGroupId = base.GetNewOperationGroupId(sender, options?.OperationGroupId);

            if (!base.GetTargetMachine(mid, e, sender, operationGroupId, out Machine machine))
            {
                return;
            }

            bool runNewHandler = false;

            this.EnqueueEvent(machine, e, sender, operationGroupId, ref runNewHandler);
            if (runNewHandler)
            {
                this.RunMachineEventHandler(machine, null, false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines whether the specified System.Object is equal
        /// to the current System.Object.
        /// </summary>
        /// <param name="obj">Object</param>
        /// <returns>Boolean</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            BaseMachine m = obj as BaseMachine;

            if (m == null ||
                this.GetType() != m.GetType())
            {
                return(false);
            }

            return(this.Id.Value == m.Id.Value);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns a fair nondeterministic boolean choice, that can be
 /// controlled during analysis or testing.
 /// </summary>
 /// <param name="machine">Machine</param>
 /// <param name="uniqueId">Unique id</param>
 /// <returns>Boolean</returns>
 internal override bool GetFairNondeterministicBooleanChoice(BaseMachine machine, string uniqueId)
 {
     return(this.GetNondeterministicBooleanChoice(machine, 2));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sends an asynchronous <see cref="Event"/> to a remote machine.
 /// </summary>
 /// <param name="mid">MachineId</param>
 /// <param name="e">Event</param>
 /// <param name="sender">Sender machine</param>
 /// <param name="options">Optional parameters of a send operation.</param>
 internal override void SendEventRemotely(MachineId mid, Event e, BaseMachine sender, SendOptions options)
 {
     base.NetworkProvider.RemoteSend(mid, e);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Sends an asynchronous <see cref="Event"/> to a machine. Returns immediately
        /// if the target machine was already running. Otherwise blocks until the machine handles
        /// the event and reaches quiescense again.
        /// </summary>
        /// <param name="mid">MachineId</param>
        /// <param name="e">Event</param>
        /// <param name="sender">Sender machine</param>
        /// <param name="options">Optional parameters of a send operation.</param>
        /// <returns>True if event was handled, false if the event was only enqueued</returns>
        internal override async Task <bool> SendEventAndExecute(MachineId mid, Event e, BaseMachine sender, SendOptions options)
        {
            var operationGroupId = base.GetNewOperationGroupId(sender, options?.OperationGroupId);

            if (!base.GetTargetMachine(mid, e, sender, operationGroupId, out Machine machine))
            {
                this.TryHandleDroppedEvent(e, mid);
                return(true);
            }

            bool runNewHandler = false;

            this.EnqueueEvent(machine, e, sender, operationGroupId, ref runNewHandler);
            if (runNewHandler)
            {
                await this.RunMachineEventHandlerAsync(machine, null, false);

                return(true);
            }
            return(false);
        }