[lld] r183806 - [Darwin][Driver] Add unit tests.

Nick Kledzik kledzik at apple.com
Tue Jun 11 16:45:19 PDT 2013


Rui,

Thanks for doing this.  I had been trying to figure out how to test the command line via scripts by having an option to dump the TargetInfo state.  Using code like this does enable much more precise checking of the TargetInfo state.

-Nick

On Jun 11, 2013, at 4:07 PM, Rui Ueyama <ruiu at google.com> wrote:
> Author: ruiu
> Date: Tue Jun 11 18:07:43 2013
> New Revision: 183806
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=183806&view=rev
> Log:
> [Darwin][Driver] Add unit tests.
> 
> Added:
>    lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
> Modified:
>    lld/trunk/unittests/DriverTests/CMakeLists.txt
> 
> Modified: lld/trunk/unittests/DriverTests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/CMakeLists.txt?rev=183806&r1=183805&r2=183806&view=diff
> ==============================================================================
> --- lld/trunk/unittests/DriverTests/CMakeLists.txt (original)
> +++ lld/trunk/unittests/DriverTests/CMakeLists.txt Tue Jun 11 18:07:43 2013
> @@ -1,6 +1,7 @@
> add_lld_unittest(DriverTests
>   UniversalDriverTest.cpp
>   GnuLdDriverTest.cpp
> +  DarwinLdDriverTest.cpp
>   WinLinkDriverTest.cpp
>   )
> 
> 
> Added: lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp?rev=183806&view=auto
> ==============================================================================
> --- lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp (added)
> +++ lld/trunk/unittests/DriverTests/DarwinLdDriverTest.cpp Tue Jun 11 18:07:43 2013
> @@ -0,0 +1,89 @@
> +//===- lld/unittest/DarwinLdDriverTest.cpp --------------------------------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +///
> +/// \file
> +/// \brief Darwin's ld driver tests.
> +///
> +//===----------------------------------------------------------------------===//
> +
> +#include "DriverTest.h"
> +
> +#include "lld/ReaderWriter/MachOTargetInfo.h"
> +#include "../../lib/ReaderWriter/MachO/MachOFormat.hpp"
> +
> +using namespace llvm;
> +using namespace lld;
> +
> +namespace {
> +
> +class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
> +protected:
> +  virtual MachOTargetInfo* doParse(int argc, const char **argv,
> +                                   raw_ostream &diag) {
> +    auto *info = new MachOTargetInfo();
> +    DarwinLdDriver::parse(argc, argv, *info, diag);
> +    return info;
> +  }
> +};
> +
> +TEST_F(DarwinLdParserTest, Basic) {
> +  parse("ld", "foo.o", "bar.o", nullptr);
> +  EXPECT_FALSE(info->allowRemainingUndefines());
> +  EXPECT_FALSE(info->deadStrip());
> +  EXPECT_EQ(2, (int)inputFiles.size());
> +  EXPECT_EQ("foo.o", inputFiles[0]);
> +  EXPECT_EQ("bar.o", inputFiles[1]);
> +}
> +
> +TEST_F(DarwinLdParserTest, Dylib) {
> +  parse("ld", "-dylib", "foo.o", nullptr);
> +  EXPECT_EQ(mach_o::MH_DYLIB, info->outputFileType());
> +}
> +
> +TEST_F(DarwinLdParserTest, Relocatable) {
> +  parse("ld", "-r", "foo.o", nullptr);
> +  EXPECT_EQ(mach_o::MH_OBJECT, info->outputFileType());
> +}
> +
> +TEST_F(DarwinLdParserTest, Bundle) {
> +  parse("ld", "-bundle", "foo.o", nullptr);
> +  EXPECT_EQ(mach_o::MH_BUNDLE, info->outputFileType());
> +}
> +
> +TEST_F(DarwinLdParserTest, Preload) {
> +  parse("ld", "-preload", "foo.o", nullptr);
> +  EXPECT_EQ(mach_o::MH_PRELOAD, info->outputFileType());
> +}
> +
> +TEST_F(DarwinLdParserTest, Static) {
> +  parse("ld", "-static", "foo.o", nullptr);
> +  EXPECT_EQ(mach_o::MH_EXECUTE, info->outputFileType());
> +}
> +
> +TEST_F(DarwinLdParserTest, Entry) {
> +  parse("ld", "-e", "entryFunc", "foo.o", nullptr);
> +  EXPECT_EQ("entryFunc", info->entrySymbolName());
> +}
> +
> +TEST_F(DarwinLdParserTest, OutputPath) {
> +  parse("ld", "-o", "foo", "foo.o", nullptr);
> +  EXPECT_EQ("foo", info->outputPath());
> +}
> +
> +TEST_F(DarwinLdParserTest, DeadStrip) {
> +  parse("ld", "-dead_strip", "foo.o", nullptr);
> +  EXPECT_TRUE(info->deadStrip());
> +}
> +
> +TEST_F(DarwinLdParserTest, Arch) {
> +  parse("ld", "-arch", "x86_64", "foo.o", nullptr);
> +  EXPECT_EQ(MachOTargetInfo::arch_x86_64, info->arch());
> +}
> +
> +}  // end anonymous namespace
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list