Skip to content

Commit

Permalink
[unittests] Split DWARF tests out of PDB, fix standalone build
Browse files Browse the repository at this point in the history
Split the PDB tests into DWARF test and actual PDB tests, the latter
requiring DIA SDK. Use the new LLVMConfig.cmake LLVM_ENABLE_DIA_SDK
symbol to enable the PDB tests rather than relying on
llvm/Config/config.h private include file that is not available when
building standalone.

Differential Revision: https://reviews.llvm.org/D26249

llvm-svn: 290819
  • Loading branch information
mgorny committed Jan 2, 2017
1 parent 89b6f16 commit 95e2629
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 47 deletions.
5 changes: 4 additions & 1 deletion lldb/unittests/SymbolFile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
add_subdirectory(PDB)
add_subdirectory(DWARF)
if (LLVM_ENABLE_DIA_SDK)
add_subdirectory(PDB)
endif()
8 changes: 8 additions & 0 deletions lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_lldb_unittest(SymbolFileDWARFTests
SymbolFileDWARFTests.cpp
)

set(test_inputs
test-dwarf.exe)

add_unittest_inputs(SymbolFileDWARFTests "${test_inputs}")
83 changes: 83 additions & 0 deletions lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//===-- PythonDataObjectsTests.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

#include "lldb/Core/Address.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"

#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"

extern const char *TestMainArgv0;

using namespace lldb_private;

class SymbolFileDWARFTests : public testing::Test {
public:
void SetUp() override {
// Initialize and TearDown the plugin every time, so we get a brand new
// AST every time so that modifications to the AST from each test don't
// leak into the next test.
HostInfo::Initialize();
ObjectFilePECOFF::Initialize();
SymbolFileDWARF::Initialize();
ClangASTContext::Initialize();
SymbolFilePDB::Initialize();

llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
llvm::SmallString<128> inputs_folder = exe_folder;
llvm::sys::path::append(inputs_folder, "Inputs");

m_dwarf_test_exe = inputs_folder;
llvm::sys::path::append(m_dwarf_test_exe, "test-dwarf.exe");
}

void TearDown() override {
SymbolFilePDB::Terminate();
ClangASTContext::Initialize();
SymbolFileDWARF::Terminate();
ObjectFilePECOFF::Terminate();
HostInfo::Terminate();
}

protected:
llvm::SmallString<128> m_dwarf_test_exe;
};

TEST_F(SymbolFileDWARFTests, TestAbilitiesForDWARF) {
// Test that when we have Dwarf debug info, SymbolFileDWARF is used.
FileSpec fspec(m_dwarf_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

SymbolVendor *plugin = module->GetSymbolVendor();
EXPECT_NE(nullptr, plugin);
SymbolFile *symfile = plugin->GetSymbolFile();
EXPECT_NE(nullptr, symfile);
EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());

uint32_t expected_abilities = SymbolFile::kAllAbilities;
EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
}
3 changes: 1 addition & 2 deletions lldb/unittests/SymbolFile/PDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ add_lldb_unittest(SymbolFilePDBTests
set(test_inputs
test-pdb.exe
test-pdb.pdb
test-dwarf.exe
test-pdb-types.exe
test-pdb-types.pdb)

add_unittest_inputs(SymbolFilePDBTests "${test_inputs}")
add_unittest_inputs(SymbolFilePDBTests "${test_inputs}")
61 changes: 17 additions & 44 deletions lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "gtest/gtest.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/Config/config.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -63,10 +62,8 @@ class SymbolFilePDBTests : public testing::Test {
llvm::sys::path::append(inputs_folder, "Inputs");

m_pdb_test_exe = inputs_folder;
m_dwarf_test_exe = inputs_folder;
m_types_test_exe = inputs_folder;
llvm::sys::path::append(m_pdb_test_exe, "test-pdb.exe");
llvm::sys::path::append(m_dwarf_test_exe, "test-dwarf.exe");
llvm::sys::path::append(m_types_test_exe, "test-pdb-types.exe");
}

Expand All @@ -84,7 +81,6 @@ class SymbolFilePDBTests : public testing::Test {

protected:
llvm::SmallString<128> m_pdb_test_exe;
llvm::SmallString<128> m_dwarf_test_exe;
llvm::SmallString<128> m_types_test_exe;

bool FileSpecMatchesAsBaseOrFull(const FileSpec &left,
Expand Down Expand Up @@ -154,29 +150,7 @@ class SymbolFilePDBTests : public testing::Test {
}
};

#if HAVE_DIA_SDK
#define REQUIRES_DIA_SDK(TestName) TestName
#else
#define REQUIRES_DIA_SDK(TestName) DISABLED_##TestName
#endif

TEST_F(SymbolFilePDBTests, TestAbilitiesForDWARF) {
// Test that when we have Dwarf debug info, SymbolFileDWARF is used.
FileSpec fspec(m_dwarf_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);

SymbolVendor *plugin = module->GetSymbolVendor();
EXPECT_NE(nullptr, plugin);
SymbolFile *symfile = plugin->GetSymbolFile();
EXPECT_NE(nullptr, symfile);
EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());

uint32_t expected_abilities = SymbolFile::kAllAbilities;
EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestAbilitiesForPDB)) {
TEST_F(SymbolFilePDBTests, TestAbilitiesForPDB) {
// Test that when we have PDB debug info, SymbolFilePDB is used.
FileSpec fspec(m_pdb_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
Expand All @@ -193,7 +167,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestAbilitiesForPDB)) {
EXPECT_EQ(expected_abilities, symfile->CalculateAbilities());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextBasename)) {
TEST_F(SymbolFilePDBTests, TestResolveSymbolContextBasename) {
// Test that attempting to call ResolveSymbolContext with only a basename
// finds all full paths
// with the same basename
Expand All @@ -213,7 +187,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextBasename)) {
EXPECT_TRUE(ContainsCompileUnit(sc_list, header_spec));
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextFullPath)) {
TEST_F(SymbolFilePDBTests, TestResolveSymbolContextFullPath) {
// Test that attempting to call ResolveSymbolContext with a full path only
// finds the one source
// file that matches the full path.
Expand All @@ -236,7 +210,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestResolveSymbolContextFullPath)) {
}

TEST_F(SymbolFilePDBTests,
REQUIRES_DIA_SDK(TestLookupOfHeaderFileWithInlines)) {
TestLookupOfHeaderFileWithInlines) {
// Test that when looking up a header file via ResolveSymbolContext (i.e. a
// file that was not by itself
// compiled, but only contributes to the combined code of other source files),
Expand Down Expand Up @@ -264,8 +238,7 @@ TEST_F(SymbolFilePDBTests,
}
}

TEST_F(SymbolFilePDBTests,
REQUIRES_DIA_SDK(TestLookupOfHeaderFileWithNoInlines)) {
TEST_F(SymbolFilePDBTests, TestLookupOfHeaderFileWithNoInlines) {
// Test that when looking up a header file via ResolveSymbolContext (i.e. a
// file that was not by itself
// compiled, but only contributes to the combined code of other source files),
Expand All @@ -289,7 +262,7 @@ TEST_F(SymbolFilePDBTests,
}
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchAll)) {
TEST_F(SymbolFilePDBTests, TestLineTablesMatchAll) {
// Test that when calling ResolveSymbolContext with a line number of 0, all
// line entries from
// the specified files are returned.
Expand Down Expand Up @@ -338,7 +311,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchAll)) {
VerifyLineEntry(module, sc, header2, *lt, 7, 0x401089);
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchSpecific)) {
TEST_F(SymbolFilePDBTests, TestLineTablesMatchSpecific) {
// Test that when calling ResolveSymbolContext with a specific line number,
// only line entries
// which match the requested line are returned.
Expand Down Expand Up @@ -390,7 +363,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestLineTablesMatchSpecific)) {
VerifyLineEntry(module, sc, header1, *lt, 9, 0x401090);
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestSimpleClassTypes)) {
TEST_F(SymbolFilePDBTests, TestSimpleClassTypes) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand All @@ -413,7 +386,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestSimpleClassTypes)) {
udt_type->GetByteSize());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestNestedClassTypes)) {
TEST_F(SymbolFilePDBTests, TestNestedClassTypes) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand All @@ -436,7 +409,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestNestedClassTypes)) {
udt_type->GetByteSize());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestClassInNamespace)) {
TEST_F(SymbolFilePDBTests, TestClassInNamespace) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand All @@ -459,7 +432,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestClassInNamespace)) {
udt_type->GetByteSize());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestEnumTypes)) {
TEST_F(SymbolFilePDBTests, TestEnumTypes) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand Down Expand Up @@ -492,21 +465,21 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestEnumTypes)) {
}
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestArrayTypes)) {
TEST_F(SymbolFilePDBTests, TestArrayTypes) {
// In order to get this test working, we need to support lookup by symbol
// name. Because array
// types themselves do not have names, only the symbols have names (i.e. the
// name of the array).
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestFunctionTypes)) {
TEST_F(SymbolFilePDBTests, TestFunctionTypes) {
// In order to get this test working, we need to support lookup by symbol
// name. Because array
// types themselves do not have names, only the symbols have names (i.e. the
// name of the array).
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestTypedefs)) {
TEST_F(SymbolFilePDBTests, TestTypedefs) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand Down Expand Up @@ -540,7 +513,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestTypedefs)) {
}
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestRegexNameMatch)) {
TEST_F(SymbolFilePDBTests, TestRegexNameMatch) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand All @@ -557,7 +530,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestRegexNameMatch)) {
EXPECT_EQ(num_results, results.GetSize());
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestMaxMatches)) {
TEST_F(SymbolFilePDBTests, TestMaxMatches) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand All @@ -584,7 +557,7 @@ TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestMaxMatches)) {
}
}

TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestNullName)) {
TEST_F(SymbolFilePDBTests, TestNullName) {
FileSpec fspec(m_types_test_exe.c_str(), false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Expand Down

0 comments on commit 95e2629

Please sign in to comment.