blob: 303871990f53c14fb8e06fad205aa83f807b947f [file] [log] [blame]
Rui Ueyama9f56df82013-06-11 23:07:43 +00001//===- lld/unittest/DarwinLdDriverTest.cpp --------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Darwin's ld driver tests.
12///
13//===----------------------------------------------------------------------===//
14
15#include "DriverTest.h"
16
17#include "lld/ReaderWriter/MachOTargetInfo.h"
18#include "../../lib/ReaderWriter/MachO/MachOFormat.hpp"
19
20using namespace llvm;
21using namespace lld;
22
23namespace {
24
25class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
26protected:
27 virtual MachOTargetInfo* doParse(int argc, const char **argv,
28 raw_ostream &diag) {
29 auto *info = new MachOTargetInfo();
30 DarwinLdDriver::parse(argc, argv, *info, diag);
31 return info;
32 }
33};
34
35TEST_F(DarwinLdParserTest, Basic) {
36 parse("ld", "foo.o", "bar.o", nullptr);
37 EXPECT_FALSE(info->allowRemainingUndefines());
38 EXPECT_FALSE(info->deadStrip());
39 EXPECT_EQ(2, (int)inputFiles.size());
40 EXPECT_EQ("foo.o", inputFiles[0]);
41 EXPECT_EQ("bar.o", inputFiles[1]);
42}
43
44TEST_F(DarwinLdParserTest, Dylib) {
45 parse("ld", "-dylib", "foo.o", nullptr);
46 EXPECT_EQ(mach_o::MH_DYLIB, info->outputFileType());
47}
48
49TEST_F(DarwinLdParserTest, Relocatable) {
50 parse("ld", "-r", "foo.o", nullptr);
51 EXPECT_EQ(mach_o::MH_OBJECT, info->outputFileType());
52}
53
54TEST_F(DarwinLdParserTest, Bundle) {
55 parse("ld", "-bundle", "foo.o", nullptr);
56 EXPECT_EQ(mach_o::MH_BUNDLE, info->outputFileType());
57}
58
59TEST_F(DarwinLdParserTest, Preload) {
60 parse("ld", "-preload", "foo.o", nullptr);
61 EXPECT_EQ(mach_o::MH_PRELOAD, info->outputFileType());
62}
63
64TEST_F(DarwinLdParserTest, Static) {
65 parse("ld", "-static", "foo.o", nullptr);
66 EXPECT_EQ(mach_o::MH_EXECUTE, info->outputFileType());
67}
68
69TEST_F(DarwinLdParserTest, Entry) {
70 parse("ld", "-e", "entryFunc", "foo.o", nullptr);
71 EXPECT_EQ("entryFunc", info->entrySymbolName());
72}
73
74TEST_F(DarwinLdParserTest, OutputPath) {
75 parse("ld", "-o", "foo", "foo.o", nullptr);
76 EXPECT_EQ("foo", info->outputPath());
77}
78
79TEST_F(DarwinLdParserTest, DeadStrip) {
80 parse("ld", "-dead_strip", "foo.o", nullptr);
81 EXPECT_TRUE(info->deadStrip());
82}
83
84TEST_F(DarwinLdParserTest, Arch) {
85 parse("ld", "-arch", "x86_64", "foo.o", nullptr);
86 EXPECT_EQ(MachOTargetInfo::arch_x86_64, info->arch());
87}
88
89} // end anonymous namespace