示例#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);
            }
        }