Пример #1
0
        /// <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);
        }
 /// <summary>
 /// Gets called when an un-explored branch is encountered during program execution
 /// </summary>
 /// <param name="executionNode"></param>
 /// <param name="explorableType"></param>
 public void LogExplorableInsufficiency(IExecutionNode executionNode, TypeEx explorableType)
 {
     var termManager = this.ExplorationServices.TermManager;
     var condition = executionNode.SuccessorLabelToExplore;
     this.GatherDebuggingInfoFromInsufficiency(executionNode, termManager, condition, explorableType);
     this.tba.HandleTargetBranch(executionNode.CodeLocation, condition, termManager, explorableType);
 }
Пример #3
0
        /// <summary>
        /// Creates GraphViz rank=same statements for nodes, which have same heights.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="storage"></param>
        /// <returns></returns>
        private string CreateSameRankStatement(IExecutionNode node, PexExecutionNodeStorageComponent storage)
        {
            StringBuilder b = new StringBuilder();

            try
            {
                b.Append("{rank=same; " + node.UniqueIndex);

                foreach (var knownNode in storage.Nodes)
                {
                    if (knownNode != node)
                    {
                        if (knownNode.Item2 == node.Depth)
                        {
                            b.Append(" " + knownNode.Item1);
                        }
                    }
                }

                b.AppendLine(" }");
            }
            catch (Exception e)
            {
                // TODO : Exception handling?
            }
            return(b.ToString());
        }
Пример #4
0
        /// <summary>
        /// Gets called when an un-explored branch is encountered during program execution
        /// </summary>
        /// <param name="executionNode"></param>
        /// <param name="explorableType"></param>
        public void LogExplorableInsufficiency(IExecutionNode executionNode, TypeEx explorableType)
        {
            var termManager = this.ExplorationServices.TermManager;
            var condition   = executionNode.SuccessorLabelToExplore;

            this.GatherDebuggingInfoFromInsufficiency(executionNode, termManager, condition, explorableType);
            this.tba.HandleTargetBranch(executionNode.CodeLocation, condition, termManager, explorableType);
        }
Пример #5
0
        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();
        }
Пример #6
0
        private void LogRootNode(IPexExplorationComponent host, StringBuilder log, IExecutionNode rootNode)
        {
            AppendLine("node: ");
            LogNode(rootNode, log, host);
//                host.GetService<IssueTrackDatabase>().
            IFiniteMap <Term, IExecutionNode> successors = rootNode.Successors;

            AppendLine("Successors: ");
            foreach (SafeKeyValuePair <Term, IExecutionNode> keyValuePair in successors)
            {
                AppendLine("term: " + prettyPrintPathCondition(host, new[] { keyValuePair.Key }));
                LogRootNode(host, log, keyValuePair.Value);
            }
        }
Пример #7
0
        /// <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);
            }
        }
Пример #8
0
        public virtual IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex)
        {
            this.next = next;

            return(next);
        }
Пример #9
0
        public virtual IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex)
        {
            this.next = next;

            return next;
        }
Пример #10
0
        public IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex = 0)
        {
            nextNodes[outletIndex] = next;

            return next;
        }
Пример #11
0
        private void GatherDebuggingInfoFromInsufficiency(IExecutionNode executionNode, TermManager termManager,
                                                          Term condition, TypeEx explorableType)
        {
            var sb = new SafeStringBuilder();

            sb.AppendLine("condition:");
            sb.AppendLine();
            this.tba.ConvertTermToText(new SafeStringWriter(sb), condition, this.ExplorationServices.TermManager);
            sb.AppendLine();
            var swriter = new TermSExpWriter(termManager, new SafeStringWriter(sb), true, false);

            swriter.Write(condition);
            sb.AppendLine();
            sb.AppendLine("location:");
            sb.AppendLine();
            sb.AppendLine(executionNode.CodeLocation.ToString());
            sb.AppendLine();
            sb.AppendLine("properties:");

            Term unnegatedCondition;

            if (termManager.TryGetInnerLogicallyNegatedValue(condition, out unnegatedCondition))
            {
                sb.AppendLine("negated");
            }
            else
            {
                unnegatedCondition = condition;
            }

            var            targetFieldValues = new SafeDictionary <Field, object>();
            Term           left, right;
            BinaryOperator binOp;

            if (termManager.TryGetBinary(unnegatedCondition, out binOp, out left, out right))
            {
                sb.AppendFormat("binary relation: {0}", binOp);
                sb.AppendLine();

                if (!termManager.IsValue(left) && !termManager.IsValue(right))
                {
                    sb.AppendLine("No constant on either left side or right side.");
                    return;
                }

                Term non_constant_term = null;
                Term constant_term     = null;
                if (termManager.IsValue(left))
                {
                    non_constant_term = right;
                    constant_term     = left;
                }
                else if (termManager.IsValue(right))
                {
                    non_constant_term = left;
                    constant_term     = right;
                }

                sb.AppendLine("against constant");
                if (constant_term == null || termManager.IsDefaultValue(constant_term))
                {
                    sb.AppendLine("against default value ('null' for references)");
                }

                int value;
                if (constant_term != null && termManager.TryGetI4Constant(constant_term, out value))
                {
                    sb.AppendLine("against integer: " + value);
                }

                Term           objectValue;
                ObjectProperty objectProperty;
                if (constant_term != null && termManager.TryGetObjectProperty(constant_term, out objectValue, out objectProperty))
                {
                    sb.AppendLine("against object property: object=" + objectValue + ", property=" + objectProperty);
                }

                sb.AppendLine(" involving fields: ");
                SafeDictionary <Field, FieldValueHolder> innerFieldValues;
                SafeList <TypeEx> innerFieldTypes;
                SafeList <Field>  fs = TargetBranchAnalyzer.GetInvolvedFields(this, termManager,
                                                                              non_constant_term, out innerFieldValues, out innerFieldTypes);
                foreach (var f in fs)
                {
                    sb.AppendLine(f.FullName);
                }
            }

            sb.AppendLine("Executed method call sequence");
            if (this.pmd.LastExecutedFactoryMethodCallSequence != null)
            {
                foreach (var m in this.pmd.LastExecutedFactoryMethodCallSequence)
                {
                    sb.AppendLine("\t" + m);
                }
            }

            this.Log.Dump("foo", "insufficiency for " + (explorableType != null ? explorableType.FullName : "?"), sb.ToString());
            return;
        }
        private void GatherDebuggingInfoFromInsufficiency(IExecutionNode executionNode, TermManager termManager, 
            Term condition, TypeEx explorableType)
        {
            var sb = new SafeStringBuilder();
            sb.AppendLine("condition:");
            sb.AppendLine();
            this.tba.ConvertTermToText(new SafeStringWriter(sb), condition, this.ExplorationServices.TermManager);
            sb.AppendLine();
            var swriter = new TermSExpWriter(termManager, new SafeStringWriter(sb), true, false);
            swriter.Write(condition);
            sb.AppendLine();
            sb.AppendLine("location:");
            sb.AppendLine();
            sb.AppendLine(executionNode.CodeLocation.ToString());
            sb.AppendLine();
            sb.AppendLine("properties:");

            Term unnegatedCondition;
            if (termManager.TryGetInnerLogicallyNegatedValue(condition, out unnegatedCondition))
                sb.AppendLine("negated");
            else
                unnegatedCondition = condition;

            var targetFieldValues = new SafeDictionary<Field, object>();
            Term left, right;
            BinaryOperator binOp;
            if (termManager.TryGetBinary(unnegatedCondition, out binOp, out left, out right))
            {
                sb.AppendFormat("binary relation: {0}", binOp);
                sb.AppendLine();

                if (!termManager.IsValue(left) && !termManager.IsValue(right))
                {
                    sb.AppendLine("No constant on either left side or right side.");
                    return;
                }

                Term non_constant_term = null;
                Term constant_term = null;
                if (termManager.IsValue(left))
                {
                    non_constant_term = right;
                    constant_term = left;
                }
                else if (termManager.IsValue(right))
                {
                    non_constant_term = left;
                    constant_term = right;
                }

                sb.AppendLine("against constant");
                if (constant_term == null || termManager.IsDefaultValue(constant_term))
                {
                    sb.AppendLine("against default value ('null' for references)");
                }

                int value;
                if (constant_term != null && termManager.TryGetI4Constant(constant_term, out value))
                {
                    sb.AppendLine("against integer: " + value);
                }

                Term objectValue;
                ObjectProperty objectProperty;
                if (constant_term != null && termManager.TryGetObjectProperty(constant_term, out objectValue, out objectProperty))
                {
                    sb.AppendLine("against object property: object=" + objectValue + ", property=" + objectProperty);
                }

                sb.AppendLine(" involving fields: ");
                SafeDictionary<Field, FieldValueHolder> innerFieldValues;
                SafeList<TypeEx> innerFieldTypes;
                SafeList<Field> fs = TargetBranchAnalyzer.GetInvolvedFields(this, termManager,
                    non_constant_term, out innerFieldValues, out innerFieldTypes);
                foreach (var f in fs)
                {
                    sb.AppendLine(f.FullName);
                }
            }

            sb.AppendLine("Executed method call sequence");
            if(this.pmd.LastExecutedFactoryMethodCallSequence != null)
                foreach (var m in this.pmd.LastExecutedFactoryMethodCallSequence)
                {
                    sb.AppendLine("\t" + m);
                }

            this.Log.Dump("foo", "insufficiency for " + (explorableType != null ? explorableType.FullName : "?"), sb.ToString());
            return;
        }
Пример #13
0
        /// <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("&", "&amp;") + "</Bold>"
                                                 + "<LineBreak />" + methodName.Replace("<", ";lt;").Replace(">", ";gt;").Replace("&", "&amp;")
                                                 + "<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 ?
            }
        }
        public void LogExplorableInsufficiency(IExecutionNode executionNode, TypeEx explorableType)
        {
            var termManager    = this.ExplorationServices.TermManager;
            var accessedFields = new SafeSet <Field>();

            var condition        = executionNode.SuccessorLabelToExplore;
            SafeStringBuilder sb = new SafeStringBuilder();

            sb.AppendLine("condition:");
            sb.AppendLine();
            dumpHelper(new SafeStringWriter(sb), condition);
            sb.AppendLine();
            var swriter = new TermSExpWriter(termManager, new SafeStringWriter(sb), true, false);

            swriter.Write(condition);
            sb.AppendLine();
            sb.AppendLine("location:");
            sb.AppendLine();
            sb.AppendLine(executionNode.CodeLocation.ToString());
            sb.AppendLine();
            sb.AppendLine("properties:");
            Term unnegatedCondition;

            if (termManager.TryGetInnerLogicallyNegatedValue(condition, out unnegatedCondition))
            {
                sb.AppendLine("negated");
            }
            else
            {
                unnegatedCondition = condition;
            }
            Term           left, right;
            BinaryOperator binOp;

            if (termManager.TryGetBinary(unnegatedCondition, out binOp, out left, out right))
            {
                sb.AppendFormat("binary relation: {0}", binOp);
                sb.AppendLine();
                // binOp==BinaryOperator.Ceq  tests for equality
                bool isLeftValue = termManager.IsValue(left);

                if (termManager.IsValue(left) || termManager.IsValue(right))
                {
                    sb.AppendLine("against constant");
                    if (termManager.IsDefaultValue(left) || termManager.IsDefaultValue(right))
                    {
                        sb.AppendLine("against default value ('null' for references)");
                    }
                    int value;
                    if (termManager.TryGetI4Constant(left, out value) || termManager.TryGetI4Constant(right, out value))
                    {
                        sb.AppendLine("against integer: " + value);
                    }
                    Term           objectValue;
                    ObjectProperty objectProperty;
                    if (termManager.TryGetObjectProperty(left, out objectValue, out objectProperty) ||
                        termManager.TryGetObjectProperty(right, out objectValue, out objectProperty))
                    {
                        sb.AppendLine("against object property: object=" + objectValue + ", property=" + objectProperty);
                    }
                    //the following determins what fields are involved on the other side of the constraint
                    Term t;
                    if (isLeftValue)
                    {
                        t = right;
                    }
                    else
                    {
                        t = left;
                    }
                    sb.AppendLine(" involving fields: ");
                    SafeSet <Field> fs = this.GetInvolvedFields(termManager, t);
                    foreach (var f in fs)
                    {
                        sb.AppendLine("f.FullName:" + f.FullName);
                        sb.AppendLine("f.Definition.FullName" + f.Definition.FullName);
                        sb.AppendLine("f.InstanceFieldMapType:" + f.InstanceFieldMapType.FullName);
                        TypeEx type;
//                        type.
                        f.TryGetDeclaringType(out type);
                        sb.AppendLine("f.TryGetDeclaringType: " + type.FullName);
                    }
                }
            }

            sb.AppendLine();
            sb.AppendLine("fields:");
            sb.AppendLine();

            SafeSet <Field> fields = this.GetInvolvedFields(termManager, condition);

            foreach (var f in fields)
            {
                sb.AppendLine(f.FullName);
                accessedFields.Add(f);
            }

            this.Log.Dump("foo", "insufficiency for " + (explorableType != null ? explorableType.FullName : "?"),
                          sb.ToString());
            StringBuilder simpleLog = this.GetService <ProblemTrackDatabase>().SimpleLog;

            simpleLog.AppendLine("insufficiency for " + (explorableType != null ? explorableType.FullName : "?") + sb);
            //this.unsuccessfullyFlippedCodeLocations.Add(executionNode.CodeLocation);

            SafeSet <Field> existingAssessedFields;

            if (
                !this.database.FieldsForUnsuccessfullyFlippedCodeLocations.TryGetValue(executionNode.CodeLocation,
                                                                                       out existingAssessedFields))
            {
                database.FieldsForUnsuccessfullyFlippedCodeLocations.Add(executionNode.CodeLocation, accessedFields);
            }
            else
            {
                existingAssessedFields.AddRange(accessedFields);
            }

            SafeStringBuilder sbTerm = new SafeStringBuilder();

            dumpHelper(new SafeStringWriter(sbTerm), condition);

            SafeSet <string> terms;

            if (
                !this.database.TermsForUnsuccessfullyFlippedCodeLocations.TryGetValue(
                    executionNode.CodeLocation.ToString(), out terms))
            {
                terms = new SafeSet <string>();
                terms.Add(sbTerm.ToString());
                database.TermsForUnsuccessfullyFlippedCodeLocations.Add(executionNode.CodeLocation.ToString(), terms);
            }
            else
            {
                terms.Add(sbTerm.ToString());
            }
        }
Пример #15
0
        public IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex = 0)
        {
            nextNodes[outletIndex] = next;

            return(next);
        }
        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();
        }
Пример #17
0
 public IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex)
 {
     return null;
 }
 private void LogRootNode(IPexExplorationComponent host, StringBuilder log, IExecutionNode rootNode)
 {
     AppendLine("node: ");
     LogNode(rootNode, log,host);
     //                host.GetService<IssueTrackDatabase>().
     IFiniteMap<Term, IExecutionNode> successors = rootNode.Successors;
     AppendLine("Successors: ");
     foreach (SafeKeyValuePair<Term, IExecutionNode> keyValuePair in successors)
     {
         AppendLine("term: " + prettyPrintPathCondition(host, new[] {keyValuePair.Key}));
         LogRootNode(host, log, keyValuePair.Value);
     }
 }
Пример #19
0
        /// <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);
        }
Пример #20
0
 public IExecutionNode ConnectExecution(IExecutionNode next, int outletIndex)
 {
     return(null);
 }