brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · daf375c Raw
133 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/DebugInfo/PDB/PDB.h"10 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"19 20#include "llvm/Testing/Support/Error.h"21#include "llvm/Testing/Support/SupportHelpers.h"22 23#include "gtest/gtest.h"24 25using namespace llvm;26using namespace llvm::pdb;27 28extern const char *TestMainArgv0;29 30TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {31  SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);32  llvm::sys::path::append(InputsDir, "empty.pdb");33 34  std::unique_ptr<IPDBSession> S;35  Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);36 37  ASSERT_THAT_ERROR(std::move(E), Succeeded());38 39  SymIndexId GlobalId;40  {41    auto GS1 = S->getGlobalScope();42    auto GS2 = S->getGlobalScope();43 44    GlobalId = GS1->getSymIndexId();45    SymIndexId Id2 = GS1->getSymIndexId();46    EXPECT_EQ(GlobalId, Id2);47  }48 49  {50    auto GS3 = S->getGlobalScope();51 52    SymIndexId Id3 = GS3->getSymIndexId();53    EXPECT_EQ(GlobalId, Id3);54  }55}56 57TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {58  SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);59  llvm::sys::path::append(InputsDir, "empty.pdb");60 61  std::unique_ptr<IPDBSession> S;62  Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);63 64  ASSERT_THAT_ERROR(std::move(E), Succeeded());65 66  auto GS = S->getGlobalScope();67 68  std::vector<SymIndexId> CompilandIds;69  {70    auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();71    ASSERT_NE(nullptr, Compilands);72    ASSERT_EQ(2U, Compilands->getChildCount());73    std::vector<SymIndexId> Ids2;74 75    // First try resetting the enumerator, then try destroying the enumerator76    // 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());82 83    EXPECT_EQ(CompilandIds, Ids2);84  }85 86  {87    auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();88    ASSERT_NE(nullptr, Compilands);89    ASSERT_EQ(2U, Compilands->getChildCount());90 91    std::vector<SymIndexId> Ids3;92    while (auto Compiland = Compilands->getNext())93      Ids3.push_back(Compiland->getSymIndexId());94 95    EXPECT_EQ(CompilandIds, Ids3);96  }97}98 99TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {100  SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);101  llvm::sys::path::append(InputsDir, "empty.pdb");102 103  std::unique_ptr<IPDBSession> S;104  Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);105 106  ASSERT_THAT_ERROR(std::move(E), Succeeded());107 108  auto GS = S->getGlobalScope();109 110  // This time do the first iteration backwards, and make sure that when you111  // then iterate them forwards, the IDs come out in reverse.112  std::vector<SymIndexId> CompilandIds;113  {114    auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();115    ASSERT_NE(nullptr, Compilands);116    ASSERT_EQ(2U, Compilands->getChildCount());117 118    std::vector<SymIndexId> Ids2;119 120    for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {121      auto Compiland = Compilands->getChildAtIndex(I);122      CompilandIds.push_back(Compiland->getSymIndexId());123    }124 125    while (auto Compiland = Compilands->getNext())126      Ids2.push_back(Compiland->getSymIndexId());127 128    auto ReversedIter = llvm::reverse(Ids2);129    std::vector<SymIndexId> Reversed{ReversedIter.begin(), ReversedIter.end()};130    EXPECT_EQ(CompilandIds, Reversed);131  }132}133