summaryrefslogtreecommitdiffstats
path: root/lld/unittests/MachOTests
diff options
context:
space:
mode:
authorJoey Gouly <joey.gouly@gmail.com>2014-01-03 23:12:02 +0000
committerJoey Gouly <joey.gouly@gmail.com>2014-01-03 23:12:02 +0000
commitceb16dedefc7833b3f3b7305e751ad9ba748d99b (patch)
tree7158a67f016d6a8bece0f3cf0b35fd8d62f6ce46 /lld/unittests/MachOTests
parent0724bf67672c754aa61ce2659939450ff22c30fa (diff)
downloadbcm5719-llvm-ceb16dedefc7833b3f3b7305e751ad9ba748d99b.tar.gz
bcm5719-llvm-ceb16dedefc7833b3f3b7305e751ad9ba748d99b.zip
[MachO] Begin to add some MachO specific File/Atoms, and add the start of
normalizedToAtoms. llvm-svn: 198459
Diffstat (limited to 'lld/unittests/MachOTests')
-rw-r--r--lld/unittests/MachOTests/CMakeLists.txt1
-rw-r--r--lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp61
2 files changed, 62 insertions, 0 deletions
diff --git a/lld/unittests/MachOTests/CMakeLists.txt b/lld/unittests/MachOTests/CMakeLists.txt
index e95d261ff7c..23052d366c6 100644
--- a/lld/unittests/MachOTests/CMakeLists.txt
+++ b/lld/unittests/MachOTests/CMakeLists.txt
@@ -2,6 +2,7 @@
add_lld_unittest(lldMachOTests
MachONormalizedFileBinaryReaderTests.cpp
MachONormalizedFileBinaryWriterTests.cpp
+ MachONormalizedFileToAtomsTests.cpp
MachONormalizedFileYAMLTests.cpp
)
diff --git a/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp b/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
new file mode 100644
index 00000000000..9b2859a5961
--- /dev/null
+++ b/lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
@@ -0,0 +1,61 @@
+//===- lld/unittest/MachOTests/MachONormalizedFileToAtomsTests.cpp --------===//
+//
+// 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/Support/MachO.h>
+#include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h"
+
+#include <assert.h>
+#include <vector>
+
+using llvm::ErrorOr;
+
+using namespace lld::mach_o::normalized;
+using namespace llvm::MachO;
+
+unsigned countDefinedAtoms(const lld::File &file) {
+ unsigned count = 0;
+ for (const auto &d : file.defined()) {
+ (void)d;
+ ++count;
+ }
+ return count;
+}
+
+TEST(ToAtomsTest, empty_obj_x86_64) {
+ NormalizedFile f;
+ f.arch = lld::MachOLinkingContext::arch_x86_64;
+ ErrorOr<std::unique_ptr<const lld::File>> atom_f = normalizedToAtoms(f, "");
+ EXPECT_FALSE(!atom_f);
+ EXPECT_EQ(0U, countDefinedAtoms(**atom_f));
+}
+
+TEST(ToAtomsTest, basic_obj_x86_64) {
+ NormalizedFile f;
+ f.arch = lld::MachOLinkingContext::arch_x86_64;
+ Section textSection;
+ static const uint8_t contentBytes[] = { 0x55, 0x48, 0x89, 0xE5,
+ 0x31, 0xC0, 0x5D, 0xC3 };
+ const unsigned contentSize = sizeof(contentBytes) / sizeof(contentBytes[0]);
+ textSection.content.insert(textSection.content.begin(), contentBytes,
+ &contentBytes[contentSize]);
+ f.sections.push_back(textSection);
+ Symbol mainSymbol;
+ mainSymbol.name = "_main";
+ mainSymbol.type = N_SECT;
+ mainSymbol.sect = 1;
+ f.globalSymbols.push_back(mainSymbol);
+ ErrorOr<std::unique_ptr<const lld::File>> atom_f = normalizedToAtoms(f, "");
+ EXPECT_FALSE(!atom_f);
+ EXPECT_EQ(1U, countDefinedAtoms(**atom_f));
+ const lld::DefinedAtom *singleAtom = *(*atom_f)->defined().begin();
+ llvm::ArrayRef<uint8_t> atomContent(singleAtom->rawContent());
+ EXPECT_EQ(0, memcmp(atomContent.data(), contentBytes, contentSize));
+}
OpenPOWER on IntegriCloud