Esempio n. 1
0
        public bool DequeueEvent(PrtImplMachine owner)
        {
            HashSet <PrtValue> deferredSet;
            HashSet <PrtValue> receiveSet;

            deferredSet = owner.CurrentDefferedSet;
            receiveSet  = owner.receiveSet;

            int iter = 0;

            while (iter < events.Count)
            {
                if ((receiveSet.Count == 0 && !deferredSet.Contains(events[iter].ev)) ||
                    (receiveSet.Count > 0 && receiveSet.Contains(events[iter].ev)))
                {
                    owner.currentTrigger           = events[iter].ev;
                    owner.currentPayload           = events[iter].arg;
                    owner.currentTriggerSenderInfo = Tuple.Create(events[iter].senderMachineName, events[iter].senderMachineStateName);
                    events.Remove(events[iter]);
                    return(true);
                }
                else
                {
                    iter++;
                }
            }

            return(false);
        }
Esempio n. 2
0
        public bool DequeueEvent(PrtImplMachine owner)
        {
            HashSet <PrtEventValue> deferredSet;
            HashSet <PrtValue>      receiveSet;

            deferredSet = owner.CurrentState.deferredSet;
            receiveSet  = owner.receiveSet;

            int iter = 0;

            while (iter < events.Count)
            {
                if ((receiveSet.Count == 0 && !deferredSet.Contains(events[iter].ev)) ||
                    (receiveSet.Count > 0 && receiveSet.Contains(events[iter].ev)))
                {
                    owner.currentTrigger = events[iter].ev;
                    owner.currentPayload = events[iter].arg;
                    events.Remove(events[iter]);
                    return(true);
                }
                else
                {
                    continue;
                }
            }

            return(false);
        }
Esempio n. 3
0
        public bool DequeueEvent(PrtImplMachine owner)
        {
            HashSet <PrtValue> deferredSet = owner.CurrentDeferredSet;
            HashSet <PrtValue> receiveSet  = owner.receiveSet;

            int iter = 0;

            idxOfLastDequeuedEvent = events.Count + 1; // if, AFTER DequeueEvent, last_... = Count + 1, nothing was dequeued. Otherwise last_... will be <= Count and points to the OLD index dequeued
            while (iter < events.Count)
            {
                if ((receiveSet.Count == 0 && !deferredSet.Contains(events[iter].ev)) ||  // we check deferredSet and receiveSet only against ev (event type), not arg
                    (receiveSet.Count > 0 && receiveSet.Contains(events[iter].ev)))
                {
                    owner.currentTrigger           = events[iter].ev;
                    owner.currentPayload           = events[iter].arg;
                    owner.currentTriggerSenderInfo = Tuple.Create(events[iter].senderMachineName, events[iter].senderMachineStateName);
                    events.Remove(events[iter]);
                    idxOfLastDequeuedEvent = iter;
                    return(true);
                }
                else
                {
                    iter++;
                }
            }

            return(false);
        }
Esempio n. 4
0
        public PrtInterfaceValue CreateInterface(PrtImplMachine currMach, string interfaceOrMachineName, PrtValue payload)
        {
            //add visible action to trace
            if (visibleInterfaces.Contains(interfaceOrMachineName))
            {
                currentVisibleTrace.AddAction(interfaceOrMachineName, payload.ToString());
            }

            var renamedImpMachine = linkMap[currMach.renamedName][interfaceOrMachineName];
            var impMachineName    = machineDefMap[renamedImpMachine];
            var machine           = createMachineMap[impMachineName](this, payload);

            machine.isSafe      = isSafeMap[renamedImpMachine];
            machine.renamedName = renamedImpMachine;
            AddImplMachineToStateImpl(machine);

            CreateMachineCallback?.Invoke(machine);

            //TraceLine("<CreateLog> Machine {0}-{1} was created by machine {2}-{3}", currMach.renamedName, currMach.instanceNumber, machine.renamedName, machine.instanceNumber);
            TraceLine("<CreateLog> Machine {0}-{1} was created by machine {2}-{3}", machine.renamedName, machine.instanceNumber, currMach.renamedName, currMach.instanceNumber);

            if (interfaceMap.ContainsKey(interfaceOrMachineName))
            {
                return(new PrtInterfaceValue(machine, interfaceMap[interfaceOrMachineName]));
            }
            else
            {
                return(new PrtInterfaceValue(machine, machine.self.permissions));
            }
        }
Esempio n. 5
0
 public PrtInterfaceValue(PrtImplMachine m, List <PrtEventValue> perm) : base(m)
 {
     permissions = new List <PrtEventValue>();
     foreach (var ev in perm)
     {
         permissions.Add(ev);
     }
 }
Esempio n. 6
0
 public PrtContinuation()
 {
     reason         = PrtContinuationReason.Return;
     createdMachine = null;
     retVal         = null;
     nondet         = false;
     retLocals      = new List <PrtValue>();
     receiveIndex   = -1;
 }
Esempio n. 7
0
 public Boolean GetSelectedChoiceValue(PrtImplMachine process)
 {
     if (UserBooleanChoice != null)
     {
         return(UserBooleanChoice());
     }
     else
     {
         //throw new NotImplementedException();
         return((new Random(DateTime.Now.Millisecond)).Next(10) > 5);
     }
 }
Esempio n. 8
0
        public bool IsEnabled(PrtImplMachine owner)
        {
            HashSet <PrtEventValue> deferredSet;
            HashSet <PrtValue>      receiveSet;

            deferredSet = owner.CurrentState.deferredSet;
            receiveSet  = owner.receiveSet;
            foreach (var evNode in events)
            {
                if ((receiveSet.Count == 0 && !deferredSet.Contains(evNode.ev)) ||
                    (receiveSet.Count > 0 && receiveSet.Contains(evNode.ev)))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Compute the abstract successors caused by updating the queue of <paramref name="currIndex"/> machine.
        ///
        /// </summary>
        /// <param name="currIndex">The index for the machine about to explore</param>
        /// <param name="abstract_succs"></param>
        /// <param name="abstract_succs_SW"></param>
        void CollectAbstractSuccessorsFromList(int currIndex, HashSet <int> abstract_succs, StreamWriter abstract_succs_SW)
        {
            List <PrtEventNode> preDequeEvents = ImplMachines[currIndex].eventQueue.events; // pre-dequeue events list

            var  choiceVector = new List <bool>();
            bool more;

            do
            {
                StateImpl           succ           = (StateImpl)Clone();
                PrtImplMachine      machineOfSucc  = succ.ImplMachines[currIndex]; // the machine of successor indexing in currIndex
                PrtEventBuffer      queueOfMachine = machineOfSucc.eventQueue;     // the message queue of successor machine
                List <PrtEventNode> queueEvents    = queueOfMachine.events;        // the events list of successor machine

                more = machineOfSucc.PrtRunStateMachineNextChoice(choiceVector);
                Debug.Assert(preDequeEvents.Count - queueOfMachine.Size() <= 1); // we have dequeued at most one event
                /// If dequeing was unsuccessful, then there is nothing left to do.
                /// No more nondeterministic choices to try
                if (preDequeEvents.Count == queueOfMachine.Size() || succ.CheckFailure(0)) //
                {
                    return;                                                                //
                }
                int          idxOfEventDequeuedFromSuffix = Math.Max(PrtEventBuffer.idxOfLastDequeuedEvent, PrtEventBuffer.p);
                PrtEventNode eventDequeuedFromSuffix      = preDequeEvents[idxOfEventDequeuedFromSuffix];

                /// <remarks>Choice 1: </remarks> The eventDequeuedFromSuffix, aka the last dequeued event, existed
                /// exactly once in the concrete suffix.
                /// Then it is gone after the dequeue, in both abstract and concrete. The new state abstract is valid.
                succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);

                ///  <remarks>Choice 1: </remarks> The eventDequeuedFromSuffix, aka the last dequeued event, existed
                ///  >= twice in concrete suffix.
                ///  We need to find all positions where to re-introduce it in the abstract queue, and try them all
                ///  non-deterministically.
                for (int pos = idxOfEventDequeuedFromSuffix; pos < queueOfMachine.Size(); ++pos)
                {
                    // insert eventDequeuedFromSuffix at position pos (push the rest to the right)
                    queueEvents.Insert(pos, eventDequeuedFromSuffix);
                    succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);
                    queueEvents.RemoveAt(pos);            // restore previous state
                }
                queueEvents.Add(eventDequeuedFromSuffix); // finally, insert eventDequeuedFromSuffix at end
                succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);
            } while (more);
        }
Esempio n. 10
0
        /// <summary>
        /// -- PL: compute all abstract successors of current state. Note: the computation is done by
        /// abstract interpretation.
        /// </summary>
        /// <param name="abstract_succs"></param>
        /// <param name="abstract_succs_SW"></param>
        public void CollectAbstractSuccessors(HashSet <int> abstract_succs, StreamWriter abstract_succs_SW)
        {
            for (int currIndex = 0; currIndex < ImplMachines.Count; ++currIndex)
            {
                PrtImplMachine machine = ImplMachines[currIndex];

                /// reject disabled machines
                if (!(machine.currentStatus == PrtMachineStatus.Enabled))
                {
                    continue;
                }

                /// reject machines not dequeing or receiving. I assume these are the only two
                /// that can lead to a call to PrtDequeueEvent
                if (!(machine.nextSMOperation == PrtNextStatemachineOperation.DequeueOperation ||
                      machine.nextSMOperation == PrtNextStatemachineOperation.ReceiveOperation))
                {
                    continue;
                }

                /// reject machines with empty queues. Apparently enabled machines whose
                /// nextSMOperation is dequeue or receive may have still an empty queue.
                if (machine.eventQueue.Empty())
                {
                    continue;
                }

                /// reject "non-abstract" queues: those with empty suffix. In this case the abstraction is precise,
                /// so the successor function cannot generate anything new
                if (machine.eventQueue.Size() <= PrtEventBuffer.p) // prefix
                {
                    continue;
                }

                CollectAbstractSuccessorsFromList(currIndex, abstract_succs, abstract_succs_SW);
            }
        }
Esempio n. 11
0
 public void AddImplMachineToStateImpl(PrtImplMachine machine)
 {
     implMachines.Add(machine);
 }
Esempio n. 12
0
 void PrtFunContNewMachine(PrtFun fun, List <PrtValue> locals, PrtImplMachine o, int ret)
 {
     PrtPushFunStackFrame(fun, locals, ret);
     continuation.reason         = PrtContinuationReason.NewMachine;
     continuation.createdMachine = o;
 }
Esempio n. 13
0
 public PrtMachineValue(PrtImplMachine mach)
 {
     this.mach = mach;
 }
Esempio n. 14
0
 public override void Resolve(StateImpl state)
 {
     mach = state.ImplMachines.First(m => m.renamedName == mach.renamedName && m.instanceNumber == mach.instanceNumber);
 }
Esempio n. 15
0
 public void SetPendingChoicesAsBoolean(PrtImplMachine process)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 public void SetPendingChoicesAsBoolean(PrtImplMachine process)
 {
     //TODO: NOT IMPLEMENT YET
     //throw new NotImplementedException();
 }
Esempio n. 17
0
 public object GetSelectedChoiceValue(PrtImplMachine process)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
 public Boolean GetSelectedChoiceValue(PrtImplMachine process)
 {
     //throw new NotImplementedException();
     return((new Random(1)).Next(1) == 0);
 }