コード例 #1
0
        /// <summary>
        /// Converts the given trace file to a dictionary containing all covered lines of each source file for which
        /// coverage could be resolved with the PDB files in the given symbol directory.
        ///
        /// Public for testing.
        /// </summary>
        public static Dictionary <string, FileCoverage> ConvertToLineCoverage(ParsedTraceFile traceFile, SymbolCollection symbolCollection,
                                                                              string symbolDirectory, GlobPatternList assemblyPatterns)
        {
            logger.Debug("Converting trace {traceFile} to line coverage", traceFile);
            Dictionary <string, AssemblyResolutionCount> resolutionCounts = new Dictionary <string, AssemblyResolutionCount>();
            Dictionary <string, FileCoverage>            lineCoverage     = new Dictionary <string, FileCoverage>();

            foreach ((string assemblyName, uint methodId) in traceFile.CoveredMethods)
            {
                if (!assemblyPatterns.Matches(assemblyName))
                {
                    continue;
                }

                SymbolCollection.SourceLocation sourceLocation = symbolCollection.Resolve(assemblyName, methodId);
                if (!resolutionCounts.TryGetValue(assemblyName, out AssemblyResolutionCount count))
                {
                    count = new AssemblyResolutionCount();
                    resolutionCounts[assemblyName] = count;
                }

                if (sourceLocation == null)
                {
                    count.unresolvedMethods += 1;
                    logger.Debug("Could not resolve method ID {methodId} from assembly {assemblyName} in trace file {traceFile}" +
                                 " with symbols from {symbolDirectory} with {assemblyPatterns}", methodId, assemblyName,
                                 traceFile.FilePath, symbolDirectory, assemblyPatterns.Describe());
                    continue;
                }
                else if (string.IsNullOrEmpty(sourceLocation.SourceFile))
                {
                    count.methodsWithoutSourceFile += 1;
                    logger.Debug("Could not resolve source file of method ID {methodId} from assembly {assemblyName} in trace file {traceFile}" +
                                 " with symbols from {symbolDirectory} with {assemblyPatterns}", methodId, assemblyName,
                                 traceFile.FilePath, symbolDirectory, assemblyPatterns.Describe());
                    continue;
                }
                else if (sourceLocation.StartLine == PdbFile.CompilerHiddenLine || sourceLocation.EndLine == PdbFile.CompilerHiddenLine)
                {
                    count.methodsWithCompilerHiddenLines += 1;
                    logger.Debug("Resolved lines of method ID {methodId} from assembly {assemblyName} contain compiler hidden lines in trace file {traceFile}" +
                                 " with symbols from {symbolDirectory} with {assemblyPatterns}", methodId, assemblyName,
                                 traceFile.FilePath, symbolDirectory, assemblyPatterns.Describe());
                    continue;
                }

                count.resolvedMethods += 1;
                AddToLineCoverage(lineCoverage, sourceLocation);
            }

            LogResolutionFailures(traceFile, symbolDirectory, assemblyPatterns, resolutionCounts);

            return(lineCoverage);
        }
コード例 #2
0
        public void OneInvalidPdbShouldNotPreventParsingOthers()
        {
            SymbolCollection collection = SymbolCollection.CreateFromFiles(new[] { $"{TestUtils.TestDataDirectory}\\Invalid.pdb", TestPdbPath });

            SymbolCollection.SourceLocation existingMethod = collection.Resolve("ProfilerGUI", ExistingMethodToken);
            Assert.That(existingMethod, Is.Not.Null);
            Assert.Multiple(() =>
            {
                Assert.That(existingMethod.SourceFile, Contains.Substring("Configurator\\MainViewModel.cs"));
                Assert.That(existingMethod.StartLine, Is.EqualTo(37));
                Assert.That(existingMethod.EndLine, Is.EqualTo(39));
            });
        }
コード例 #3
0
        public void DuplicatePdbsShouldNotThrowExceptions()
        {
            SymbolCollection collection = SymbolCollection.CreateFromFiles(new[] { TestPdbPath, TestPDBCopyPath });

            SymbolCollection.SourceLocation existingMethod = collection.Resolve("ProfilerGUI", ExistingMethodToken);
            Assert.That(existingMethod, Is.Not.Null);
            Assert.Multiple(() =>
            {
                Assert.That(existingMethod.SourceFile, Contains.Substring("Configurator\\MainViewModel.cs"));
                Assert.That(existingMethod.StartLine, Is.EqualTo(37));
                Assert.That(existingMethod.EndLine, Is.EqualTo(39));
            });
        }
コード例 #4
0
        public void TestPdbParsing()
        {
            SymbolCollection collection = SymbolCollection.CreateFromFiles(new[] { TestPdbPath });

            SymbolCollection.SourceLocation existingMethod = collection.Resolve("ProfilerGUI", ExistingMethodToken);
            Assert.Multiple(() =>
            {
                Assert.That(existingMethod, Is.Not.Null);
                Assert.That(collection.Resolve("does-not-exist", 123), Is.Null);
            });

            Assert.Multiple(() =>
            {
                Assert.That(existingMethod.SourceFile, Contains.Substring("Configurator\\MainViewModel.cs"));
                Assert.That(existingMethod.StartLine, Is.EqualTo(37));
                Assert.That(existingMethod.EndLine, Is.EqualTo(39));
            });
        }
コード例 #5
0
        private static void AddToLineCoverage(Dictionary <string, FileCoverage> lineCoverage, SymbolCollection.SourceLocation sourceLocation)
        {
            if (!lineCoverage.TryGetValue(sourceLocation.SourceFile, out FileCoverage fileCoverage))
            {
                fileCoverage = new FileCoverage();
                lineCoverage[sourceLocation.SourceFile] = fileCoverage;
            }

            fileCoverage.CoveredLineRanges.Add((sourceLocation.StartLine, sourceLocation.EndLine));
        }