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("=========================");
        }
Exemple #2
0
        private void DumpProblem()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var problemEventArgs in PexProblemEventArgsList)
            {
                CodeLocation location = problemEventArgs.FlippedLocation;
                Log.Dump("My Category", "flipped location: " + location, null);
                SequencePoint sp;
                Services.SymbolManager.TryGetSequencePoint(location.Method, location.Offset, out sp);
                sb.AppendLine("=======================================================");
                sb.AppendLine("result: " + problemEventArgs.Result);
                sb.AppendLine("flipped location: " + sp.Document + " line: " + sp.Line);
                var flippedCondition = problemEventArgs.Suffix;
//                sb.AppendLine("suffix term: " + ((ISymbolId)flippedCondition).Description);
                var location1 = problemEventArgs.ParentOfFlipped.CodeLocation;
                Services.SymbolManager.TryGetSequencePoint(location1.Method, location1.Offset, out sp);
                sb.AppendLine("ParentOfFlipped location: " + sp.Document + " line: " + sp.Line);

                var stringWriter = new StringWriter();
                var bodyWriter   = this.Services.LanguageManager.DefaultLanguage.CreateBodyWriter(stringWriter,
                                                                                                  VisibilityContext.
                                                                                                  Private);
                var extractor = new ResultTrackConditionExtractor(problemEventArgs.TermManager);
                extractor.VisitTerm(default(TVoid), flippedCondition);

                var emitter = new TermEmitter(problemEventArgs.TermManager, new NameCreator());
                if (emitter.TryEvaluate(Indexable.One(flippedCondition), 1000, bodyWriter))
                {
                    bodyWriter.Return(SystemTypes.Bool);
                }
                Log.Dump("My Category", "condition", stringWriter.ToString());
                sb.AppendLine(stringWriter.ToString());
            }

            DumpInfoToDebugFile(sb.ToString(), problemIssueFileName);
        }
        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 override int GetNextCallId(int threadId, int offset, IMethodSignature methodSignature, TypeEx[] varArgTypes, Term[] arguments)
            {
                DumpInfo(methodSignature, threadId, offset, varArgTypes);
                var termManager = host.ExplorationServices.TermManager;
                var method = methodSignature as Method;
                if (method != null)
                {
                    Dump("method name: " + method.FullName + " offset: " + offset);
                    if (!method.FullName.Equals(_trackMethod.FullName))
                    {
                        Dump("method: " + method.FullName + " is not tracking method " + _trackMethod);
                        Dump("end GetNextCallId=============================");
                        Dump("");
                        return 0;
                    }
                }

                if (method != null)
                {
                    Dump("method name: " + method.FullName);
                    if (method.FullName.Equals(_trackMethod.FullName))
                    {
                        bool foundSymbol = false;
                        if (arguments == null)
                        {
                            Dump("args is null");
                        }
                        else
                        {
                            string arg = "";
                            foreach (Term term in arguments)
                            {
                                arg += "arg: " + term + " is symbolic: " + termManager.IsSymbol(term);
                                var extractor = new ResultTrackConditionExtractor(termManager);
                                extractor.VisitTerm(default(TVoid), term);
                                arg += " symbol: " + extractor.Log;
                            }
                            Dump("args: " + arg);

                            foreach (Term argument in arguments)
                            {
                                if (termManager.IsSymbol(argument))
                                {
                                    foundSymbol = true;
                                    break;
                                }
                            }
                        }

                        track = foundSymbol;
                        if (track)
                        {
                            Dump("track " + method.FullName);
                            trackArg = true;
                            methodForTrackingArg = method;
                            Dump("track parameter of " + method.FullName);
                        }
                    }
                }
                else
                {
                    Dump(methodSignature + " signature is null.");
                }

                Dump("end GetNextCallId=============================");
                Dump("");
                return 0;
            }
            public override int GetNextCallId(int threadId, int offset, IMethodSignature methodSignature, TypeEx[] varArgTypes, Term[] arguments)
            {
                DumpInfo(methodSignature, threadId, offset, varArgTypes);
                var termManager = host.ExplorationServices.TermManager;
                var method      = methodSignature as Method;

                if (method != null)
                {
                    Dump("method name: " + method.FullName + " offset: " + offset);
                    if (!method.FullName.Equals(_trackMethod.FullName))
                    {
                        Dump("method: " + method.FullName + " is not tracking method " + _trackMethod);
                        Dump("end GetNextCallId=============================");
                        Dump("");
                        return(0);
                    }
                }


                if (method != null)
                {
                    Dump("method name: " + method.FullName);
                    if (method.FullName.Equals(_trackMethod.FullName))
                    {
                        bool foundSymbol = false;
                        if (arguments == null)
                        {
                            Dump("args is null");
                        }
                        else
                        {
                            string arg = "";
                            foreach (Term term in arguments)
                            {
                                arg += "arg: " + term + " is symbolic: " + termManager.IsSymbol(term);
                                var extractor = new ResultTrackConditionExtractor(termManager);
                                extractor.VisitTerm(default(TVoid), term);
                                arg += " symbol: " + extractor.Log;
                            }
                            Dump("args: " + arg);

                            foreach (Term argument in arguments)
                            {
                                if (termManager.IsSymbol(argument))
                                {
                                    foundSymbol = true;
                                    break;
                                }
                            }
                        }

                        track = foundSymbol;
                        if (track)
                        {
                            Dump("track " + method.FullName);
                            trackArg             = true;
                            methodForTrackingArg = method;
                            Dump("track parameter of " + method.FullName);
                        }
                    }
                }
                else
                {
                    Dump(methodSignature + " signature is null.");
                }

                Dump("end GetNextCallId=============================");
                Dump("");
                return(0);
            }
        private void DumpProblem()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var problemEventArgs in PexProblemEventArgsList)
            {
                CodeLocation location = problemEventArgs.FlippedLocation;
                Log.Dump("My Category", "flipped location: " + location, null);
                SequencePoint sp;
                Services.SymbolManager.TryGetSequencePoint(location.Method, location.Offset, out sp);
                sb.AppendLine("=======================================================");
                sb.AppendLine("result: " + problemEventArgs.Result);
                sb.AppendLine("flipped location: " + sp.Document + " line: " + sp.Line);
                var flippedCondition = problemEventArgs.Suffix;
            //                sb.AppendLine("suffix term: " + ((ISymbolId)flippedCondition).Description);
                var location1 = problemEventArgs.ParentOfFlipped.CodeLocation;
                Services.SymbolManager.TryGetSequencePoint(location1.Method, location1.Offset, out sp);
                sb.AppendLine("ParentOfFlipped location: " + sp.Document + " line: " + sp.Line);

                var stringWriter = new StringWriter();
                var bodyWriter = this.Services.LanguageManager.DefaultLanguage.CreateBodyWriter(stringWriter,
                                                                                                VisibilityContext.
                                                                                                    Private);
                var extractor = new ResultTrackConditionExtractor(problemEventArgs.TermManager);
                extractor.VisitTerm(default(TVoid), flippedCondition);

                var emitter = new TermEmitter(problemEventArgs.TermManager, new NameCreator());
                if (emitter.TryEvaluate(Indexable.One(flippedCondition), 1000, bodyWriter))
                {
                    bodyWriter.Return(SystemTypes.Bool);
                }
                Log.Dump("My Category", "condition", stringWriter.ToString());
                sb.AppendLine(stringWriter.ToString());
            }

            DumpInfoToDebugFile(sb.ToString(), problemIssueFileName);
        }