protected override void SearchStateSpace(object obj) { int myThreadId = (int)obj; int numberOfSchedulesExplored = 0; //frontier FrontierNode startfN = new FrontierNode(StartStateTraversalInfo); TraversalInfo startState = startfN.GetTraversalInfo(StartStateStateImpl, myThreadId); var statesExplored = new HashSet<Fingerprint>(); while (numberOfSchedulesExplored < ZingerConfiguration.MaxSchedulesPerIteration) { //increment the schedule count numberOfSchedulesExplored++; ZingerStats.IncrementNumberOfSchedules(); //random walk always starts from the start state ( no frontier ). TraversalInfo currentState = startState.Clone(); statesExplored.Clear(); while (currentState.CurrentDepth < ZingerConfiguration.MaxDepthPerSchedule) { //kil the exploration if bug found //Check if cancelation token triggered if (CancelTokenZingExplorer.IsCancellationRequested) { //some task found bug and hence cancelling this task return; } ZingerStats.MaxDepth = Math.Max(ZingerStats.MaxDepth, currentState.CurrentDepth); //Check if the DFS Stack Overflow has occured. if (currentState.CurrentDepth > ZingerConfiguration.BoundDFSStackLength) { //update the safety traces SafetyErrors.Add(currentState.GenerateNonCompactTrace()); // return value this.lastErrorFound = ZingerResult.DFSStackOverFlowError; throw new ZingerDFSStackOverFlow(); } TraversalInfo nextSuccessor = currentState.GetNextSuccessorUniformRandomly(); ZingerStats.IncrementTransitionsCount(); ZingerStats.IncrementStatesCount(); if (nextSuccessor == null) { break; } //check if the next step is entered through a accepting transition if(nextSuccessor.IsAcceptingState && nextSuccessor.IsFingerPrinted && statesExplored.Contains(nextSuccessor.Fingerprint)) //if (nextSuccessor.IsFingerPrinted && statesExplored.Contains(nextSuccessor.Fingerprint)) { AcceptingCycles.Add(nextSuccessor.GenerateNonCompactTrace()); lastErrorFound = ZingerResult.AcceptanceCyleFound; if (ZingerConfiguration.StopOnError) throw new ZingerAcceptingCycleFound(); } //add the current state in the set. if(nextSuccessor.IsFingerPrinted) statesExplored.Add(nextSuccessor.Fingerprint); TerminalState terminalState = nextSuccessor as TerminalState; if (terminalState != null) { if (terminalState.IsErroneousTI) { lock (SafetyErrors) { // bugs found SafetyErrors.Add(nextSuccessor.GenerateNonCompactTrace()); this.lastErrorFound = nextSuccessor.ErrorCode; } if (ZingerConfiguration.StopOnError) { CancelTokenZingExplorer.Cancel(true); throw nextSuccessor.Exception; } } break; } currentState = nextSuccessor; } } }
private void FrontierNodeReader(object obj) { if (ZingerConfiguration.FrontierToDisk) { string inputFileName = obj as string; if (File.Exists(inputFileName)) { Stream sreader = File.Open(inputFileName, FileMode.Open); while (sreader.Position < sreader.Length) { var fNode = new FrontierNode(); fNode.Deserialize(sreader); currFrontierSet.Add(fNode); } sreader.Close(); } } }
/// <summary> /// Constructor /// </summary> public FrontierSet(TraversalInfo startState) { if (!ZingerConfiguration.FrontierToDisk) { InMemoryCurrentGlobalFrontier = new ConcurrentQueue<FrontierNode>(); InMemoryNextGlobalFrontier = new ConcurrentDictionary<Fingerprint, FrontierNode>(); InMemoryNextGlobalFrontier.TryAdd(startState.Fingerprint, new FrontierNode(startState)); } else { currFrontierSet = new BlockingCollection<FrontierNode>(bufferSize); nextFrontierSet = new BlockingCollection<KeyValuePair<Fingerprint, FrontierNode>>(2 * bufferSize); nextFrontierSetHT = new HashSet<Fingerprint>(); readerWorkers = new Task[numOfRWThreads]; writerWorkers = new Task[numOfRWThreads]; counter = 0; currFrontierSet.Add(new FrontierNode(startState)); for (int i = 0; i < numOfRWThreads; i++) { File.Delete("i_" + i.ToString()); File.Delete("o_" + i.ToString()); } //put the start frontier onto disk var startFrontier = new FrontierNode(startState); Stream writeStream = File.Open("o_0", FileMode.Create); startFrontier.Serialize(writeStream); writeStream.Close(); } }
public void Add(TraversalInfo ti) { //no need of adding to the frontier if the final choice bound is reached if (ZingerConfiguration.BoundChoices && ti.zBounds.ChoiceCost >= ZingerConfiguration.zBoundedSearch.FinalChoiceCutOff) { return; } Fingerprint fp = ti.Fingerprint; ti.IsFingerPrinted = true; if (ZingerConfiguration.FrontierToDisk) { if (!nextFrontierSetHT.Contains(fp)) { FrontierNode fNode = new FrontierNode(ti); counter++; nextFrontierSetHT.Add(fp); //Add the item into current next frontier blocking collection nextFrontierSet.Add(new KeyValuePair<Fingerprint, FrontierNode>(fp, fNode)); } } else { if (!InMemoryNextGlobalFrontier.ContainsKey(fp)) { FrontierNode fNode = new FrontierNode(ti); //add the item into in memory next frontier InMemoryNextGlobalFrontier.TryAdd(fp, fNode); } } }
protected override void SearchStateSpace(object obj) { int myThreadId = (int)obj; //maximum number of schedules per iteration = c1 + c2^d. // c1 = ZingerConfiguration.MaxSchedulesPerIteration. // c2 = 3 as we found that to work the best. int maxSchedulesPerIteration = ZingerConfiguration.MaxSchedulesPerIteration + ZingerConfiguration.zBoundedSearch.IterativeCutoff; int delayBudget = 0; Stack<TraversalInfo> searchStack = new Stack<TraversalInfo>(); //frontier FrontierNode startfN = new FrontierNode(StartStateTraversalInfo); TraversalInfo startState = startfN.GetTraversalInfo(StartStateStateImpl, myThreadId); while (ZingerConfiguration.numberOfSchedulesExplored < maxSchedulesPerIteration) { //kil the exploration if bug found //Check if cancelation token triggered if (CancelTokenZingExplorer.IsCancellationRequested) { //some task found bug and hence cancelling this task return; } delayBudget = ZingerConfiguration.zBoundedSearch.IterativeCutoff; //increment the schedule count Interlocked.Increment(ref ZingerConfiguration.numberOfSchedulesExplored); ZingerStats.IncrementNumberOfSchedules(); searchStack = new Stack<TraversalInfo>(); searchStack.Push(startState); int lastStartPoint = 1; while (delayBudget > 0) { RunToCompletionWithDelayZero(searchStack); lastStartPoint = RandomBackTrackAndDelay(searchStack, lastStartPoint); if (lastStartPoint == -1) { break; } delayBudget--; } } }