[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / DebugInfo / PDB / NativeSymbolReuseTest.cpp
blobdaf375c8e5cd17bece1fbc5f811b8e60a4b97ad5
1 //===- NativeSymbolReuseTest.cpp ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/PDB.h"
11 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
12 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
13 #include "llvm/DebugInfo/PDB/IPDBSession.h"
14 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
18 #include "llvm/Support/Path.h"
20 #include "llvm/Testing/Support/Error.h"
21 #include "llvm/Testing/Support/SupportHelpers.h"
23 #include "gtest/gtest.h"
25 using namespace llvm;
26 using namespace llvm::pdb;
28 extern const char *TestMainArgv0;
30 TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {
31 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
32 llvm::sys::path::append(InputsDir, "empty.pdb");
34 std::unique_ptr<IPDBSession> S;
35 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
37 ASSERT_THAT_ERROR(std::move(E), Succeeded());
39 SymIndexId GlobalId;
41 auto GS1 = S->getGlobalScope();
42 auto GS2 = S->getGlobalScope();
44 GlobalId = GS1->getSymIndexId();
45 SymIndexId Id2 = GS1->getSymIndexId();
46 EXPECT_EQ(GlobalId, Id2);
50 auto GS3 = S->getGlobalScope();
52 SymIndexId Id3 = GS3->getSymIndexId();
53 EXPECT_EQ(GlobalId, Id3);
57 TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {
58 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
59 llvm::sys::path::append(InputsDir, "empty.pdb");
61 std::unique_ptr<IPDBSession> S;
62 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
64 ASSERT_THAT_ERROR(std::move(E), Succeeded());
66 auto GS = S->getGlobalScope();
68 std::vector<SymIndexId> CompilandIds;
70 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
71 ASSERT_NE(nullptr, Compilands);
72 ASSERT_EQ(2U, Compilands->getChildCount());
73 std::vector<SymIndexId> Ids2;
75 // First try resetting the enumerator, then try destroying the enumerator
76 // and constructing another one.
77 while (auto Compiland = Compilands->getNext())
78 CompilandIds.push_back(Compiland->getSymIndexId());
79 Compilands->reset();
80 while (auto Compiland = Compilands->getNext())
81 Ids2.push_back(Compiland->getSymIndexId());
83 EXPECT_EQ(CompilandIds, Ids2);
87 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
88 ASSERT_NE(nullptr, Compilands);
89 ASSERT_EQ(2U, Compilands->getChildCount());
91 std::vector<SymIndexId> Ids3;
92 while (auto Compiland = Compilands->getNext())
93 Ids3.push_back(Compiland->getSymIndexId());
95 EXPECT_EQ(CompilandIds, Ids3);
99 TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {
100 SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
101 llvm::sys::path::append(InputsDir, "empty.pdb");
103 std::unique_ptr<IPDBSession> S;
104 Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
106 ASSERT_THAT_ERROR(std::move(E), Succeeded());
108 auto GS = S->getGlobalScope();
110 // This time do the first iteration backwards, and make sure that when you
111 // then iterate them forwards, the IDs come out in reverse.
112 std::vector<SymIndexId> CompilandIds;
114 auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
115 ASSERT_NE(nullptr, Compilands);
116 ASSERT_EQ(2U, Compilands->getChildCount());
118 std::vector<SymIndexId> Ids2;
120 for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {
121 auto Compiland = Compilands->getChildAtIndex(I);
122 CompilandIds.push_back(Compiland->getSymIndexId());
125 while (auto Compiland = Compilands->getNext())
126 Ids2.push_back(Compiland->getSymIndexId());
128 auto ReversedIter = llvm::reverse(Ids2);
129 std::vector<SymIndexId> Reversed{ReversedIter.begin(), ReversedIter.end()};
130 EXPECT_EQ(CompilandIds, Reversed);