diff options
Diffstat (limited to 'unittests/Target')
-rw-r--r-- | unittests/Target/CMakeLists.txt | 17 | ||||
-rw-r--r-- | unittests/Target/Inputs/TestModule.c | 9 | ||||
-rw-r--r-- | unittests/Target/Inputs/TestModule.so | bin | 5602 -> 0 bytes | |||
-rw-r--r-- | unittests/Target/MemoryRegionInfoTest.cpp | 20 | ||||
-rw-r--r-- | unittests/Target/ModuleCacheTest.cpp | 168 | ||||
-rw-r--r-- | unittests/Target/PathMappingListTest.cpp | 115 |
6 files changed, 0 insertions, 329 deletions
diff --git a/unittests/Target/CMakeLists.txt b/unittests/Target/CMakeLists.txt deleted file mode 100644 index bd73d708cb8b..000000000000 --- a/unittests/Target/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -add_lldb_unittest(TargetTests - MemoryRegionInfoTest.cpp - ModuleCacheTest.cpp - PathMappingListTest.cpp - - LINK_LIBS - lldbCore - lldbHost - lldbSymbol - lldbUtility - lldbPluginObjectFileELF - lldbUtilityHelpers - LINK_COMPONENTS - Support - ) - -add_unittest_inputs(TargetTests TestModule.so) diff --git a/unittests/Target/Inputs/TestModule.c b/unittests/Target/Inputs/TestModule.c deleted file mode 100644 index 6347f7264944..000000000000 --- a/unittests/Target/Inputs/TestModule.c +++ /dev/null @@ -1,9 +0,0 @@ -// Compile with $CC -nostdlib -shared TestModule.c -o TestModule.so -// The actual contents of the test module is not important here. I am using this -// because it -// produces an extremely tiny (but still perfectly valid) module. - -void boom(void) { - char *BOOM; - *BOOM = 47; -} diff --git a/unittests/Target/Inputs/TestModule.so b/unittests/Target/Inputs/TestModule.so Binary files differdeleted file mode 100644 index 9e9bf0b6e17e..000000000000 --- a/unittests/Target/Inputs/TestModule.so +++ /dev/null diff --git a/unittests/Target/MemoryRegionInfoTest.cpp b/unittests/Target/MemoryRegionInfoTest.cpp deleted file mode 100644 index 704f7f8c48c6..000000000000 --- a/unittests/Target/MemoryRegionInfoTest.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//===-- MemoryRegionInfoTest.cpp --------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "lldb/Target/MemoryRegionInfo.h" -#include "llvm/Support/FormatVariadic.h" -#include "gtest/gtest.h" - -using namespace lldb_private; - -TEST(MemoryRegionInfoTest, Formatv) { - EXPECT_EQ("yes", llvm::formatv("{0}", MemoryRegionInfo::eYes).str()); - EXPECT_EQ("no", llvm::formatv("{0}", MemoryRegionInfo::eNo).str()); - EXPECT_EQ("don't know", llvm::formatv("{0}", MemoryRegionInfo::eDontKnow).str()); -} diff --git a/unittests/Target/ModuleCacheTest.cpp b/unittests/Target/ModuleCacheTest.cpp deleted file mode 100644 index 9678bb078cef..000000000000 --- a/unittests/Target/ModuleCacheTest.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "gtest/gtest.h" - -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Path.h" - -#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" -#include "TestingSupport/TestUtilities.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/ModuleSpec.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" -#include "lldb/Symbol/SymbolContext.h" -#include "lldb/Target/ModuleCache.h" - -using namespace lldb_private; -using namespace lldb; - -namespace { - -class ModuleCacheTest : public testing::Test { -public: - static void SetUpTestCase(); - - static void TearDownTestCase(); - -protected: - static FileSpec s_cache_dir; - static std::string s_test_executable; - - void TryGetAndPut(const FileSpec &cache_dir, const char *hostname, - bool expect_download); -}; -} - -FileSpec ModuleCacheTest::s_cache_dir; -std::string ModuleCacheTest::s_test_executable; - -static const char dummy_hostname[] = "dummy_hostname"; -static const char dummy_remote_dir[] = "bin"; -static const char module_name[] = "TestModule.so"; -static const char module_uuid[] = - "F4E7E991-9B61-6AD4-0073-561AC3D9FA10-C043A476"; -static const uint32_t uuid_bytes = 20; -static const size_t module_size = 5602; - -static FileSpec GetDummyRemotePath() { - FileSpec fs("/", FileSpec::Style::posix); - fs.AppendPathComponent(dummy_remote_dir); - fs.AppendPathComponent(module_name); - return fs; -} - -static FileSpec GetUuidView(FileSpec spec) { - spec.AppendPathComponent(".cache"); - spec.AppendPathComponent(module_uuid); - spec.AppendPathComponent(module_name); - return spec; -} - -static FileSpec GetSysrootView(FileSpec spec, const char *hostname) { - spec.AppendPathComponent(hostname); - spec.AppendPathComponent(dummy_remote_dir); - spec.AppendPathComponent(module_name); - return spec; -} - -void ModuleCacheTest::SetUpTestCase() { - FileSystem::Initialize(); - HostInfo::Initialize(); - ObjectFileELF::Initialize(); - - s_cache_dir = HostInfo::GetProcessTempDir(); - s_test_executable = GetInputFilePath(module_name); -} - -void ModuleCacheTest::TearDownTestCase() { - ObjectFileELF::Terminate(); - HostInfo::Terminate(); - FileSystem::Terminate(); -} - -static void VerifyDiskState(const FileSpec &cache_dir, const char *hostname) { - FileSpec uuid_view = GetUuidView(cache_dir); - EXPECT_TRUE(FileSystem::Instance().Exists(uuid_view)) - << "uuid_view is: " << uuid_view.GetCString(); - EXPECT_EQ(module_size, FileSystem::Instance().GetByteSize(uuid_view)); - - FileSpec sysroot_view = GetSysrootView(cache_dir, hostname); - EXPECT_TRUE(FileSystem::Instance().Exists(sysroot_view)) - << "sysroot_view is: " << sysroot_view.GetCString(); - EXPECT_EQ(module_size, FileSystem::Instance().GetByteSize(sysroot_view)); -} - -void ModuleCacheTest::TryGetAndPut(const FileSpec &cache_dir, - const char *hostname, bool expect_download) { - ModuleCache mc; - ModuleSpec module_spec; - module_spec.GetFileSpec() = GetDummyRemotePath(); - module_spec.GetUUID().SetFromStringRef(module_uuid, uuid_bytes); - module_spec.SetObjectSize(module_size); - ModuleSP module_sp; - bool did_create; - bool download_called = false; - - Status error = mc.GetAndPut( - cache_dir, hostname, module_spec, - [&download_called](const ModuleSpec &module_spec, - const FileSpec &tmp_download_file_spec) { - download_called = true; - EXPECT_STREQ(GetDummyRemotePath().GetCString(), - module_spec.GetFileSpec().GetCString()); - std::error_code ec = llvm::sys::fs::copy_file( - s_test_executable, tmp_download_file_spec.GetCString()); - EXPECT_FALSE(ec); - return Status(); - }, - [](const ModuleSP &module_sp, const FileSpec &tmp_download_file_spec) { - return Status("Not supported."); - }, - module_sp, &did_create); - EXPECT_EQ(expect_download, download_called); - - EXPECT_TRUE(error.Success()) << "Error was: " << error.AsCString(); - EXPECT_TRUE(did_create); - ASSERT_TRUE(bool(module_sp)); - - SymbolContextList sc_list; - EXPECT_EQ(1u, module_sp->FindFunctionSymbols(ConstString("boom"), - eFunctionNameTypeFull, sc_list)); - EXPECT_STREQ(GetDummyRemotePath().GetCString(), - module_sp->GetPlatformFileSpec().GetCString()); - EXPECT_STREQ(module_uuid, module_sp->GetUUID().GetAsString().c_str()); -} - -TEST_F(ModuleCacheTest, GetAndPut) { - FileSpec test_cache_dir = s_cache_dir; - test_cache_dir.AppendPathComponent("GetAndPut"); - - const bool expect_download = true; - TryGetAndPut(test_cache_dir, dummy_hostname, expect_download); - VerifyDiskState(test_cache_dir, dummy_hostname); -} - -TEST_F(ModuleCacheTest, GetAndPutUuidExists) { - FileSpec test_cache_dir = s_cache_dir; - test_cache_dir.AppendPathComponent("GetAndPutUuidExists"); - - FileSpec uuid_view = GetUuidView(test_cache_dir); - std::error_code ec = - llvm::sys::fs::create_directories(uuid_view.GetDirectory().GetCString()); - ASSERT_FALSE(ec); - ec = llvm::sys::fs::copy_file(s_test_executable, uuid_view.GetCString()); - ASSERT_FALSE(ec); - - const bool expect_download = false; - TryGetAndPut(test_cache_dir, dummy_hostname, expect_download); - VerifyDiskState(test_cache_dir, dummy_hostname); -} - -TEST_F(ModuleCacheTest, GetAndPutStrangeHostname) { - FileSpec test_cache_dir = s_cache_dir; - test_cache_dir.AppendPathComponent("GetAndPutStrangeHostname"); - - const bool expect_download = true; - TryGetAndPut(test_cache_dir, "tab\tcolon:asterisk*", expect_download); - VerifyDiskState(test_cache_dir, "tab_colon_asterisk_"); -} diff --git a/unittests/Target/PathMappingListTest.cpp b/unittests/Target/PathMappingListTest.cpp deleted file mode 100644 index 42db27fdb504..000000000000 --- a/unittests/Target/PathMappingListTest.cpp +++ /dev/null @@ -1,115 +0,0 @@ -//===-- PathMappingListTest.cpp ---------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/ArrayRef.h" -#include "lldb/Target/PathMappingList.h" -#include "lldb/Utility/FileSpec.h" -#include "gtest/gtest.h" -#include <utility> - -using namespace lldb_private; - -namespace { -struct Matches { - FileSpec original; - FileSpec remapped; - Matches(const char *o, const char *r) : original(o), remapped(r) {} -}; -} // namespace - -static void TestPathMappings(const PathMappingList &map, - llvm::ArrayRef<Matches> matches, - llvm::ArrayRef<ConstString> fails) { - ConstString actual_remapped; - for (const auto &fail : fails) { - SCOPED_TRACE(fail.GetCString()); - EXPECT_FALSE(map.RemapPath(fail, actual_remapped)) - << "actual_remapped: " << actual_remapped.GetCString(); - } - for (const auto &match : matches) { - SCOPED_TRACE(match.original.GetPath() + " -> " + match.remapped.GetPath()); - std::string orig_normalized = match.original.GetPath(); - EXPECT_TRUE( - map.RemapPath(ConstString(match.original.GetPath()), actual_remapped)); - EXPECT_EQ(FileSpec(actual_remapped.GetStringRef()), match.remapped); - FileSpec unmapped_spec; - EXPECT_TRUE(map.ReverseRemapPath(match.remapped, unmapped_spec)); - std::string unmapped_path = unmapped_spec.GetPath(); - EXPECT_EQ(unmapped_path, orig_normalized); - } -} - -TEST(PathMappingListTest, RelativeTests) { - Matches matches[] = { - {".", "/tmp"}, - {"./", "/tmp"}, - {"./////", "/tmp"}, - {"./foo.c", "/tmp/foo.c"}, - {"foo.c", "/tmp/foo.c"}, - {"./bar/foo.c", "/tmp/bar/foo.c"}, - {"bar/foo.c", "/tmp/bar/foo.c"}, - }; - ConstString fails[] = { -#ifdef _WIN32 - ConstString("C:\\"), - ConstString("C:\\a"), -#else - ConstString("/a"), - ConstString("/"), -#endif - }; - PathMappingList map; - map.Append(ConstString("."), ConstString("/tmp"), false); - TestPathMappings(map, matches, fails); - PathMappingList map2; - map2.Append(ConstString(""), ConstString("/tmp"), false); - TestPathMappings(map, matches, fails); -} - -TEST(PathMappingListTest, AbsoluteTests) { - PathMappingList map; - map.Append(ConstString("/old"), ConstString("/new"), false); - Matches matches[] = { - {"/old", "/new"}, - {"/old/", "/new"}, - {"/old/foo/.", "/new/foo"}, - {"/old/foo.c", "/new/foo.c"}, - {"/old/foo.c/.", "/new/foo.c"}, - {"/old/./foo.c", "/new/foo.c"}, - }; - ConstString fails[] = { - ConstString("/foo"), - ConstString("/"), - ConstString("foo.c"), - ConstString("./foo.c"), - ConstString("../foo.c"), - ConstString("../bar/foo.c"), - }; - TestPathMappings(map, matches, fails); -} - -TEST(PathMappingListTest, RemapRoot) { - PathMappingList map; - map.Append(ConstString("/"), ConstString("/new"), false); - Matches matches[] = { - {"/old", "/new/old"}, - {"/old/", "/new/old"}, - {"/old/foo/.", "/new/old/foo"}, - {"/old/foo.c", "/new/old/foo.c"}, - {"/old/foo.c/.", "/new/old/foo.c"}, - {"/old/./foo.c", "/new/old/foo.c"}, - }; - ConstString fails[] = { - ConstString("foo.c"), - ConstString("./foo.c"), - ConstString("../foo.c"), - ConstString("../bar/foo.c"), - }; - TestPathMappings(map, matches, fails); -} |