-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPdbLibraryTests.cs
More file actions
117 lines (105 loc) · 4.42 KB
/
Copy pathPdbLibraryTests.cs
File metadata and controls
117 lines (105 loc) · 4.42 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.IO;
using NUnit.Framework;
using PdbLibrary;
namespace UnitTestPdbLibrary
{
[TestFixture]
public class PdbLibraryTests
{
// Fixtures are copied next to the test binary (see the csproj), so resolve
// them from the test directory rather than a Windows-relative "..\..\" path.
static string TestData(string name) =>
Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", name);
[Test]
public void TestPdbFileInvalidPath()
{
Assert.Throws<ArgumentException>(() => new PDBFile(new FileInfo(TestData("does-not-exist.pdb"))));
}
[Test]
public void TestPeFileInvalidPath()
{
Assert.Throws<ArgumentException>(() => new PEFile(new FileInfo(TestData("does-not-exist.dll"))));
}
[Test]
public void TestPDBFileGuid()
{
PDBFile pdbFile = new PDBFile(new FileInfo(TestData("myConsoleCrasher.pdb")));
string guid = pdbFile.GUID.Value();
Assert.That(guid, Is.EqualTo("0C0E0F8243B54897952E4DB3E538A2361"));
}
[Test]
public void TestPortablePdbGuid()
{
// A Portable PDB (BSJB) — the format a .NET Core / modern SDK app's own
// assembly PDB ships in. Its {GUID}{age} key must equal the one a dump's
// CodeView record names, so the backend indexes it into the symsrv store
// under the same key bugsplat-cdb later looks it up by. This fixture's key
// is the directory it lives under in bugsplat-cdb's data/symbols-core store.
PDBFile pdbFile = new PDBFile(new FileInfo(TestData("MyDotNetCrasher.pdb")));
string guid = pdbFile.GUID.Value();
Assert.That(guid, Is.EqualTo("0023F679780F4F5D8DE2F203E88AB6721"));
}
[Test]
public void TestPEFileGuid()
{
PEFile peFile = new PEFile(new FileInfo(TestData("myConsoleCrasher.exe")));
string guid = peFile.Guid();
Assert.That(guid, Is.EqualTo("56BDDA687000"));
}
[Test]
public void TestPEFileGuid2()
{
PEFile peFile = new PEFile(new FileInfo(TestData("libgcc_s_sjlj-1.dll")));
string guid = peFile.Guid();
Assert.That(guid, Is.EqualTo("000200001E000"));
}
[Test, Explicit]
public void TestSymbolStore()
{
// Checks all GUIDs in a given symbol store.
string dir = @"z:\SymbolServers";
CheckGuidsInStore(dir, Path.Combine(dir, "pbdtests.log"));
Assert.Pass();
}
void CheckGuidsInStore(string dir, string fp)
{
try
{
foreach (string d in Directory.GetDirectories(dir))
{
foreach (string f in Directory.GetFiles(d))
{
File.AppendAllText(fp, String.Format("file: {0}", f));
string extension = Path.GetExtension(f);
string directory = Path.GetFileName(Path.GetDirectoryName(f)).ToUpperInvariant();
switch (extension)
{
case ".pdb":
PDBFile pdbFile = new PDBFile(new FileInfo(f));
string pdbGuid = pdbFile.GUID.Value();
File.AppendAllText(fp, String.Format(" {0} {1}\n", pdbGuid, directory));
Assert.That(pdbGuid, Is.EqualTo(directory));
break;
case ".exe":
case ".dll":
PEFile peFile = new PEFile(new FileInfo(f));
string peGuid = peFile.Guid();
File.AppendAllText(fp, String.Format("{0} {1}\n", peGuid, directory));
Assert.That(peGuid, Is.EqualTo(directory));
break;
default:
File.AppendAllText(fp, "\n");
break;
}
}
CheckGuidsInStore(d, fp);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
}
}