-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathCoverageBenchmarks.cs
68 lines (57 loc) · 2.43 KB
/
CoverageBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using BenchmarkDotNet.Attributes;
using Coverlet.Core;
using Coverlet.Core.Abstractions;
using Coverlet.Core.Helpers;
using Coverlet.Core.Symbols;
using Moq;
namespace coverlet.core.benchmark.tests
{
[MemoryDiagnoser]
public class CoverageBenchmarks
{
private Coverage _coverage;
private readonly Mock<ILogger> _mockLogger = new();
private DirectoryInfo _directory;
[GlobalSetup(Target = nameof(GetCoverageBenchmark))]
public void GetCoverageBenchmarkSetup()
{
string module = GetType().Assembly.Location;
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
_directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
File.Copy(module, Path.Combine(_directory.FullName, Path.GetFileName(module)), true);
File.Copy(pdb, Path.Combine(_directory.FullName, Path.GetFileName(pdb)), true);
// TODO: Find a way to mimick hits
var instrumentationHelper =
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));
var parameters = new CoverageParameters
{
IncludeFilters = new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" },
IncludeDirectories = Array.Empty<string>(),
ExcludeFilters = Array.Empty<string>(),
ExcludedSourceFiles = Array.Empty<string>(),
ExcludeAttributes = Array.Empty<string>(),
IncludeTestAssembly = false,
SingleHit = false,
MergeWith = string.Empty,
UseSourceLink = false
};
_coverage = new Coverage(Path.Combine(_directory.FullName, Path.GetFileName(module)), parameters, _mockLogger.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(_mockLogger.Object, new FileSystem()), new CecilSymbolHelper());
_coverage.PrepareModules();
}
[GlobalCleanup]
public void IterationCleanup()
{
_directory.Delete(true);
}
[Benchmark]
public void GetCoverageBenchmark()
{
CoverageResult result = _coverage.GetCoverageResult();
}
}
}