[llvm-exegesis][NFC] Return many CodeTemplates instead of one.
[llvm-complete.git] / unittests / DebugInfo / PDB / NativeSymbolReuseTest.cpp
blob15afea6729295b9cd52bbae8e5c78d0168191ea6
1 //===- NativeSymbolReuseTest.cpp ------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/PDB.h"
12 #include "llvm/DebugInfo/PDB/IPDBSession.h"
13 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
16 #include "llvm/Support/Path.h"
18 #include "llvm/Testing/Support/Error.h"
19 #include "llvm/Testing/Support/SupportHelpers.h"
21 #include "gtest/gtest.h"
23 using namespace llvm;
24 using namespace llvm::pdb;
26 extern const char *TestMainArgv0;
28 TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {
29 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
30 llvm::sys::path::append(InputsDir, "empty.pdb");
32 std::unique_ptr<IPDBSession> S;
33 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
35 ASSERT_THAT_ERROR(std::move(E), Succeeded());
37 SymIndexId GlobalId;
39 auto GS1 = S->getGlobalScope();
40 auto GS2 = S->getGlobalScope();
42 GlobalId = GS1->getSymIndexId();
43 SymIndexId Id2 = GS1->getSymIndexId();
44 EXPECT_EQ(GlobalId, Id2);
48 auto GS3 = S->getGlobalScope();
50 SymIndexId Id3 = GS3->getSymIndexId();
51 EXPECT_EQ(GlobalId, Id3);
55 TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {
56 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
57 llvm::sys::path::append(InputsDir, "empty.pdb");
59 std::unique_ptr<IPDBSession> S;
60 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
62 ASSERT_THAT_ERROR(std::move(E), Succeeded());
64 auto GS = S->getGlobalScope();
66 std::vector<SymIndexId> CompilandIds;
68 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
69 ASSERT_NE(nullptr, Compilands);
70 ASSERT_EQ(2U, Compilands->getChildCount());
71 std::vector<SymIndexId> Ids2;
73 // First try resetting the enumerator, then try destroying the enumerator
74 // and constructing another one.
75 while (auto Compiland = Compilands->getNext())
76 CompilandIds.push_back(Compiland->getSymIndexId());
77 Compilands->reset();
78 while (auto Compiland = Compilands->getNext())
79 Ids2.push_back(Compiland->getSymIndexId());
81 EXPECT_EQ(CompilandIds, Ids2);
85 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
86 ASSERT_NE(nullptr, Compilands);
87 ASSERT_EQ(2U, Compilands->getChildCount());
89 std::vector<SymIndexId> Ids3;
90 while (auto Compiland = Compilands->getNext())
91 Ids3.push_back(Compiland->getSymIndexId());
93 EXPECT_EQ(CompilandIds, Ids3);
97 TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {
98 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
99 llvm::sys::path::append(InputsDir, "empty.pdb");
101 std::unique_ptr<IPDBSession> S;
102 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
104 ASSERT_THAT_ERROR(std::move(E), Succeeded());
106 auto GS = S->getGlobalScope();
108 // This time do the first iteration backwards, and make sure that when you
109 // then iterate them forwards, the IDs come out in reverse.
110 std::vector<SymIndexId> CompilandIds;
112 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
113 ASSERT_NE(nullptr, Compilands);
114 ASSERT_EQ(2U, Compilands->getChildCount());
116 std::vector<SymIndexId> Ids2;
118 for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {
119 auto Compiland = Compilands->getChildAtIndex(I);
120 CompilandIds.push_back(Compiland->getSymIndexId());
123 while (auto Compiland = Compilands->getNext())
124 Ids2.push_back(Compiland->getSymIndexId());
126 auto ReversedIter = llvm::reverse(Ids2);
127 std::vector<SymIndexId> Reversed{ReversedIter.begin(), ReversedIter.end()};
128 EXPECT_EQ(CompilandIds, Reversed);