summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-06-07 03:48:56 +0000
committerZachary Turner <zturner@google.com>2017-06-07 03:48:56 +0000
commit264b5d9e8817fce8c47d2b06aba2d9244e426794 (patch)
tree234a31fd342ebd5f14a17da05bc7c3ca92cf25f1 /llvm/unittests/Support
parentb4b16556e348ef42e69aff3c9f4332afc8fae67b (diff)
downloadbcm5719-llvm-264b5d9e8817fce8c47d2b06aba2d9244e426794.tar.gz
bcm5719-llvm-264b5d9e8817fce8c47d2b06aba2d9244e426794.zip
Move Object format code to lib/BinaryFormat.
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/DwarfTest.cpp141
-rw-r--r--llvm/unittests/Support/Path.cpp81
3 files changed, 1 insertions, 222 deletions
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index e7f2f515d76..83d81927384 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -19,7 +19,6 @@ add_llvm_unittest(SupportTests
ConvertUTFTest.cpp
DataExtractorTest.cpp
DebugTest.cpp
- DwarfTest.cpp
EndianStreamTest.cpp
EndianTest.cpp
ErrorOrTest.cpp
diff --git a/llvm/unittests/Support/DwarfTest.cpp b/llvm/unittests/Support/DwarfTest.cpp
deleted file mode 100644
index 148ea2736e1..00000000000
--- a/llvm/unittests/Support/DwarfTest.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-//===- unittest/Support/DwarfTest.cpp - Dwarf support tests ---------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/Dwarf.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace llvm::dwarf;
-
-namespace {
-
-TEST(DwarfTest, TagStringOnInvalid) {
- // This is invalid, so it shouldn't be stringified.
- EXPECT_EQ(StringRef(), TagString(DW_TAG_invalid));
-
- // These aren't really tags: they describe ranges within tags. They
- // shouldn't be stringified either.
- EXPECT_EQ(StringRef(), TagString(DW_TAG_lo_user));
- EXPECT_EQ(StringRef(), TagString(DW_TAG_hi_user));
- EXPECT_EQ(StringRef(), TagString(DW_TAG_user_base));
-}
-
-TEST(DwarfTest, getTag) {
- // A couple of valid tags.
- EXPECT_EQ(DW_TAG_array_type, getTag("DW_TAG_array_type"));
- EXPECT_EQ(DW_TAG_module, getTag("DW_TAG_module"));
-
- // Invalid tags.
- EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_invalid"));
- EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_madeuptag"));
- EXPECT_EQ(DW_TAG_invalid, getTag("something else"));
-
- // Tag range markers should not be recognized.
- EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_lo_user"));
- EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_hi_user"));
- EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_user_base"));
-}
-
-TEST(DwarfTest, getOperationEncoding) {
- // Some valid ops.
- EXPECT_EQ(DW_OP_deref, getOperationEncoding("DW_OP_deref"));
- EXPECT_EQ(DW_OP_bit_piece, getOperationEncoding("DW_OP_bit_piece"));
-
- // Invalid ops.
- EXPECT_EQ(0u, getOperationEncoding("DW_OP_otherthings"));
- EXPECT_EQ(0u, getOperationEncoding("other"));
-
- // Markers shouldn't be recognized.
- EXPECT_EQ(0u, getOperationEncoding("DW_OP_lo_user"));
- EXPECT_EQ(0u, getOperationEncoding("DW_OP_hi_user"));
-}
-
-TEST(DwarfTest, LanguageStringOnInvalid) {
- // This is invalid, so it shouldn't be stringified.
- EXPECT_EQ(StringRef(), LanguageString(0));
-
- // These aren't really tags: they describe ranges within tags. They
- // shouldn't be stringified either.
- EXPECT_EQ(StringRef(), LanguageString(DW_LANG_lo_user));
- EXPECT_EQ(StringRef(), LanguageString(DW_LANG_hi_user));
-}
-
-TEST(DwarfTest, getLanguage) {
- // A couple of valid languages.
- EXPECT_EQ(DW_LANG_C89, getLanguage("DW_LANG_C89"));
- EXPECT_EQ(DW_LANG_C_plus_plus_11, getLanguage("DW_LANG_C_plus_plus_11"));
- EXPECT_EQ(DW_LANG_OCaml, getLanguage("DW_LANG_OCaml"));
- EXPECT_EQ(DW_LANG_Mips_Assembler, getLanguage("DW_LANG_Mips_Assembler"));
-
- // Invalid languages.
- EXPECT_EQ(0u, getLanguage("DW_LANG_invalid"));
- EXPECT_EQ(0u, getLanguage("DW_TAG_array_type"));
- EXPECT_EQ(0u, getLanguage("something else"));
-
- // Language range markers should not be recognized.
- EXPECT_EQ(0u, getLanguage("DW_LANG_lo_user"));
- EXPECT_EQ(0u, getLanguage("DW_LANG_hi_user"));
-}
-
-TEST(DwarfTest, AttributeEncodingStringOnInvalid) {
- // This is invalid, so it shouldn't be stringified.
- EXPECT_EQ(StringRef(), AttributeEncodingString(0));
-
- // These aren't really tags: they describe ranges within tags. They
- // shouldn't be stringified either.
- EXPECT_EQ(StringRef(), AttributeEncodingString(DW_ATE_lo_user));
- EXPECT_EQ(StringRef(), AttributeEncodingString(DW_ATE_hi_user));
-}
-
-TEST(DwarfTest, getAttributeEncoding) {
- // A couple of valid languages.
- EXPECT_EQ(DW_ATE_boolean, getAttributeEncoding("DW_ATE_boolean"));
- EXPECT_EQ(DW_ATE_imaginary_float,
- getAttributeEncoding("DW_ATE_imaginary_float"));
-
- // Invalid languages.
- EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_invalid"));
- EXPECT_EQ(0u, getAttributeEncoding("DW_TAG_array_type"));
- EXPECT_EQ(0u, getAttributeEncoding("something else"));
-
- // AttributeEncoding range markers should not be recognized.
- EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_lo_user"));
- EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_hi_user"));
-}
-
-TEST(DwarfTest, VirtualityString) {
- EXPECT_EQ(StringRef("DW_VIRTUALITY_none"),
- VirtualityString(DW_VIRTUALITY_none));
- EXPECT_EQ(StringRef("DW_VIRTUALITY_virtual"),
- VirtualityString(DW_VIRTUALITY_virtual));
- EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"),
- VirtualityString(DW_VIRTUALITY_pure_virtual));
-
- // DW_VIRTUALITY_max should be pure virtual.
- EXPECT_EQ(StringRef("DW_VIRTUALITY_pure_virtual"),
- VirtualityString(DW_VIRTUALITY_max));
-
- // Invalid numbers shouldn't be stringified.
- EXPECT_EQ(StringRef(), VirtualityString(DW_VIRTUALITY_max + 1));
- EXPECT_EQ(StringRef(), VirtualityString(DW_VIRTUALITY_max + 77));
-}
-
-TEST(DwarfTest, getVirtuality) {
- EXPECT_EQ(DW_VIRTUALITY_none, getVirtuality("DW_VIRTUALITY_none"));
- EXPECT_EQ(DW_VIRTUALITY_virtual, getVirtuality("DW_VIRTUALITY_virtual"));
- EXPECT_EQ(DW_VIRTUALITY_pure_virtual,
- getVirtuality("DW_VIRTUALITY_pure_virtual"));
-
- // Invalid strings.
- EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_invalid"));
- EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("DW_VIRTUALITY_max"));
- EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("something else"));
-}
-
-} // end namespace
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index 90aa2b3a2b3..3e474f33ca6 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -11,6 +11,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
@@ -919,86 +920,6 @@ TEST_F(FileSystemTest, Remove) {
ASSERT_FALSE(fs::exists(BaseDir));
}
-const char archive[] = "!<arch>\x0A";
-const char bitcode[] = "\xde\xc0\x17\x0b";
-const char coff_object[] = "\x00\x00......";
-const char coff_bigobj[] = "\x00\x00\xff\xff\x00\x02......"
- "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8";
-const char coff_import_library[] = "\x00\x00\xff\xff....";
-const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 1 };
-const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00";
-const char macho_object[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x01............";
-const char macho_executable[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x02............";
-const char macho_fixed_virtual_memory_shared_lib[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x03............";
-const char macho_core[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x04............";
-const char macho_preload_executable[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x05............";
-const char macho_dynamically_linked_shared_lib[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x06............";
-const char macho_dynamic_linker[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x07............";
-const char macho_bundle[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x08............";
-const char macho_dsym_companion[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x0a............";
-const char macho_kext_bundle[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x0b............";
-const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff";
-const char macho_dynamically_linked_shared_lib_stub[] =
- "\xfe\xed\xfa\xce........\x00\x00\x00\x09............";
-
-TEST_F(FileSystemTest, Magic) {
- struct type {
- const char *filename;
- const char *magic_str;
- size_t magic_str_len;
- fs::file_magic magic;
- } types[] = {
-#define DEFINE(magic) \
- { #magic, magic, sizeof(magic), fs::file_magic::magic }
- DEFINE(archive),
- DEFINE(bitcode),
- DEFINE(coff_object),
- { "coff_bigobj", coff_bigobj, sizeof(coff_bigobj), fs::file_magic::coff_object },
- DEFINE(coff_import_library),
- DEFINE(elf_relocatable),
- DEFINE(macho_universal_binary),
- DEFINE(macho_object),
- DEFINE(macho_executable),
- DEFINE(macho_fixed_virtual_memory_shared_lib),
- DEFINE(macho_core),
- DEFINE(macho_preload_executable),
- DEFINE(macho_dynamically_linked_shared_lib),
- DEFINE(macho_dynamic_linker),
- DEFINE(macho_bundle),
- DEFINE(macho_dynamically_linked_shared_lib_stub),
- DEFINE(macho_dsym_companion),
- DEFINE(macho_kext_bundle),
- DEFINE(windows_resource)
-#undef DEFINE
- };
-
- // Create some files filled with magic.
- for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e;
- ++i) {
- SmallString<128> file_pathname(TestDirectory);
- path::append(file_pathname, i->filename);
- std::error_code EC;
- raw_fd_ostream file(file_pathname, EC, sys::fs::F_None);
- ASSERT_FALSE(file.has_error());
- StringRef magic(i->magic_str, i->magic_str_len);
- file << magic;
- file.close();
- EXPECT_EQ(i->magic, fs::identify_magic(magic));
- ASSERT_NO_ERROR(fs::remove(Twine(file_pathname)));
- }
-}
-
#ifdef LLVM_ON_WIN32
TEST_F(FileSystemTest, CarriageReturn) {
SmallString<128> FilePathname(TestDirectory);
OpenPOWER on IntegriCloud