public object BeforeExploration(IPexExplorationComponent host) { MessageBox.Show("BeforeExploration"); // Subscribing to constraint problem handler host.Log.ProblemHandler += (problemEventArgs) => { var location = problemEventArgs.FlippedLocation.Method == null ? "" : (problemEventArgs.FlippedLocation.Method.FullName + ":" + problemEventArgs.FlippedLocation.Offset); Z3CallLocations.Add(location); }; // Subscribing to test emitting handler host.Log.GeneratedTestHandler += (generatedTestEventArgs) => { // Getting the number of the corresponding run var run = generatedTestEventArgs.GeneratedTest.Run; // Storing the result of the test (this is called before AfterRun) EmittedTestResult.Add(run, new Tuple <bool, string>(generatedTestEventArgs.GeneratedTest.IsFailure, generatedTestEventArgs.GeneratedTest.MethodCode)); }; return(null); }
public void AfterRun(IPexPathComponent host, object data) { MessageBox.Show("AfterRun"); // Getting the executions nodes in the current path var nodesInPath = host.PathServices.CurrentExecutionNodeProvider.ReversedNodes.Reverse().ToArray(); // Getting the sequence id of the current run var runId = host.ExplorationServices.Driver.Runs; // Iterating over the nodes in the path foreach (var node in nodesInPath) { var vertex = new CFGNode(node.UniqueIndex, false); // Adding the method name this early in order to color edges string methodName = null; int offset = 0; if (node.CodeLocation.Method == null) { if (node.InCodeBranch.Method != null) { methodName = node.InCodeBranch.Method.FullName; } } else { methodName = node.CodeLocation.Method.FullName; offset = node.CodeLocation.Offset; } // Setting the method name vertex.MethodName = methodName; // Setting the offset vertex.ILOffset = (uint)offset; var nodeIndex = nodesInPath.ToList().IndexOf(node); if (nodeIndex > 0) { var prevNode = nodesInPath [nodeIndex - 1]; // If there is no edge between the previous and the current node if (!(Edges.ContainsKey(prevNode.UniqueIndex) && Edges [prevNode.UniqueIndex].ContainsKey(node.UniqueIndex))) { var prevVertex = Vertices [prevNode.UniqueIndex]; var edge = new CFGEdge(new Random().Next(), prevVertex, vertex); Dictionary <int, CFGEdge> outEdges = null; if (Edges.TryGetValue(prevNode.UniqueIndex, out outEdges)) { outEdges.Add(node.UniqueIndex, edge); } else { Edges.Add(prevNode.UniqueIndex, new Dictionary <int, CFGEdge>()); Edges [prevNode.UniqueIndex].Add(node.UniqueIndex, edge); } // Edge coloring based on unit border detection if (UnitNamespace != null) { // Checking if pointing into the unit from outside if (!(prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && (vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace))) { edge.Color = CFGEdge.EdgeColor.Green; } // Checking if pointing outside the unit from inside if ((prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && !(vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace))) { edge.Color = CFGEdge.EdgeColor.Red; } } } } // If the node is new then it is added to the list and the metadata is filled if (!Vertices.ContainsKey(node.UniqueIndex)) { Vertices.Add(node.UniqueIndex, vertex); // Adding source code mapping vertex.SourceCodeMappingString = MapToSourceCodeLocationString(host, node); // Setting the border based on mapping existence vertex.Border = vertex.SourceCodeMappingString == null ? CFGNode.NodeBorder.Single : CFGNode.NodeBorder.Double; // Setting the color if (nodesInPath.LastOrDefault() == node) { if (!EmittedTestResult.ContainsKey(runId)) { vertex.Color = CFGNode.NodeColor.Orange; } else { if (EmittedTestResult [runId].Item1) { vertex.Color = CFGNode.NodeColor.Red; } else { vertex.Color = CFGNode.NodeColor.Green; } vertex.GenerateTestCode = EmittedTestResult [runId].Item2; } } else { vertex.Color = CFGNode.NodeColor.White; } // Setting the default shape vertex.Shape = CFGNode.NodeShape.Rectangle; // Adding path condition tasks and getting the required services TermEmitter termEmitter = new TermEmitter(host.GetService <TermManager>()); SafeStringWriter safeStringWriter = new SafeStringWriter(); IMethodBodyWriter methodBodyWriter = host.GetService <IPexTestManager>().Language.CreateBodyWriter(safeStringWriter, VisibilityContext.Private, 2000); PrettyPathConditionTasks.Add(vertex.Id, PrettyPrintPathCondition(termEmitter, methodBodyWriter, safeStringWriter, node)); // Setting the status vertex.Status = node.ExhaustedReason.ToString(); // Collecting the parent nodes for the later incremental path condition calculation if (nodeIndex > 0) { ParentNodes.Add(vertex.Id, nodesInPath [nodeIndex - 1].UniqueIndex); } } // Adding the Id of the run Vertices [node.UniqueIndex].Runs += (runId + ";"); } }