Ejemplo n.º 1
0
 public PexMePostProcessor(IPexComponent host)
     : base(host)
 {
     this.host = host;
     this.pmd = host.GetService<IPexMeDynamicDatabase>() as PexMeDynamicDatabase;
     this.psd = host.GetService<IPexMeStaticDatabase>() as PexMeStaticDatabase;
     this.pdw = new PexMeDumpWriter(host);
     this.currAssembly = this.pmd.Services.CurrentAssembly.Assembly.Assembly;
     var nestingdepth = System.Environment.GetEnvironmentVariable("PEXME_NESTED_DEPTH");
     if (nestingdepth != null)
         ndepth = Convert.ToInt32(nestingdepth, 10);
 }
        protected override void Initialize()
        {
            base.Initialize();
            this.pmd = this.GetService<IPexMeDynamicDatabase>() as PexMeDynamicDatabase;
            this.psd = this.GetService<IPexMeStaticDatabase>() as PexMeStaticDatabase;
            this.tba = new TargetBranchAnalyzer(this.pmd, this.Services, this);
            this.ExplorationServices.ExplorableManager.AddExplorableInsufficienyObserver(this);

            this.Log.LogMessage("hint provider", "Registered the hint provider");
            this.thp = new TypeHintProvider(this.pmd, this.psd);
            this.ExplorationServices.DomainManager.AddTypeHintProvider(thp);
        }
 public FieldAccessCollector(IFieldAccessPathObserver pathObserver, 
     IFieldAccessExplorationObserver explorationObserver,
     IPexMeDynamicDatabase pmd, PexMeStaticDatabase psd,
     int level)
 {
     this.pathObserver = pathObserver;
     this.explorationObserver = explorationObserver;
     this.pmd = pmd as PexMeDynamicDatabase;
     this.psd = psd;
     this.trackedFrameId = -1;
     this.level = level;
     this.depth = -1;
 }
Ejemplo n.º 4
0
        public DUCoverEngine()
            : base(new Container(new TypeEx[] { Microsoft.ExtendedReflection.Metadata.Metadata<IEngineOptions>.Type }), new IComponent[] { })
        {
            EngineOptions options = new EngineOptions();
            this.AddComponent("options", options);
            this.AddComponents();

            var pmd = new PexMeDynamicDatabase();
            pmd.AssemblyName = System.Environment.GetEnvironmentVariable(DUCoverConstants.DUCoverAssemblyVar);
            this.AddComponent("pmd", pmd);

            var psd = new PexMeStaticDatabase();
            psd.AssemblyName = System.Environment.GetEnvironmentVariable(DUCoverConstants.DUCoverAssemblyVar);
            this.AddComponent("psd", psd);
        }
        public void Analyze()
        {
            //this.Log.LogMessage(PexMeLogCategories.MethodBegin, "Begin of FieldAccessPathObserver.Analyze() method");

            if(this.explorationObserver == null)
                this.explorationObserver = this.GetService<IFieldAccessExplorationObserver>();

            if (this.pmd == null)
                this.pmd = this.GetService<IPexMeDynamicDatabase>() as PexMeDynamicDatabase;

            if (this.psd == null)
                this.psd = this.GetService<IPexMeStaticDatabase>() as PexMeStaticDatabase;

            int framesCount = 0;
            int framesHandled = 0;
            int maxLevelCount = 16; //TODO: Why 16?

            pmd.LastExecutedFactoryMethodCallSequence = null;

            for (int level = 0; level < maxLevelCount; level++)
            {
                FieldAccessCollector controller = new FieldAccessCollector(this,
                    this.explorationObserver, this.pmd, this.psd, level);

                this.pmd.DefectDetectingSequence = false;
                try
                {
                    using (IEngine trackingEngine = this.PathServices.TrackingEngineFactory.CreateTrackingEngine(controller))
                    {
                        IPexTrackingDriver driver = trackingEngine.GetService<IPexTrackingDriver>();
                        if (!driver.Run())
                            break;
                    }
                }
                catch (Exception ex)
                {
                    this.pmd.DefectDetectingSequence = true;
                }

                pmd.LastExecutedFactoryMethodCallSequence = controller.FactoryMethodCallSequence;
                pmd.LastExecutedCUTMethodCallSequence = controller.CUTMethodCallSequence;

                //StringBuilder sb = new StringBuilder();
                //foreach(Method m in pmd.LastExecutedMethodCallSequence)
                //{
                //    sb.Append(m.ToString() + "\n");
                //}
                //this.pmd.Log.LogMessage("debug", "Executed method call sequence " + sb.ToString());

                framesCount = SafeMath.Max(framesCount, controller.FramesCount);
                framesHandled += controller.FramesHandled;
                if (framesHandled > framesCount) framesHandled = framesCount;
                //this.Log.LogMessage(
                //    "FieldAccessObserver",
                //    "collecting data, {0:P} of all frames up to level {1} / {2}",
                //    ((double)framesHandled / framesCount), level, maxLevelCount);
                if (controller.FramesHandled == 0 || // did we make any progress?
                    framesHandled >= framesCount) // or have we processed all frames there are?
                    break;
            }

            //Gather the information of last visited term here to use it later in
            //InsufficientObjectFactoryObserver.LogExplorableInsufficiency

            //this.Log.LogMessage(PexMeLogCategories.MethodEnd, "End of FieldAccessPathObserver.Analyze() method");
        }
Ejemplo n.º 6
0
 public TypeHintProvider(PexMeDynamicDatabase pmd, PexMeStaticDatabase psd)
 {
     this.pmd = pmd;
     this.psd = psd;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// If type is an interface, returns all concrete implementing classes
        /// else if type is an abstract class, returns all concrete extending classes
        /// </summary>
        /// <param name="psd"></param>
        /// <param name="type"></param>
        /// <param name="extendingClasses"></param>
        /// <returns></returns>
        public static bool TryGetExtendingClasses(PexMeStaticDatabase psd, TypeEx type, out IIndexable<TypeDefinition> extendingClasses)
        {
            //load inheritance hierarchies if not already done
            psd.LoadInheritanceHierarchies();
            extendingClasses = null;

            TypeStore ts;
            if (!psd.TypeDictionary.TryGetValue(type.Definition, out ts))
                return false;

            SafeSet<TypeDefinition> extendingClassesSet = new SafeSet<TypeDefinition>();
            CollectAllExtendingClasses(ts, extendingClassesSet);

            if (extendingClassesSet.Count == 0)
                return false;

            var extendingClassesList = new SafeList<TypeDefinition>();
            foreach (var tdef in extendingClassesSet)
            {
                extendingClassesList.Add(tdef);
            }

            extendingClasses = extendingClassesList;
            return true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Dumps static database
        /// </summary>
        public void DumpStaticDatabase(PexMeStaticDatabase psd)
        {
            SafeDebug.AssumeNotNull(psd, "psd");

            if (!Directory.Exists(PexMeConstants.PexMeStorageDirectory))
                Directory.CreateDirectory(PexMeConstants.PexMeStorageDirectory);

            //Dump the dynamic field store that includes information of which method modify which fields
            try
            {
                var filename = Path.Combine(PexMeConstants.PexMeStorageDirectory, PexMeConstants.PexMeStaticFieldStore);
                Stream streamWrite = File.Create(filename);
                BinaryFormatter binaryWrite = new BinaryFormatter();
                var persistentFieldDic = this.GetPersistentFieldDictionary(psd.FieldDictionary);
                binaryWrite.Serialize(streamWrite, persistentFieldDic);
                streamWrite.Close();
            }
            catch (Exception ex)
            {
                psd.Log.LogErrorFromException(ex, WikiTopics.MissingWikiTopic, "dumpwriter",
                    "Failed to dump field store of static database");
            }

            //Dump the dynamic method store that includes information of which method calls other methods and field they modify
            try
            {
                var filename = Path.Combine(PexMeConstants.PexMeStorageDirectory, PexMeConstants.PexMeStaticMethodStore);
                Stream streamWrite = File.Create(filename);
                BinaryFormatter binaryWrite = new BinaryFormatter();
                var persistentMethodDic = this.GetPersistentMethodDictionary(psd.MethodDictionary);
                binaryWrite.Serialize(streamWrite, persistentMethodDic);
                streamWrite.Close();
            }
            catch (Exception ex)
            {
                psd.Log.LogErrorFromException(ex, WikiTopics.MissingWikiTopic, "dumpwriter",
                    "Failed to dump method store of static database");
            }

            /******************** DEBUGGING INFO *************************/
            //Writing method information
            var methodDic = psd.MethodDictionary;

            var methodAccessFileName = Path.Combine(PexMeConstants.PexMeStorageDirectory, psd.AssemblyName + ".static.methodAccess.txt");
            using (StreamWriter sw = new StreamWriter(methodAccessFileName))
            {
                foreach (var methodEntry in methodDic.Values)
                {
                    //Printing write fields
                    sw.WriteLine("Methodname: " + methodEntry.methodName);

                    if (methodEntry.WriteFields.Count > 0)
                    {
                        sw.WriteLine("Write fields: ");
                        foreach (var writeField in methodEntry.WriteFields)
                            sw.WriteLine("\tField: " + writeField);
                    }

                    if (methodEntry.CalledMethods.Count > 0)
                    {
                        sw.WriteLine("Called Methods: ");
                        foreach (var calledMethod in methodEntry.CalledMethods)
                            sw.WriteLine("\t" + calledMethod);
                    }

                    if (methodEntry.CallingMethods.Count > 0)
                    {
                        sw.WriteLine("Calling Methods: ");
                        foreach (var callingMethod in methodEntry.CallingMethods)
                            sw.WriteLine("\t" + callingMethod);
                    }

                    //TODO: Print read fields
                }
            }

            //Writing field information
            var fieldDic = psd.FieldDictionary;

            var fieldAccessFileName = Path.Combine(PexMeConstants.PexMeStorageDirectory, psd.AssemblyName + ".static.fieldAccess.txt");
            using (StreamWriter sw = new StreamWriter(fieldAccessFileName))
            {
                foreach (var fieldEntry in fieldDic.Values)
                {
                    //Printing write methods
                    sw.WriteLine("Fieldname: " + fieldEntry.FieldName);
                    sw.WriteLine("Write methods: ");
                    foreach (var writeMethodSet in fieldEntry.WriteMethods.Values)
                    {
                        foreach (var writeMethod in writeMethodSet)
                            sw.WriteLine("\tMethod: " + writeMethod + ", ModificationType: " + FieldStore.GetModificationType(fieldEntry, writeMethod));
                    }

                    sw.WriteLine("Field values: ");
                    foreach (var fieldValue in fieldEntry.FieldValues)
                    {
                        sw.WriteLine("\tValue: " + fieldValue);
                    }

                    //TODO: Print read methods
                }
            }
            /******************** DEBUGGING INFO *************************/
        }