/// <summary> /// Pretty prints the path condition of the execution node. /// </summary> /// <param name="host">Host of the Pex Path Component</param> /// <param name="node">The execution node to map</param> /// <returns>The pretty printed path condition string</returns> private Task <string> PrettyPrintPathCondition(TermEmitter emitter, IMethodBodyWriter mbw, SafeStringWriter ssw, IExecutionNode node) { MessageBox.Show("PrettyPrintPathCondition()"); var task = Task.Factory.StartNew(() => { string output = ""; try { if (node.GetPathCondition().Conjuncts.Count != 0) { if (emitter.TryEvaluate(node.GetPathCondition().Conjuncts, 2000, mbw)) // TODO Perf leak { for (int i = 0; i < node.GetPathCondition().Conjuncts.Count - 1; i++) { mbw.ShortCircuitAnd(); } mbw.Statement(); var safeString = ssw.ToString(); output = safeString.Remove(ssw.Length - 3); } } } catch (Exception) { } return(output); }); return(task); }
/// <summary> /// Pretty prints the path condition of the given execution node. /// </summary> /// <param name="node"></param> /// <returns></returns> private string PrettyPrintPathCondition(IExecutionNode node) { string output = ""; try { if (node.GetPathCondition().Conjuncts.Count != 0) { TermEmitter termEmitter = new TermEmitter(pathComponent.GetService <TermManager>()); SafeStringWriter safeStringWriter = new SafeStringWriter(); IMethodBodyWriter methodBodyWriter = pathComponent.GetService <IPexTestManager>().Language.CreateBodyWriter(safeStringWriter, VisibilityContext.Private, 2000); if (termEmitter.TryEvaluate(node.GetPathCondition().Conjuncts, 2000, methodBodyWriter)) { for (int i = 0; i < node.GetPathCondition().Conjuncts.Count - 1; i++) { methodBodyWriter.ShortCircuitAnd(); } methodBodyWriter.Statement(); output = safeStringWriter.ToString().Remove(safeStringWriter.ToString().Count() - 3); } } } catch (Exception e) { // TODO : Exception handling? } return(output); }
private void LogNode(IExecutionNode rootNode, StringBuilder log, IPexExplorationComponent host) { var visualExecutionNode = rootNode as IVisualExecutionNode; IIndexable <PexPathExecutionResult> indexable = visualExecutionNode.AttachedPathExecutionResults; if (rootNode.CodeLocation != null && rootNode.CodeLocation.Method != null) { AppendLine("node CodeLocation: " + rootNode.CodeLocation.Method.FullName + ":" + rootNode.CodeLocation.Offset); } else { AppendLine("node CodeLocation: " + rootNode.CodeLocation); } if (rootNode.InCodeBranch != null && rootNode.InCodeBranch.Method != null) { CodeLocation location = rootNode.InCodeBranch.Method.GetBranchLabelSource(rootNode.InCodeBranch.BranchLabel); AppendLine("node InCodeBranch: " + location.Method.FullName + ":" + location.Offset.ToString("x") + " out: " + rootNode.InCodeBranch.BranchLabel); AppendLine("node InCodeBranch: " + rootNode.InCodeBranch); } else { AppendLine("node InCodeBranch: " + rootNode.InCodeBranch); } AppendLine("node Pathcondition: "); foreach (var term in rootNode.GetPathCondition().Conjuncts) { AppendLine(prettyPrintPathCondition(host, new[] { term })); } AppendLine("node OutCodeBranches: "); foreach (CodeBranch branch in rootNode.OutCodeBranches) { if (branch != null && branch.Method != null) { CodeLocation location = branch.Method.GetBranchLabelSource(branch.BranchLabel); AppendLine("node OutCodeBranch: " + location.Method.FullName + ":" + location.Offset.ToString("x") + " out: " + branch.BranchLabel); } else { AppendLine("node OutCodeBranch: " + branch); } } foreach (PexPathExecutionResult result in indexable) { AppendLine("node result: " + result.Kind); } AppendLine("node Pathcondition: " + rootNode.ModelHints); AppendLine(); }
private void LogNode(IExecutionNode rootNode, StringBuilder log, IPexExplorationComponent host) { var visualExecutionNode = rootNode as IVisualExecutionNode; IIndexable<PexPathExecutionResult> indexable = visualExecutionNode.AttachedPathExecutionResults; if (rootNode.CodeLocation != null && rootNode.CodeLocation.Method != null) { AppendLine("node CodeLocation: " + rootNode.CodeLocation.Method.FullName + ":" + rootNode.CodeLocation.Offset); } else { AppendLine("node CodeLocation: " + rootNode.CodeLocation); } if (rootNode.InCodeBranch != null && rootNode.InCodeBranch.Method != null) { CodeLocation location = rootNode.InCodeBranch.Method.GetBranchLabelSource(rootNode.InCodeBranch.BranchLabel); AppendLine("node InCodeBranch: " + location.Method.FullName + ":" + location.Offset.ToString("x") + " out: " + rootNode.InCodeBranch.BranchLabel); AppendLine("node InCodeBranch: " + rootNode.InCodeBranch); } else { AppendLine("node InCodeBranch: " + rootNode.InCodeBranch); } AppendLine("node Pathcondition: "); foreach (var term in rootNode.GetPathCondition().Conjuncts) { AppendLine(prettyPrintPathCondition(host, new[]{term})); } AppendLine("node OutCodeBranches: "); foreach (CodeBranch branch in rootNode.OutCodeBranches) { if (branch != null && branch.Method != null) { CodeLocation location = branch.Method.GetBranchLabelSource(branch.BranchLabel); AppendLine("node OutCodeBranch: " + location.Method.FullName + ":" + location.Offset.ToString("x") + " out: " + branch.BranchLabel); } else { AppendLine("node OutCodeBranch: " + branch); } } foreach (PexPathExecutionResult result in indexable) { AppendLine("node result: " + result.Kind); } AppendLine("node Pathcondition: " + rootNode.ModelHints); AppendLine(); }