private void PexLog(IPexPathComponent host, string title, string text) { if (verbose) { host.Log.Dump(title, title, text); } }
void IPexPathPackage.AfterRun(IPexPathComponent host, object data) { FieldAccessPathObserver fieldAccessPathObserver = ServiceProviderHelper.GetService <FieldAccessPathObserver>(host.Site); fieldAccessPathObserver.Analyze(); }
private static string prettyPrintPathCondition(IPexPathComponent host, Term[] pathConditions) { var writer = new SafeStringWriter(); var codeWriter = host.Services.TestManager.Language.CreateBodyWriter( writer, VisibilityContext.Private, 100); var emitter = new TermEmitter( host.ExplorationServices.TermManager, new NameCreator()); for (int i = pathConditions.Length - 1; i >= 0; i--) { var pathCondition = pathConditions[i]; if (!emitter.TryEvaluate( new Term[] { pathCondition }, 10000, // bound on size of expression we are going to pretty-print codeWriter)) { writer.WriteLine("(expression too big; consider using environment variable {0})", ExtendedReflectionEnvironmentSettings.NoCodeEmitterSizeLimit.Name); } else { writer.WriteLine("path condition: " + pathCondition.GetType()); codeWriter.Return(SystemTypes.Bool); } } return(writer.ToString()); }
/// <summary> /// The method, which is called before each Pex run. /// </summary> /// <param name="host"></param> /// <returns></returns> protected override object BeforeRun(IPexPathComponent host) { pathComponent = host; var runStorage = host.GetService <PexRunAndTestStorageComponent>(); return(new Tuple <PexExecutionNodeStorageComponent, PexRunAndTestStorageComponent>(host.GetService <PexExecutionNodeStorageComponent>(), runStorage)); }
protected override void AfterRun(IPexPathComponent host, object data) { Term[] pathConditions = new Term[] {}; IList <Term> conditions = null; IList <CodeLocation> locations = null; SafeSet <Method> trackingMethods = null; var database = host.GetService <IssueTrackDatabase>(); var unInstrumentedMethods = database.UnInstrumentedMethods; log = database.SimpleLog; foreach (var unInstrumentedMethod in unInstrumentedMethods) { var controller = new ResultTracer(host, unInstrumentedMethod.Method, log); log.AppendLine("try tracking " + unInstrumentedMethod.Method.FullName); log.AppendLine("*****************************************************"); using (IEngine trackingEngine = host.PathServices.TrackingEngineFactory.CreateTrackingEngine(controller)) { trackingEngine.GetService <IPexTrackingDriver>().Run(); pathConditions = Enumerable.ToArray(controller.PathConditions); conditions = controller.Conditions; locations = controller.Locations; trackingMethods = controller.TrackingMethods; } PexLog(host, "ResultTracing", prettyPrintPathCondition(host, pathConditions)); // log.AppendLine("condition: " + prettyPrintPathCondition(host, pathConditions)); PexLog(host, "tracking methods", trackingMethods.Select(x => x.FullName)); for (int i = 0; i < conditions.Count; i++) { var condition = conditions[i]; using (var extractor = new ResultTrackConditionExtractor(host.ExplorationServices.TermManager)) { extractor.VisitTerm(default(TVoid), condition); if (extractor.Method == null) { host.Log.Dump("method", "not in branch", "null"); continue; } PexLog(host, "method", extractor.Method.FullName); PexLog(host, "offset", extractor.CallerOffset.ToString("x")); PexLog(host, "location", extractor.Location.ToString()); var method = extractor.Signature as Method; PexLog(host, "signature", method.FullName); log.AppendLine("found method: " + method.FullName + " in branch " + locations[i]); if (!host.GetService <IssueTrackDatabase>().UninstrumentedMethodInBranch.ContainsKey(locations[i])) { host.GetService <IssueTrackDatabase>().UninstrumentedMethodInBranch.Add(locations[i], method); } } } PexLog(host, "location", locations.Select(x => x.ToString())); log.AppendLine("*****************************************************"); } log.AppendLine("========================="); }
private void PexLog(IPexPathComponent host, string title, IEnumerable <string> text) { if (verbose) { host.Log.LogMessage(title, title + " start"); foreach (var t in text) { host.Log.Dump(title, title, t); } host.Log.LogMessage(title, title + " start"); } }
/// <summary> /// Gets invoked after each run, which happens for each path in the exploration /// </summary> /// <param name="host"></param> /// <param name="data"></param> void IPexPathPackage.AfterRun(IPexPathComponent host, object data) { if (pathObserver != null) { pathObserver = host.GetService <IFieldAccessPathObserver>(); } pathObserver.Analyze(); //aggregate the coverage this.pmd.AccumulateMaxCoverage(host.ExplorationServices.Driver.TotalCoverageBuilder); //Check whether any uncovered locations are covered and then store the associated sequence this.pmd.CheckForNewlyCoveredLocations(); }
/// <summary> /// Maps the execution node to source code location string. /// </summary> /// <param name="host">Host of the Pex Path Component</param> /// <param name="node">The execution node to map</param> /// <returns>The source code location string in the form of [documentlocation]:[linenumber]</returns> private string MapToSourceCodeLocationString(IPexPathComponent host, IExecutionNode node) { MessageBox.Show("MapToSourceCodeLocationString()"); try { var symbolManager = host.GetService <ISymbolManager>(); var sourceManager = host.GetService <ISourceManager>(); MethodDefinitionBodyInstrumentationInfo nfo; if (node.CodeLocation.Method == null) { if (node.InCodeBranch.Method == null) { return(null); } else { node.InCodeBranch.Method.TryGetBodyInstrumentationInfo(out nfo); } } else { node.CodeLocation.Method.TryGetBodyInstrumentationInfo(out nfo); } SequencePoint point; int targetOffset; nfo.TryGetTargetOffset(node.InCodeBranch.BranchLabel, out targetOffset); if (symbolManager.TryGetSequencePoint(node.CodeLocation.Method == null ? node.InCodeBranch.Method : node.CodeLocation.Method, node.CodeLocation.Method == null ? targetOffset : node.CodeLocation.Offset, out point)) { return(point.Document + ":" + point.Line); } else { return(null); } } catch (Exception) { // TODO Exception handling return(null); } }
private static string prettyPrintPathCondition(IPexPathComponent host, Term[] pathConditions) { var writer = new SafeStringWriter(); var codeWriter = host.Services.TestManager.Language.CreateBodyWriter( writer, VisibilityContext.Private, 100); var emitter = new TermEmitter( host.ExplorationServices.TermManager, new NameCreator()); for (int i = pathConditions.Length - 1; i >= 0; i--) { var pathCondition = pathConditions[i]; if (!emitter.TryEvaluate( new Term[] {pathCondition}, 10000, // bound on size of expression we are going to pretty-print codeWriter)) { writer.WriteLine("(expression too big; consider using environment variable {0})", ExtendedReflectionEnvironmentSettings.NoCodeEmitterSizeLimit.Name); } else { writer.WriteLine("path condition: " + pathCondition.GetType()); codeWriter.Return(SystemTypes.Bool); } } return writer.ToString(); }
protected override object BeforeRun(IPexPathComponent host) { return null; }
public ResultTracer(IPexPathComponent component, MethodName trackMethod, StringBuilder log) { host = component; _trackMethod = trackMethod; _log = log; }
object IPexPathPackage.BeforeRun(IPexPathComponent host) { 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 + ";"); } }
public object BeforeRun(IPexPathComponent host) { return(null); }
public ResultTracer(IPexPathComponent component, MethodName trackMethod,StringBuilder log) { host = component; _trackMethod = trackMethod; _log = log; }
protected override object BeforeRun(IPexPathComponent host) { return(null); }
private void PexLog(IPexPathComponent host, string title, IEnumerable<string> text) { if (verbose) { host.Log.LogMessage(title, title + " start"); foreach (var t in text) { host.Log.Dump(title, title, t); } host.Log.LogMessage(title, title + " start"); } }
/// <summary> /// The method, which is called after each Pex run. /// </summary> /// <param name="host"></param> /// <param name="data"></param> protected override void AfterRun(IPexPathComponent host, object data) { try { var nodesInPath = host.PathServices.CurrentExecutionNodeProvider.ReversedNodes.Reverse().ToArray(); var storage = ((Tuple <PexExecutionNodeStorageComponent, PexRunAndTestStorageComponent>)data).Item1; var runStorage = ((Tuple <PexExecutionNodeStorageComponent, PexRunAndTestStorageComponent>)data).Item2; var numberOfRuns = host.ExplorationServices.Driver.Runs; if (runStorage.Runs.Where(t => t.Item1 == numberOfRuns).FirstOrDefault() == null) { runStorage.Runs.Add(new Tuple <int, int>(numberOfRuns, 0)); } var nodeIndexes = new List <int>(); foreach (var node in nodesInPath) { nodeIndexes.Add(node.UniqueIndex); if (storage.NodeInstances.ContainsKey(node.UniqueIndex)) { storage.NodeInstances.Remove(node.UniqueIndex); } storage.NodeInstances.Add(node.UniqueIndex, node); var gvStringBuilder = new StringBuilder(); var ind = nodesInPath.ToList().IndexOf(node); IExecutionNode prevNode = null; if (ind > 0) { prevNode = nodesInPath[ind - 1]; List <int> knownSuccessors = new List <int>(); if (storage.KnownSuccessors.ContainsKey(prevNode.UniqueIndex)) { knownSuccessors = storage.KnownSuccessors[prevNode.UniqueIndex]; } if (!knownSuccessors.Contains(node.UniqueIndex)) { var splittedIncludeList = new List <string>(includeList.Split(';').ToArray()); if (prevNode.CodeLocation.Method != null && splittedIncludeList.Count > 0 && node.CodeLocation.Method != null) { if ((prevNode.CodeLocation.Method.FullName.StartsWith("System") || prevNode.CodeLocation.Method.FullName.StartsWith("Microsoft") || splittedIncludeList.Where(e => prevNode.CodeLocation.Method.FullName.StartsWith(e)).Count() > 0) && (!node.CodeLocation.Method.FullName.StartsWith("System") && !node.CodeLocation.Method.FullName.StartsWith("Microsoft") && splittedIncludeList.Where(e => node.CodeLocation.Method.FullName.StartsWith(e)).Count() == 0)) { gvStringBuilder.AppendLine(prevNode.UniqueIndex + " -> " + node.UniqueIndex + " [color=red]"); } else { gvStringBuilder.AppendLine(prevNode.UniqueIndex + " -> " + node.UniqueIndex); } } else { gvStringBuilder.AppendLine(prevNode.UniqueIndex + " -> " + node.UniqueIndex); } knownSuccessors.Add(node.UniqueIndex); } storage.KnownSuccessors.Remove(prevNode.UniqueIndex); storage.KnownSuccessors.Add(prevNode.UniqueIndex, knownSuccessors); } gvStringBuilder.AppendLine(CreateSameRankStatement(node, storage)); using (var gvWriter = new StreamWriter(outFileUrl, true)) { gvWriter.WriteLine(gvStringBuilder.ToString()); } if (storage.Nodes.Where(n => n.Item1 == node.UniqueIndex).Count() == 0) { using (var infoWriter = new StreamWriter(outFileUrl + ".info", true)) { infoWriter.WriteLine("<Tip Tag=\"" + node.UniqueIndex + "\">"); infoWriter.WriteLine("<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\">"); var tuple = MapToSourceCode(host, node); if (tuple != null) { using (var gvWriter = new StreamWriter(outFileUrl, true)) { gvWriter.WriteLine(node.UniqueIndex + " [ color=\"gray\" peripheries=2 ]"); } } string methodName = "No method available"; if (node.CodeLocation.Method == null) { if (node.InCodeBranch.Method != null) { methodName = node.InCodeBranch.Method.FullName; } } else { methodName = node.CodeLocation.Method.FullName; } var pathCondition = PrettyPrintPathCondition(node); infoWriter.WriteLine("<Bold>" + pathCondition.Replace('\"', '.').Replace("<", ";lt;").Replace(">", ";gt;").Replace("&", "&") + "</Bold>" + "<LineBreak />" + methodName.Replace("<", ";lt;").Replace(">", ";gt;").Replace("&", "&") + "<LineBreak />" + ((tuple == null) ? "No source mapping available" : (tuple.Item2 + ":" + tuple.Item1)) ); infoWriter.WriteLine("</TextBlock>"); infoWriter.WriteLine("</Tip>"); storage.Nodes.Add(new Tuple <int, int>(node.UniqueIndex, node.Depth)); storage.NodeLocations.Add(node.UniqueIndex, methodName + ":" + node.CodeLocation.Offset); } } } runStorage.NodesInPath.Add(numberOfRuns, nodeIndexes); } catch (Exception e) { // TODO : Exception handling ? } }
protected override void AfterRun(IPexPathComponent host, object data) { Term[] pathConditions = new Term[] {}; IList<Term> conditions = null; IList<CodeLocation> locations = null; SafeSet<Method> trackingMethods = null; var database = host.GetService<IssueTrackDatabase>(); var unInstrumentedMethods = database.UnInstrumentedMethods; log = database.SimpleLog; foreach (var unInstrumentedMethod in unInstrumentedMethods) { var controller = new ResultTracer(host, unInstrumentedMethod.Method,log); log.AppendLine("try tracking " + unInstrumentedMethod.Method.FullName); log.AppendLine("*****************************************************"); using (IEngine trackingEngine = host.PathServices.TrackingEngineFactory.CreateTrackingEngine(controller)) { trackingEngine.GetService<IPexTrackingDriver>().Run(); pathConditions = Enumerable.ToArray(controller.PathConditions); conditions = controller.Conditions; locations = controller.Locations; trackingMethods = controller.TrackingMethods; } PexLog(host, "ResultTracing", prettyPrintPathCondition(host, pathConditions)); // log.AppendLine("condition: " + prettyPrintPathCondition(host, pathConditions)); PexLog(host, "tracking methods", trackingMethods.Select(x => x.FullName)); for (int i = 0; i < conditions.Count; i++) { var condition = conditions[i]; using (var extractor = new ResultTrackConditionExtractor(host.ExplorationServices.TermManager)) { extractor.VisitTerm(default(TVoid), condition); if (extractor.Method == null) { host.Log.Dump("method", "not in branch", "null"); continue; } PexLog(host, "method", extractor.Method.FullName); PexLog(host, "offset", extractor.CallerOffset.ToString("x")); PexLog(host, "location", extractor.Location.ToString()); var method = extractor.Signature as Method; PexLog(host, "signature", method.FullName); log.AppendLine("found method: " + method.FullName + " in branch " + locations[i]); if (!host.GetService<IssueTrackDatabase>().UninstrumentedMethodInBranch.ContainsKey(locations[i])) { host.GetService<IssueTrackDatabase>().UninstrumentedMethodInBranch.Add(locations[i], method); } } } PexLog(host, "location", locations.Select(x => x.ToString())); log.AppendLine("*****************************************************"); } log.AppendLine("========================="); }
public object BeforeRun(IPexPathComponent host) { MessageBox.Show("BeforeRun"); return(null); }