Пример #1
0
        /// <summary>
        /// Captures a snapshot of the program state.
        /// </summary>
        /// <param name="traceStep">Trace step</param>
        internal void CaptureState(TraceStep traceStep)
        {
            var fingerprint = PSharpRuntime.GetProgramState();
            var enabledMachines = PSharpRuntime.BugFinder.GetEnabledMachines();
            var state = new State(fingerprint, enabledMachines, PSharpRuntime.LivenessChecker.GetMonitorStatus());

            if (traceStep.Type == TraceStepType.SchedulingChoice)
            {
                Output.Debug("<LivenessDebug> Captured program state '{0}' at " +
                    "scheduling choice.", fingerprint.GetHashCode());
            }
            else if (traceStep.Type == TraceStepType.NondeterministicChoice)
            {
                Output.Debug("<LivenessDebug> Captured program state '{0}' at nondeterministic " +
                    "choice '{1}'.", fingerprint.GetHashCode(), traceStep.Choice);
            }
            else if (traceStep.Type == TraceStepType.FairNondeterministicChoice)
            {
                Output.Debug("<LivenessDebug> Captured program state '{0}' at fair nondeterministic choice " +
                    "'{1}-{2}'.", fingerprint.GetHashCode(), traceStep.NondetId, traceStep.Choice);
            }

            var stateExists = this.StateMap.Values.Any(val => val.Fingerprint.Equals(fingerprint));
            this.StateMap.Add(traceStep, state);

            if (stateExists && PSharpRuntime.Configuration.CheckLiveness)
            {
                Output.Debug("<LivenessDebug> Detected potential infinite execution.");
                PSharpRuntime.LivenessChecker.CheckLivenessAtTraceCycle(state.Fingerprint, this.StateMap);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a scheduling choice trace step.
        /// </summary>
        /// <param name="fingerprint">Fingerprint</param>
        /// <param name="scheduledMachine">Scheduled machine</param>
        /// <param name="enabledMachines">Enabled machines</param>
        /// <param name="monitorStatus">Monitor status</param>
        /// <returns>TraceStep</returns>
        internal static TraceStep CreateSchedulingChoice(Fingerprint fingerprint, Machine scheduledMachine,
            HashSet<Machine> enabledMachines, Dictionary<Monitor, MonitorStatus> monitorStatus)
        {
            var traceStep = new TraceStep();

            traceStep.IsChoice = false;
            traceStep.Fingerprint = fingerprint;

            traceStep.ScheduledMachine = scheduledMachine;
            traceStep.EnabledMachines = enabledMachines;
            traceStep.MonitorStatus = monitorStatus;

            traceStep.Previous = null;
            traceStep.Next = null;

            return traceStep;
        }
Пример #3
0
        /// <summary>
        /// Creates a nondeterministic choice trace step.
        /// </summary>
        /// <param name="fingerprint">Fingerprint</param>
        /// <param name="uniqueId">Unique nondet id</param>
        /// <param name="choice">Choice</param>
        /// <param name="enabledMachines">Enabled machines</param>
        /// <param name="monitorStatus">Monitor status</param>
        /// <returns>TraceStep</returns>
        internal static TraceStep CreateNondeterministicChoice(Fingerprint fingerprint,
            string uniqueId, bool choice, HashSet<Machine> enabledMachines,
            Dictionary<Monitor, MonitorStatus> monitorStatus)
        {
            var traceStep = new TraceStep();

            traceStep.IsChoice = true;
            traceStep.Fingerprint = fingerprint;

            traceStep.NondetId = uniqueId;
            traceStep.Choice = choice;
            traceStep.EnabledMachines = enabledMachines;
            traceStep.MonitorStatus = monitorStatus;

            traceStep.Previous = null;
            traceStep.Next = null;

            return traceStep;
        }