summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/BinaryFormat/CMakeLists.txt9
-rw-r--r--llvm/unittests/BinaryFormat/DwarfTest.cpp (renamed from llvm/unittests/Support/DwarfTest.cpp)5
-rw-r--r--llvm/unittests/BinaryFormat/TestFileMagic.cpp128
-rw-r--r--llvm/unittests/CMakeLists.txt1
-rw-r--r--llvm/unittests/CodeGen/DIEHashTest.cpp2
-rw-r--r--llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp2
-rw-r--r--llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp2
-rw-r--r--llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp2
-rw-r--r--llvm/unittests/MC/DwarfLineTables.cpp2
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/Path.cpp81
11 files changed, 147 insertions, 88 deletions
diff --git a/llvm/unittests/BinaryFormat/CMakeLists.txt b/llvm/unittests/BinaryFormat/CMakeLists.txt
new file mode 100644
index 00000000000..631936795b6
--- /dev/null
+++ b/llvm/unittests/BinaryFormat/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(LLVM_LINK_COMPONENTS
+ BinaryFormat
+ )
+
+add_llvm_unittest(BinaryFormatTests
+ DwarfTest.cpp
+ TestFileMagic.cpp
+ )
+
diff --git a/llvm/unittests/Support/DwarfTest.cpp b/llvm/unittests/BinaryFormat/DwarfTest.cpp
index 148ea2736e1..f24e029beef 100644
--- a/llvm/unittests/Support/DwarfTest.cpp
+++ b/llvm/unittests/BinaryFormat/DwarfTest.cpp
@@ -1,4 +1,4 @@
-//===- unittest/Support/DwarfTest.cpp - Dwarf support tests ---------------===//
+//===- unittest/BinaryFormat/DwarfTest.cpp - Dwarf support tests ----------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Support/Dwarf.h"
+#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/ADT/StringRef.h"
#include "gtest/gtest.h"
using namespace llvm;
diff --git a/llvm/unittests/BinaryFormat/TestFileMagic.cpp b/llvm/unittests/BinaryFormat/TestFileMagic.cpp
new file mode 100644
index 00000000000..fc2c1eef9fb
--- /dev/null
+++ b/llvm/unittests/BinaryFormat/TestFileMagic.cpp
@@ -0,0 +1,128 @@
+//===- llvm/unittest/BinaryFormat/TestFileMagic.cpp - File magic tests ----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Magic.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+namespace fs = llvm::sys::fs;
+
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ SmallString<128> MessageStorage; \
+ raw_svector_ostream Message(MessageStorage); \
+ Message << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
+ } else { \
+ }
+
+class MagicTest : public testing::Test {
+protected:
+ /// Unique temporary directory in which all created filesystem entities must
+ /// be placed. It is removed at the end of each test (must be empty).
+ SmallString<128> TestDirectory;
+
+ void SetUp() override {
+ ASSERT_NO_ERROR(
+ fs::createUniqueDirectory("file-system-test", TestDirectory));
+ // We don't care about this specific file.
+ errs() << "Test Directory: " << TestDirectory << '\n';
+ errs().flush();
+ }
+
+ void TearDown() override { ASSERT_NO_ERROR(fs::remove(TestDirectory.str())); }
+};
+
+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(MagicTest, Magic) {
+ struct type {
+ const char *filename;
+ const char *magic_str;
+ size_t magic_str_len;
+ file_magic magic;
+ } types[] = {
+#define DEFINE(magic) {#magic, magic, sizeof(magic), file_magic::magic}
+ DEFINE(archive),
+ DEFINE(bitcode),
+ DEFINE(coff_object),
+ {"coff_bigobj", coff_bigobj, sizeof(coff_bigobj),
+ 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);
+ llvm::sys::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, identify_magic(magic));
+ ASSERT_NO_ERROR(fs::remove(Twine(file_pathname)));
+ }
+}
diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index 8e40f141463..daece1fe322 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -18,6 +18,7 @@ add_subdirectory(Linker)
add_subdirectory(MC)
add_subdirectory(MI)
add_subdirectory(Object)
+add_subdirectory(BinaryFormat)
add_subdirectory(ObjectYAML)
add_subdirectory(Option)
add_subdirectory(ProfileData)
diff --git a/llvm/unittests/CodeGen/DIEHashTest.cpp b/llvm/unittests/CodeGen/DIEHashTest.cpp
index a962dbfd6ad..f60b0dd3b7e 100644
--- a/llvm/unittests/CodeGen/DIEHashTest.cpp
+++ b/llvm/unittests/CodeGen/DIEHashTest.cpp
@@ -9,10 +9,10 @@
#include "../lib/CodeGen/AsmPrinter/DIEHash.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "gtest/gtest.h"
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
index 3d14eb736df..18cab52a81b 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -13,6 +13,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -21,7 +22,6 @@
#include "llvm/Object/ObjectFile.h"
#include "llvm/ObjectYAML/DWARFEmitter.h"
#include "llvm/ObjectYAML/DWARFYAML.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/TargetSelect.h"
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
index 028a03595de..da7f43e721a 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
@@ -10,7 +10,7 @@
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/Dwarf.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/LEB128.h"
#include "gtest/gtest.h"
diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
index d3bd6c91e36..c32cfa1de9a 100644
--- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -10,6 +10,7 @@
#include "DwarfGenerator.h"
#include "../lib/CodeGen/AsmPrinter/DwarfStringPool.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -28,7 +29,6 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
#include "llvm/PassAnalysisSupport.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/llvm/unittests/MC/DwarfLineTables.cpp b/llvm/unittests/MC/DwarfLineTables.cpp
index 810125f6922..1b1a4d647ce 100644
--- a/llvm/unittests/MC/DwarfLineTables.cpp
+++ b/llvm/unittests/MC/DwarfLineTables.cpp
@@ -8,11 +8,11 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/STLExtras.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCRegisterInfo.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "gtest/gtest.h"
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/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