Exemple #1
0
        public void EnqueueEvent(PrtValue e, PrtValue arg)
        {
            Debug.Assert(e is PrtEventValue, "Illegal enqueue of null event");
            PrtEventValue ev = e as PrtEventValue;

            if (ev.evt.maxInstances == PrtEvent.DefaultMaxInstances)
            {
                events.Add(new PrtEventNode(e, arg));
            }
            else
            {
                if (CalculateInstances(e) == ev.evt.maxInstances)
                {
                    if (ev.evt.doAssume)
                    {
                        throw new PrtAssumeFailureException();
                    }
                    else
                    {
                        throw new PrtMaxEventInstancesExceededException(
                                  String.Format(@"< Exception > Attempting to enqueue event {0} more than max instance of {1}\n", ev.evt.name, ev.evt.maxInstances));
                    }
                }
                else
                {
                    events.Add(new PrtEventNode(e, arg));
                }
            }
        }
Exemple #2
0
        public void Announce(PrtEventValue ev, PrtValue payload, PrtMachine parent)
        {
            if (ev.Equals(PrtValue.@null))
            {
                throw new PrtIllegalEnqueueException("Enqueued event must not be null");
            }

            PrtType prtType = ev.evt.payloadType;

            //assertion to check if argument passed inhabits the payload type.
            if (prtType is PrtNullType)
            {
                if (!payload.Equals(PrtValue.@null))
                {
                    throw new PrtIllegalEnqueueException("Did not expect a payload value");
                }
            }
            else if (!PrtValue.PrtInhabitsType(payload, prtType))
            {
                throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", payload.ToString(), prtType.ToString(), ev.evt.name));
            }

            var allSpecMachines = GetSpecMachines(parent.renamedName);

            foreach (var mon in allSpecMachines)
            {
                if (mon.observes.Contains(ev))
                {
                    TraceLine("<AnnounceLog> Enqueued Event <{0}, {1}> to Spec Machine {2}", ev, payload, mon.Name);
                    mon.PrtEnqueueEvent(ev, payload, parent);
                }
            }
        }
Exemple #3
0
        public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source)
        {
            if (e is PrtNullValue)
            {
                throw new PrtIllegalEnqueueException("Enqueued event must be non-null");
            }
            PrtType       prtType;
            PrtEventValue ev = e as PrtEventValue;


            //assertion to check if argument passed inhabits the payload type.
            prtType = ev.evt.payloadType;

            if (!(prtType is PrtNullType) && !PrtValue.PrtInhabitsType(arg, prtType))
            {
                throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.GetString(), prtType.GetString(), ev.evt.name));
            }
            else if (prtType is PrtNullType && !(arg is PrtNullValue))
            {
                throw new PrtIllegalEnqueueException("Did not expect a payload value");
            }

            if (currentStatus == PrtMachineStatus.Halted)
            {
                stateImpl.Trace(
                    @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped",
                    this.Name, this.instanceNumber, ev.evt.name);
            }
            else
            {
                stateImpl.Trace(
                    @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}",
                    ev.evt.name, arg.GetString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber);

                this.eventQueue.EnqueueEvent(e, arg);
                if (this.maxBufferSize != -1 && this.eventQueue.Size() > this.maxBufferSize)
                {
                    if (this.doAssume)
                    {
                        throw new PrtAssumeFailureException();
                    }
                    else
                    {
                        throw new PrtMaxBufferSizeExceededException(
                                  String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}",
                                                this.maxBufferSize, this.Name, this.instanceNumber));
                    }
                }
                if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this))
                {
                    currentStatus = PrtMachineStatus.Enabled;
                }
            }

            //Announce it to all the monitors
            stateImpl.Announce(e, arg, source);
        }
Exemple #4
0
        public void Announce(PrtEventValue ev, PrtValue payload, PrtMachine parent)
        {
            var allSpecMachines = GetSpecMachines(parent.renamedName);

            foreach (var mon in allSpecMachines)
            {
                if (mon.observes.Contains(ev))
                {
                    Trace("<AnnounceLog> Enqueued Event <{0}, {1}> to Spec Machine {2}", ev, payload, mon.Name);
                    mon.PrtEnqueueEvent(ev, payload, parent);
                }
            }
        }
Exemple #5
0
        public void EnqueueEvent(PrtValue e, PrtValue arg, string senderMachineName, string senderMachineStateName)
        {
            Debug.Assert(e is PrtEventValue, "Illegal enqueue of null event");

            var en = new PrtEventNode(e, arg, senderMachineName, senderMachineStateName);

            if (IsConcrete()) // concrete: honor k-bounded queue semantics, instance counters, etc
            {
                if (k > 0 && Size() == k)
                {
                    // Console.WriteLine("PrtEventBuffer.EnqueueEvent: queue bound {0} reached in attempt to enqueue; rejecting send event", k);
                    throw new PrtAssumeFailureException();
                }

                PrtEventValue ev = e as PrtEventValue;
                if (ev.evt.maxInstances != PrtEvent.DefaultMaxInstances) // instance counter is used
                {
                    if (CalculateInstances(e) == ev.evt.maxInstances)
                    {
                        if (ev.evt.doAssume)
                        {
                            throw new PrtAssumeFailureException();
                        }
                        else
                        {
                            throw new PrtMaxEventInstancesExceededException(String.Format(@"< Exception > Attempting to enqueue event {0} more than {1} many times\n", ev.evt.name, ev.evt.maxInstances));
                        }
                    }
                }
            }

            events.Add(en);                      // concrete or abstract

            if (IsAbstract() && Size() >= p + 2) // if the suffix was not empty before enqueuing this element
            {
                RemoveDuplicatesInSuffix();
            }
        }
Exemple #6
0
        public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source, PrtMachineValue target = null)
        {
            PrtEventValue ev = e as PrtEventValue;

            if (ev.evt.name == "null")
            {
                throw new PrtIllegalEnqueueException("Enqueued event must not be null");
            }

            //check if the sent event is in source send set
            if (!source.sends.Contains(e as PrtEventValue))
            {
                throw new PrtIllegalEnqueueException(String.Format("Machine <0> cannot send event {1}", source.Name, e.ToString()));
            }

            //check if the sent event is in target permissions
            if (target is PrtInterfaceValue)
            {
                if (!(target as PrtInterfaceValue).permissions.Contains(e as PrtEventValue))
                {
                    throw new PrtIllegalEnqueueException(String.Format("Event {1} is not in the permission set of the target", e.ToString()));
                }
            }

            PrtType prtType = ev.evt.payloadType;

            //assertion to check if argument passed inhabits the payload type.
            if (prtType is PrtNullType)
            {
                if (!arg.Equals(PrtValue.@null))
                {
                    throw new PrtIllegalEnqueueException("Did not expect a payload value");
                }
            }
            else if (!PrtValue.PrtInhabitsType(arg, prtType))
            {
                throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.ToString(), prtType.ToString(), ev.evt.name));
            }

            //check if the event sent is in the permissions

            if (currentStatus == PrtMachineStatus.Halted)
            {
                stateImpl.Trace(
                    @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped",
                    this.Name, this.instanceNumber, ev.evt.name);
            }
            else
            {
                stateImpl.Trace(
                    @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}",
                    ev.evt.name, arg.ToString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber);
                this.eventQueue.EnqueueEvent(e, arg);
                if (this.maxBufferSize != DefaultMaxBufferSize && this.eventQueue.Size() > this.maxBufferSize)
                {
                    if (this.doAssume)
                    {
                        throw new PrtAssumeFailureException();
                    }
                    else
                    {
                        throw new PrtMaxBufferSizeExceededException(
                                  String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}",
                                                this.maxBufferSize, this.Name, this.instanceNumber));
                    }
                }
                if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this))
                {
                    currentStatus = PrtMachineStatus.Enabled;
                }
            }

            //Announce it to all the spec machines
            stateImpl.Announce(e as PrtEventValue, arg, source);
        }
Exemple #7
0
 public void AddAction(Tuple <string, int> t, PrtEventValue e, PrtValue v)
 {
     trace.Add(new SendAction(t, e.evt.name, v));
 }