diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
commit | 3176e97f130184ece0e1a21352c8124cc83ff24a (patch) | |
tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /unittests/Driver/ToolChainTest.cpp | |
parent | 1e9b8d38881c3213d1e67b0c47ab9b2c00721a5c (diff) | |
download | FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.zip FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.tar.gz |
Vendor import of clang trunk r256633:
https://llvm.org/svn/llvm-project/cfe/trunk@256633
Diffstat (limited to 'unittests/Driver/ToolChainTest.cpp')
-rw-r--r-- | unittests/Driver/ToolChainTest.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/unittests/Driver/ToolChainTest.cpp b/unittests/Driver/ToolChainTest.cpp new file mode 100644 index 0000000..ef21e2d --- /dev/null +++ b/unittests/Driver/ToolChainTest.cpp @@ -0,0 +1,120 @@ +//===- unittests/Driver/ToolChainTest.cpp --- ToolChain tests -------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Unit tests for ToolChains. +// +//===----------------------------------------------------------------------===// + +#include "clang/Driver/ToolChain.h" +#include "clang/Basic/DiagnosticIDs.h" +#include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/VirtualFileSystem.h" +#include "clang/Driver/Compilation.h" +#include "clang/Driver/Driver.h" +#include "llvm/Support/raw_ostream.h" +#include "gtest/gtest.h" +using namespace clang; +using namespace clang::driver; + +namespace { + +TEST(ToolChainTest, VFSGCCInstallation) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( + new vfs::InMemoryFileSystem); + Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags, + InMemoryFileSystem); + + const char *EmptyFiles[] = { + "foo.cpp", + "/bin/clang", + "/usr/lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o", + "/usr/lib/gcc/arm-linux-gnueabi/4.6.1/crtend.o", + "/usr/lib/gcc/arm-linux-gnueabihf/4.6.3/crtbegin.o", + "/usr/lib/gcc/arm-linux-gnueabihf/4.6.3/crtend.o", + "/usr/lib/arm-linux-gnueabi/crt1.o", + "/usr/lib/arm-linux-gnueabi/crti.o", + "/usr/lib/arm-linux-gnueabi/crtn.o", + "/usr/lib/arm-linux-gnueabihf/crt1.o", + "/usr/lib/arm-linux-gnueabihf/crti.o", + "/usr/lib/arm-linux-gnueabihf/crtn.o", + "/usr/include/arm-linux-gnueabi/.keep", + "/usr/include/arm-linux-gnueabihf/.keep", + "/lib/arm-linux-gnueabi/.keep", + "/lib/arm-linux-gnueabihf/.keep"}; + + for (const char *Path : EmptyFiles) + InMemoryFileSystem->addFile(Path, 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation( + {"-fsyntax-only", "--gcc-toolchain=", "foo.cpp"})); + + std::string S; + { + llvm::raw_string_ostream OS(S); + C->getDefaultToolChain().printVerboseInfo(OS); + } +#if LLVM_ON_WIN32 + std::replace(S.begin(), S.end(), '\\', '/'); +#endif + EXPECT_EQ( + "Found candidate GCC installation: " + "/usr/lib/gcc/arm-linux-gnueabihf/4.6.3\n" + "Selected GCC installation: /usr/lib/gcc/arm-linux-gnueabihf/4.6.3\n" + "Candidate multilib: .;@m32\n" + "Selected multilib: .;@m32\n", + S); +} + +TEST(ToolChainTest, VFSGCCInstallationRelativeDir) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( + new vfs::InMemoryFileSystem); + Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, + InMemoryFileSystem); + + const char *EmptyFiles[] = { + "foo.cpp", "/home/test/lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o", + "/home/test/include/arm-linux-gnueabi/.keep"}; + + for (const char *Path : EmptyFiles) + InMemoryFileSystem->addFile(Path, 0, + llvm::MemoryBuffer::getMemBuffer("\n")); + + std::unique_ptr<Compilation> C(TheDriver.BuildCompilation( + {"-fsyntax-only", "--gcc-toolchain=", "foo.cpp"})); + + std::string S; + { + llvm::raw_string_ostream OS(S); + C->getDefaultToolChain().printVerboseInfo(OS); + } +#if LLVM_ON_WIN32 + std::replace(S.begin(), S.end(), '\\', '/'); +#endif + EXPECT_EQ("Found candidate GCC installation: " + "/home/test/lib/gcc/arm-linux-gnueabi/4.6.1\n" + "Selected GCC installation: " + "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n" + "Candidate multilib: .;@m32\n" + "Selected multilib: .;@m32\n", + S); +} + +} // end anonymous namespace |