Esempio n. 1
0
        public void IncludesSymbolFilesFromSubDirectories()
        {
            var testSubSymbolDirectory = $"{TestSymbolDirectory}\\Sub";

            Directory.CreateDirectory(testSubSymbolDirectory);
            File.Move(TestSymbolFilePath, $"{testSubSymbolDirectory}\\Some.pdb");

            SymbolCollection collection = resolver.ResolveFrom(TestSymbolDirectory, includeAllAssembliesPattern);

            Assert.That(collection.IsEmpty, Is.False);
        }
Esempio n. 2
0
        public void ConsidersSymbolFileExcludes()
        {
            SymbolCollection collection = resolver.ResolveFrom(TestSymbolDirectory,
                                                               new GlobPatternList(new List <string> {
                "*"
            }, new List <string> {
                "So*"
            }));

            Assert.That(collection.IsEmpty, Is.True);
        }
Esempio n. 3
0
        public void CachesCollectionAgainAfterInvalidation()
        {
            SymbolCollection collection1 = resolver.ResolveFrom(TestSymbolDirectory, includeAllAssembliesPattern);

            SimulateSymbolFileChange(collection1.SymbolFilePaths.First());

            SymbolCollection collection2 = resolver.ResolveFrom(TestSymbolDirectory, includeAllAssembliesPattern);
            SymbolCollection collection3 = resolver.ResolveFrom(TestSymbolDirectory, includeAllAssembliesPattern);

            Assert.That(collection2, Is.SameAs(collection3));
        }
        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));
            });
        }
        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));
            });
        }
        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));
            });
        }
        /// <inheritdoc/>
        public Dictionary <string, FileCoverage> ConvertToLineCoverage(ParsedTraceFile traceFile, string symbolDirectory, GlobPatternList assemblyPatterns)
        {
            SymbolCollection symbolCollection = symbolCollectionResolver.ResolveFrom(symbolDirectory, assemblyPatterns);

            if (symbolCollection.IsEmpty)
            {
                throw new LineCoverageConversionFailedException($"Failed to convert {traceFile.FilePath} to line coverage." +
                                                                $" Found no symbols in {symbolDirectory} matching {assemblyPatterns.Describe()}");
            }

            Dictionary <string, FileCoverage> lineCoverage = ConvertToLineCoverage(traceFile, symbolCollection, symbolDirectory, assemblyPatterns);

            if (lineCoverage.Count == 0 || lineCoverage.Values.All(fileCoverage => fileCoverage.CoveredLineRanges.Count() == 0))
            {
                return(null);
            }

            return(lineCoverage);
        }
        public void CompilerHiddenLinesShouldBeIgnored()
        {
            ParsedTraceFile traceFile = new ParsedTraceFile(new string[] {
                "Assembly=Test:2 Version:1.0.0.0",
                "Inlined=2:1234",
            }, "coverage_12345_1234.txt");

            AssemblyMethodMappings mappings = new AssemblyMethodMappings
            {
                AssemblyName   = "Test",
                SymbolFileName = "Test.pdb",
            };

            mappings.MethodMappings.Add(new MethodMapping
            {
                MethodToken = 1234,
                SourceFile  = "",
                StartLine   = 16707566,
                EndLine     = 16707566,
            });
            mappings.MethodMappings.Add(new MethodMapping
            {
                MethodToken = 1234,
                SourceFile  = @"c:\some\file.cs",
                StartLine   = 16707566,
                EndLine     = 16707566,
            });

            SymbolCollection symbolCollection = new SymbolCollection(new List <AssemblyMethodMappings>()
            {
                mappings
            });

            Dictionary <string, FileCoverage> coverage = LineCoverageSynthesizer.ConvertToLineCoverage(traceFile, symbolCollection, TestUtils.TestDataDirectory,
                                                                                                       new GlobPatternList(new List <string> {
                "*"
            }, new List <string> {
            }));

            Assert.That(coverage, Is.Empty);
        }
        /// <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);
        }
        public void CollectsSymbolFilePaths()
        {
            SymbolCollection collection = SymbolCollection.CreateFromFiles(new[] { TestPdbPath });

            Assert.That(collection.SymbolFilePaths, Is.EqualTo(new[] { TestPdbPath }));
        }