예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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));
 }
예제 #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);
 }
예제 #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);
        }