예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        void Log_ProblemHandler(Microsoft.ExtendedReflection.Logging.ProblemEventArgs e)
        {
            //TODO: Xusheng's code for additional OCI issues
            if (e.Result == TryGetModelResult.Success)
            {
                return;
            }

            CodeLocation location = e.FlippedLocation;
            var          term     = e.Suffix;

            SafeDictionary <Field, FieldValueHolder> fieldValues;
            SafeList <TypeEx> allFieldTypes;
            SafeList <Field>  fields = TargetBranchAnalyzer.GetInvolvedFields(this.host, e.TermManager, term, out fieldValues, out allFieldTypes);

            //Not an object creation issue
            if (fields == null || fields.Count == 0)
            {
                return;
            }
            this.host.Log.LogMessage("ProblemHandler", "Recorded an issue at code location " + location.ToString());
            if (!PexMeConstants.USE_TERM_SOLVER)
            {
                //A heuristic to choose the explorable type
                this.tba.HandleTargetBranch(location, term, e.TermManager, allFieldTypes[0]);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets invoked before execution
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        protected override object BeforeExecution(IPexComponent host)
        {
            this.host = host;
            //register all explorables
            foreach (IPexExplorableGuesser guesser in this.CreateExplorableGuessers(host))
            {
                host.Services.ExplorableGuesserManager.AddExplorableGuesser(guesser);
            }

            this.host.Log.ExplorableHandler += Log_ExplorableHandler;
            this.host.Log.ProblemHandler    += Log_ProblemHandler;
            this.pmd = host.GetService <IPexMeDynamicDatabase>() as PexMeDynamicDatabase;

            //TargetBranch Handler cannot be instantiated with ExplorationServices from here if TERM_SOLVER
            //functionality is required
            if (!PexMeConstants.USE_TERM_SOLVER)
            {
                this.tba = new TargetBranchAnalyzer(this.pmd, this.host.Services, null);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Helps guess factory methods for each uncovered condition
        /// </summary>
        private void GuessFactorymethods(out SafeSet <Method> allNewSuggestedPUTs, string currPUTSignature, out bool bHasSomeCoveredLocation,
                                         out bool bAllAreNewLocations, out bool bNoneAreNewLocations)
        {
            PexMeFactoryGuesser pfg = new PexMeFactoryGuesser(this.host);

            HashSet <string> allGivenUpLocations, allCoveredLocations, newUnCoveredLocations;

            //Analyze the current uncovered and previously uncovered locations
            this.pmd.AnalyzePreviousAndCurrentUncoveredLoc(currPUTSignature, out allGivenUpLocations,
                                                           out allCoveredLocations, out newUnCoveredLocations, out bHasSomeCoveredLocation, out bAllAreNewLocations, out bNoneAreNewLocations);

            allNewSuggestedPUTs = new SafeSet <Method>();
            //Iterate through each uncovered location
            foreach (var ucovLocList in pmd.UncoveredLocationDictionary.Values)
            {
                //TODO: Classify the uncovered locations into different groups
                //Because, it can happen that a single code location can have multiple terms which
                //cannot be merged together.
                if (ucovLocList.StoreList.Count == 0)
                {
                    continue;
                }

                //Check whether this location is earlier attempted and is failed. no
                //need to try this location again
                FactorySuggestionStore fss = null;
                string key = null;
                if (this.pmd.FactorySuggestionsDictionary.TryGetValue(ucovLocList.ExplorableType, out fss))
                {
                    key = UncoveredCodeLocationStore.GetKey(ucovLocList.Location.ToString(),
                                                            ucovLocList.ExplorableType, ucovLocList.TermIndex);

                    //A fix to keep track of uncovered locations in system libraries
                    if (TargetBranchAnalyzer.IsUncoveredLocationInSystemLib(ucovLocList.Location))
                    {
                        fss.UncoveredSystemLibLocations.Add(key);
                    }

                    if (allGivenUpLocations.Contains(key))
                    {
                        continue;
                    }
                    //Already covered locations can be reported again due to different PUTs or different call sites
                    //if (allCoveredLocations.Contains(key))
                    //    continue;
                    if (fss.PermanentFailedUncoveredLocations.Contains(key))
                    {
                        continue;
                    }
                    //if (fss.SuccessfulCoveredLocations.Contains(key))
                    //    continue;
                }

                //A single element of ucovLoc is sufficient here
                var ucovLoc = ucovLocList.StoreList[0];
                if (!pfg.TryInferFactoryMethod(ucovLoc, out ucovLoc.SuggestedMethodSetforFactory))
                {
                    this.host.Log.LogWarning(WikiTopics.MissingWikiTopic, "postprocessor",
                                             "Failed to suggest factory methods for uncovered location " + ucovLoc.ToString() + " -> Adding to permanent failed locations");

                    if (fss != null && key != null)
                    {
                        fss.PermanentFailedUncoveredLocations.Add(key);
                    }

                    continue;
                }

                //If a suggested method is not yet explored, add it to all new suggested method
                if (ucovLoc.SuggestedMethodSetforFactory != null)
                {
                    foreach (var suggestedm in ucovLoc.SuggestedMethodSetforFactory)
                    {
                        if (suggestedm.IsConstructor)
                        {
                            continue;
                        }

                        //Check if this is ever explored by this process by getting associated PUT
                        Method pexmethod;
                        bool   bretval = PUTGenerator.PUTGenerator.TryRetrievePUT(this.pmd, this.currAssembly, suggestedm, out pexmethod);
                        if (!bretval)
                        {
                            //The suggested method is out of scope of current library and
                            //no need to explore it explicitly
                            continue;
                        }

                        //Ignore self suggestions
                        if (pexmethod == this.pmd.CurrentPUTMethod)
                        {
                            continue;
                        }
                        var signature = MethodOrFieldAnalyzer.GetMethodSignature(pexmethod);
                        if (this.pmd.AllExploredMethods.Contains(signature))
                        {
                            continue;
                        }

                        if (this.pmd.PendingExplorationMethods.Contains(signature))
                        {
                            this.host.Log.LogWarning(WikiTopics.MissingWikiTopic,
                                                     "Nested PUTs", "Ignoring the nested PUT due to cycle detection " + signature);
                            continue;
                        }

                        allNewSuggestedPUTs.Add(pexmethod);
                    }
                }
            }
        }