Example #1
0
        /// <summary>
        /// Captures a snapshot of the program state.
        /// </summary>
        /// <param name="state">Captured state</param>
        /// <param name="fingerprint">Fingerprint</param>
        /// <param name="fingerprintIndexMap">Fingerprint to schedule step index map</param>
        /// <param name="scheduleStep">ScheduleStep</param>
        /// <param name="monitors">List of monitors</param>
        /// <returns>True if state already exists</returns>
        internal bool CaptureState(out State state, out Fingerprint fingerprint, Dictionary <Fingerprint, List <int> > fingerprintIndexMap,
                                   ScheduleStep scheduleStep, List <Monitor> monitors)
        {
            fingerprint = Runtime.GetProgramState();
            var enabledMachineIds = Runtime.Scheduler.GetEnabledSchedulableIds();

            state = new State(fingerprint, enabledMachineIds, GetMonitorStatus(monitors));

            if (Debug.IsEnabled)
            {
                if (scheduleStep.Type == ScheduleStepType.SchedulingChoice)
                {
                    Debug.WriteLine("<LivenessDebug> Captured program state '{0}' at " +
                                    "scheduling choice.", fingerprint.GetHashCode());
                }
                else if (scheduleStep.Type == ScheduleStepType.NondeterministicChoice &&
                         scheduleStep.BooleanChoice != null)
                {
                    Debug.WriteLine("<LivenessDebug> Captured program state '{0}' at nondeterministic " +
                                    "choice '{1}'.", fingerprint.GetHashCode(), scheduleStep.BooleanChoice.Value);
                }
                else if (scheduleStep.Type == ScheduleStepType.FairNondeterministicChoice &&
                         scheduleStep.BooleanChoice != null)
                {
                    Debug.WriteLine("<LivenessDebug> Captured program state '{0}' at fair nondeterministic choice " +
                                    "'{1}-{2}'.", fingerprint.GetHashCode(), scheduleStep.NondetId, scheduleStep.BooleanChoice.Value);
                }
                else if (scheduleStep.Type == ScheduleStepType.NondeterministicChoice &&
                         scheduleStep.IntegerChoice != null)
                {
                    Debug.WriteLine("<LivenessDebug> Captured program state '{0}' at nondeterministic " +
                                    "choice '{1}'.", fingerprint.GetHashCode(), scheduleStep.IntegerChoice.Value);
                }
            }

            var stateExists = Fingerprints.Contains(fingerprint);

            Fingerprints.Add(fingerprint);
            scheduleStep.State = state;

            if (!fingerprintIndexMap.ContainsKey(fingerprint))
            {
                var hs = new List <int> {
                    scheduleStep.Index
                };
                fingerprintIndexMap.Add(fingerprint, hs);
            }
            else
            {
                fingerprintIndexMap[fingerprint].Add(scheduleStep.Index);
            }

            return(stateExists);
        }