Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,17 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Support
Option
)
add_clang_unittest(ClangDriverTests
DistroTest.cpp
ToolChainTest.cpp
MultilibTest.cpp
)
target_link_libraries(ClangDriverTests
PRIVATE
clangDriver
clangBasic
)

View File

@@ -0,0 +1,305 @@
//===- unittests/Driver/DistroTest.cpp --- ToolChains 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 Distro detection.
//
//===----------------------------------------------------------------------===//
#include "clang/Driver/Distro.h"
#include "clang/Basic/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace clang;
using namespace clang::driver;
namespace {
// The tests include all release-related files for each distribution
// in the VFS, in order to make sure that earlier tests do not
// accidentally result in incorrect distribution guess.
TEST(DistroTest, DetectUbuntu) {
vfs::InMemoryFileSystem UbuntuTrustyFileSystem;
// Ubuntu uses Debian Sid version.
UbuntuTrustyFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("jessie/sid\n"));
UbuntuTrustyFileSystem.addFile("/etc/lsb-release", 0,
llvm::MemoryBuffer::getMemBuffer("DISTRIB_ID=Ubuntu\n"
"DISTRIB_RELEASE=14.04\n"
"DISTRIB_CODENAME=trusty\n"
"DISTRIB_DESCRIPTION=\"Ubuntu 14.04 LTS\"\n"));
UbuntuTrustyFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"Ubuntu\"\n"
"VERSION=\"14.04, Trusty Tahr\"\n"
"ID=ubuntu\n"
"ID_LIKE=debian\n"
"PRETTY_NAME=\"Ubuntu 14.04 LTS\"\n"
"VERSION_ID=\"14.04\"\n"
"HOME_URL=\"http://www.ubuntu.com/\"\n"
"SUPPORT_URL=\"http://help.ubuntu.com/\"\n"
"BUG_REPORT_URL=\"http://bugs.launchpad.net/ubuntu/\"\n"));
Distro UbuntuTrusty{UbuntuTrustyFileSystem};
ASSERT_EQ(Distro(Distro::UbuntuTrusty), UbuntuTrusty);
ASSERT_TRUE(UbuntuTrusty.IsUbuntu());
ASSERT_FALSE(UbuntuTrusty.IsRedhat());
ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
ASSERT_FALSE(UbuntuTrusty.IsDebian());
vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("stretch/sid\n"));
UbuntuYakketyFileSystem.addFile("/etc/lsb-release", 0,
llvm::MemoryBuffer::getMemBuffer("DISTRIB_ID=Ubuntu\n"
"DISTRIB_RELEASE=16.10\n"
"DISTRIB_CODENAME=yakkety\n"
"DISTRIB_DESCRIPTION=\"Ubuntu 16.10\"\n"));
UbuntuYakketyFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"Ubuntu\"\n"
"VERSION=\"16.10 (Yakkety Yak)\"\n"
"ID=ubuntu\n"
"ID_LIKE=debian\n"
"PRETTY_NAME=\"Ubuntu 16.10\"\n"
"VERSION_ID=\"16.10\"\n"
"HOME_URL=\"http://www.ubuntu.com/\"\n"
"SUPPORT_URL=\"http://help.ubuntu.com/\"\n"
"BUG_REPORT_URL=\"http://bugs.launchpad.net/ubuntu/\"\n"
"PRIVACY_POLICY_URL=\"http://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\n"
"VERSION_CODENAME=yakkety\n"
"UBUNTU_CODENAME=yakkety\n"));
Distro UbuntuYakkety{UbuntuYakketyFileSystem};
ASSERT_EQ(Distro(Distro::UbuntuYakkety), UbuntuYakkety);
ASSERT_TRUE(UbuntuYakkety.IsUbuntu());
ASSERT_FALSE(UbuntuYakkety.IsRedhat());
ASSERT_FALSE(UbuntuYakkety.IsOpenSUSE());
ASSERT_FALSE(UbuntuYakkety.IsDebian());
}
TEST(DistroTest, DetectRedhat) {
vfs::InMemoryFileSystem Fedora25FileSystem;
Fedora25FileSystem.addFile("/etc/system-release-cpe", 0,
llvm::MemoryBuffer::getMemBuffer("cpe:/o:fedoraproject:fedora:25\n"));
// Both files are symlinks to fedora-release.
Fedora25FileSystem.addFile("/etc/system-release", 0,
llvm::MemoryBuffer::getMemBuffer("Fedora release 25 (Twenty Five)\n"));
Fedora25FileSystem.addFile("/etc/redhat-release", 0,
llvm::MemoryBuffer::getMemBuffer("Fedora release 25 (Twenty Five)\n"));
Fedora25FileSystem.addFile("/etc/fedora-release", 0,
llvm::MemoryBuffer::getMemBuffer("Fedora release 25 (Twenty Five)\n"));
Fedora25FileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=Fedora\n"
"VERSION=\"25 (Twenty Five)\"\n"
"ID=fedora\n"
"VERSION_ID=25\n"
"PRETTY_NAME=\"Fedora 25 (Twenty Five)\"\n"
"ANSI_COLOR=\"0;34\"\n"
"CPE_NAME=\"cpe:/o:fedoraproject:fedora:25\"\n"
"HOME_URL=\"https://fedoraproject.org/\"\n"
"BUG_REPORT_URL=\"https://bugzilla.redhat.com/\"\n"
"REDHAT_BUGZILLA_PRODUCT=\"Fedora\"\n"
"REDHAT_BUGZILLA_PRODUCT_VERSION=25\n"
"REDHAT_SUPPORT_PRODUCT=\"Fedora\"\n"
"REDHAT_SUPPORT_PRODUCT_VERSION=25\n"
"PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy\n"));
Distro Fedora25{Fedora25FileSystem};
ASSERT_EQ(Distro(Distro::Fedora), Fedora25);
ASSERT_FALSE(Fedora25.IsUbuntu());
ASSERT_TRUE(Fedora25.IsRedhat());
ASSERT_FALSE(Fedora25.IsOpenSUSE());
ASSERT_FALSE(Fedora25.IsDebian());
vfs::InMemoryFileSystem CentOS7FileSystem;
CentOS7FileSystem.addFile("/etc/system-release-cpe", 0,
llvm::MemoryBuffer::getMemBuffer("cpe:/o:centos:centos:7\n"));
// Both files are symlinks to centos-release.
CentOS7FileSystem.addFile("/etc/system-release", 0,
llvm::MemoryBuffer::getMemBuffer("CentOS Linux release 7.2.1511 (Core) \n"));
CentOS7FileSystem.addFile("/etc/redhat-release", 0,
llvm::MemoryBuffer::getMemBuffer("CentOS Linux release 7.2.1511 (Core) \n"));
CentOS7FileSystem.addFile("/etc/centos-release", 0,
llvm::MemoryBuffer::getMemBuffer("CentOS Linux release 7.2.1511 (Core) \n"));
CentOS7FileSystem.addFile("/etc/centos-release-upstream", 0,
llvm::MemoryBuffer::getMemBuffer("Derived from Red Hat Enterprise Linux 7.2 (Source)\n"));
CentOS7FileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"CentOS Linux\"\n"
"VERSION=\"7 (Core)\"\n"
"ID=\"centos\"\n"
"ID_LIKE=\"rhel fedora\"\n"
"VERSION_ID=\"7\"\n"
"PRETTY_NAME=\"CentOS Linux 7 (Core)\"\n"
"ANSI_COLOR=\"0;31\"\n"
"CPE_NAME=\"cpe:/o:centos:centos:7\"\n"
"HOME_URL=\"https://www.centos.org/\"\n"
"BUG_REPORT_URL=\"https://bugs.centos.org/\"\n"
"\n"
"CENTOS_MANTISBT_PROJECT=\"CentOS-7\"\n"
"CENTOS_MANTISBT_PROJECT_VERSION=\"7\"\n"
"REDHAT_SUPPORT_PRODUCT=\"centos\"\n"
"REDHAT_SUPPORT_PRODUCT_VERSION=\"7\"\n"));
Distro CentOS7{CentOS7FileSystem};
ASSERT_EQ(Distro(Distro::RHEL7), CentOS7);
ASSERT_FALSE(CentOS7.IsUbuntu());
ASSERT_TRUE(CentOS7.IsRedhat());
ASSERT_FALSE(CentOS7.IsOpenSUSE());
ASSERT_FALSE(CentOS7.IsDebian());
}
TEST(DistroTest, DetectOpenSUSE) {
vfs::InMemoryFileSystem OpenSUSELeap421FileSystem;
OpenSUSELeap421FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("openSUSE 42.1 (x86_64)\n"
"VERSION = 42.1\n"
"CODENAME = Malachite\n"
"# /etc/SuSE-release is deprecated and will be removed in the future, use /etc/os-release instead\n"));
OpenSUSELeap421FileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"openSUSE Leap\"\n"
"VERSION=\"42.1\"\n"
"VERSION_ID=\"42.1\"\n"
"PRETTY_NAME=\"openSUSE Leap 42.1 (x86_64)\"\n"
"ID=opensuse\n"
"ANSI_COLOR=\"0;32\"\n"
"CPE_NAME=\"cpe:/o:opensuse:opensuse:42.1\"\n"
"BUG_REPORT_URL=\"https://bugs.opensuse.org\"\n"
"HOME_URL=\"https://opensuse.org/\"\n"
"ID_LIKE=\"suse\"\n"));
Distro OpenSUSELeap421{OpenSUSELeap421FileSystem};
ASSERT_EQ(Distro(Distro::OpenSUSE), OpenSUSELeap421);
ASSERT_FALSE(OpenSUSELeap421.IsUbuntu());
ASSERT_FALSE(OpenSUSELeap421.IsRedhat());
ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
ASSERT_FALSE(OpenSUSELeap421.IsDebian());
vfs::InMemoryFileSystem OpenSUSE132FileSystem;
OpenSUSE132FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("openSUSE 13.2 (x86_64)\n"
"VERSION = 13.2\n"
"CODENAME = Harlequin\n"
"# /etc/SuSE-release is deprecated and will be removed in the future, use /etc/os-release instead\n"));
OpenSUSE132FileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=openSUSE\n"
"VERSION=\"13.2 (Harlequin)\"\n"
"VERSION_ID=\"13.2\"\n"
"PRETTY_NAME=\"openSUSE 13.2 (Harlequin) (x86_64)\"\n"
"ID=opensuse\n"
"ANSI_COLOR=\"0;32\"\n"
"CPE_NAME=\"cpe:/o:opensuse:opensuse:13.2\"\n"
"BUG_REPORT_URL=\"https://bugs.opensuse.org\"\n"
"HOME_URL=\"https://opensuse.org/\"\n"
"ID_LIKE=\"suse\"\n"));
Distro OpenSUSE132{OpenSUSE132FileSystem};
ASSERT_EQ(Distro(Distro::OpenSUSE), OpenSUSE132);
ASSERT_FALSE(OpenSUSE132.IsUbuntu());
ASSERT_FALSE(OpenSUSE132.IsRedhat());
ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
ASSERT_FALSE(OpenSUSE132.IsDebian());
vfs::InMemoryFileSystem SLES10FileSystem;
SLES10FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("SUSE Linux Enterprise Server 10 (x86_64)\n"
"VERSION = 10\n"
"PATCHLEVEL = 4\n"));
SLES10FileSystem.addFile("/etc/lsb_release", 0,
llvm::MemoryBuffer::getMemBuffer("LSB_VERSION=\"core-2.0-noarch:core-3.0-noarch:core-2.0-x86_64:core-3.0-x86_64\"\n"));
// SLES10 is unsupported and therefore evaluates to unknown
Distro SLES10{SLES10FileSystem};
ASSERT_EQ(Distro(Distro::UnknownDistro), SLES10);
ASSERT_FALSE(SLES10.IsUbuntu());
ASSERT_FALSE(SLES10.IsRedhat());
ASSERT_FALSE(SLES10.IsOpenSUSE());
ASSERT_FALSE(SLES10.IsDebian());
}
TEST(DistroTest, DetectDebian) {
vfs::InMemoryFileSystem DebianJessieFileSystem;
DebianJessieFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("8.6\n"));
DebianJessieFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("PRETTY_NAME=\"Debian GNU/Linux 8 (jessie)\"\n"
"NAME=\"Debian GNU/Linux\"\n"
"VERSION_ID=\"8\"\n"
"VERSION=\"8 (jessie)\"\n"
"ID=debian\n"
"HOME_URL=\"http://www.debian.org/\"\n"
"SUPPORT_URL=\"http://www.debian.org/support\"\n"
"BUG_REPORT_URL=\"https://bugs.debian.org/\"\n"));
Distro DebianJessie{DebianJessieFileSystem};
ASSERT_EQ(Distro(Distro::DebianJessie), DebianJessie);
ASSERT_FALSE(DebianJessie.IsUbuntu());
ASSERT_FALSE(DebianJessie.IsRedhat());
ASSERT_FALSE(DebianJessie.IsOpenSUSE());
ASSERT_TRUE(DebianJessie.IsDebian());
vfs::InMemoryFileSystem DebianStretchSidFileSystem;
DebianStretchSidFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("stretch/sid\n"));
DebianStretchSidFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("PRETTY_NAME=\"Debian GNU/Linux stretch/sid\"\n"
"NAME=\"Debian GNU/Linux\"\n"
"ID=debian\n"
"HOME_URL=\"http://www.debian.org/\"\n"
"SUPPORT_URL=\"http://www.debian.org/support\"\n"
"BUG_REPORT_URL=\"https://bugs.debian.org/\"\n"));
Distro DebianStretchSid{DebianStretchSidFileSystem};
ASSERT_EQ(Distro(Distro::DebianStretch), DebianStretchSid);
ASSERT_FALSE(DebianStretchSid.IsUbuntu());
ASSERT_FALSE(DebianStretchSid.IsRedhat());
ASSERT_FALSE(DebianStretchSid.IsOpenSUSE());
ASSERT_TRUE(DebianStretchSid.IsDebian());
}
TEST(DistroTest, DetectExherbo) {
vfs::InMemoryFileSystem ExherboFileSystem;
ExherboFileSystem.addFile("/etc/exherbo-release", 0, // (ASCII art)
llvm::MemoryBuffer::getMemBuffer(""));
ExherboFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"Exherbo\"\n"
"PRETTY_NAME=\"Exherbo Linux\"\n"
"ID=\"exherbo\"\n"
"ANSI_COLOR=\"0;32\"\n"
"HOME_URL=\"https://www.exherbo.org/\"\n"
"SUPPORT_URL=\"irc://irc.freenode.net/#exherbo\"\n"
"BUG_REPORT_URL=\"https://bugs.exherbo.org/\"\n"));
Distro Exherbo{ExherboFileSystem};
ASSERT_EQ(Distro(Distro::Exherbo), Exherbo);
ASSERT_FALSE(Exherbo.IsUbuntu());
ASSERT_FALSE(Exherbo.IsRedhat());
ASSERT_FALSE(Exherbo.IsOpenSUSE());
ASSERT_FALSE(Exherbo.IsDebian());
}
TEST(DistroTest, DetectArchLinux) {
vfs::InMemoryFileSystem ArchLinuxFileSystem;
ArchLinuxFileSystem.addFile("/etc/arch-release", 0, // (empty)
llvm::MemoryBuffer::getMemBuffer(""));
ArchLinuxFileSystem.addFile("/etc/os-release", 0,
llvm::MemoryBuffer::getMemBuffer("NAME=\"Arch Linux\"\n"
"ID=arch\n"
"PRETTY_NAME=\"Arch Linux\"\n"
"ANSI_COLOR=\"0;36\"\n"
"HOME_URL=\"https://www.archlinux.org/\"\n"
"SUPPORT_URL=\"https://bbs.archlinux.org/\"\n"
"BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n"));
Distro ArchLinux{ArchLinuxFileSystem};
ASSERT_EQ(Distro(Distro::ArchLinux), ArchLinux);
ASSERT_FALSE(ArchLinux.IsUbuntu());
ASSERT_FALSE(ArchLinux.IsRedhat());
ASSERT_FALSE(ArchLinux.IsOpenSUSE());
ASSERT_FALSE(ArchLinux.IsDebian());
}
} // end anonymous namespace

View File

@@ -0,0 +1,352 @@
//===- unittests/Driver/MultilibTest.cpp --- Multilib 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 Multilib and MultilibSet
//
//===----------------------------------------------------------------------===//
#include "clang/Driver/Multilib.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "gtest/gtest.h"
using namespace clang::driver;
using namespace clang;
TEST(MultilibTest, MultilibValidity) {
ASSERT_TRUE(Multilib().isValid()) << "Empty multilib is not valid";
ASSERT_TRUE(Multilib().flag("+foo").isValid())
<< "Single indicative flag is not valid";
ASSERT_TRUE(Multilib().flag("-foo").isValid())
<< "Single contraindicative flag is not valid";
ASSERT_FALSE(Multilib().flag("+foo").flag("-foo").isValid())
<< "Conflicting flags should invalidate the Multilib";
ASSERT_TRUE(Multilib().flag("+foo").flag("+foo").isValid())
<< "Multilib should be valid even if it has the same flag twice";
ASSERT_TRUE(Multilib().flag("+foo").flag("-foobar").isValid())
<< "Seemingly conflicting prefixes shouldn't actually conflict";
}
TEST(MultilibTest, OpEqReflexivity1) {
Multilib M;
ASSERT_TRUE(M == M) << "Multilib::operator==() is not reflexive";
}
TEST(MultilibTest, OpEqReflexivity2) {
ASSERT_TRUE(Multilib() == Multilib())
<< "Separately constructed default multilibs are not equal";
}
TEST(MultilibTest, OpEqReflexivity3) {
Multilib M1, M2;
M1.flag("+foo");
M2.flag("+foo");
ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
}
TEST(MultilibTest, OpEqInequivalence1) {
Multilib M1, M2;
M1.flag("+foo");
M2.flag("-foo");
ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
ASSERT_FALSE(M2 == M1)
<< "Multilibs with conflicting flags are not the same (commuted)";
}
TEST(MultilibTest, OpEqInequivalence2) {
Multilib M1, M2;
M2.flag("+foo");
ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
}
TEST(MultilibTest, OpEqEquivalence1) {
Multilib M1, M2;
M1.flag("+foo");
M2.flag("+foo").flag("+foo");
ASSERT_TRUE(M1 == M2) << "Flag duplication shouldn't affect equivalence";
ASSERT_TRUE(M2 == M1)
<< "Flag duplication shouldn't affect equivalence (commuted)";
}
TEST(MultilibTest, OpEqEquivalence2) {
Multilib M1("64");
Multilib M2;
M2.gccSuffix("/64");
ASSERT_TRUE(M1 == M2)
<< "Constructor argument must match Multilib::gccSuffix()";
ASSERT_TRUE(M2 == M1)
<< "Constructor argument must match Multilib::gccSuffix() (commuted)";
}
TEST(MultilibTest, OpEqEquivalence3) {
Multilib M1("", "32");
Multilib M2;
M2.osSuffix("/32");
ASSERT_TRUE(M1 == M2)
<< "Constructor argument must match Multilib::osSuffix()";
ASSERT_TRUE(M2 == M1)
<< "Constructor argument must match Multilib::osSuffix() (commuted)";
}
TEST(MultilibTest, OpEqEquivalence4) {
Multilib M1("", "", "16");
Multilib M2;
M2.includeSuffix("/16");
ASSERT_TRUE(M1 == M2)
<< "Constructor argument must match Multilib::includeSuffix()";
ASSERT_TRUE(M2 == M1)
<< "Constructor argument must match Multilib::includeSuffix() (commuted)";
}
TEST(MultilibTest, OpEqInequivalence3) {
Multilib M1("foo");
Multilib M2("bar");
ASSERT_FALSE(M1 == M2) << "Differing gccSuffixes should be different";
ASSERT_FALSE(M2 == M1)
<< "Differing gccSuffixes should be different (commuted)";
}
TEST(MultilibTest, OpEqInequivalence4) {
Multilib M1("", "foo");
Multilib M2("", "bar");
ASSERT_FALSE(M1 == M2) << "Differing osSuffixes should be different";
ASSERT_FALSE(M2 == M1)
<< "Differing osSuffixes should be different (commuted)";
}
TEST(MultilibTest, OpEqInequivalence5) {
Multilib M1("", "", "foo");
Multilib M2("", "", "bar");
ASSERT_FALSE(M1 == M2) << "Differing includeSuffixes should be different";
ASSERT_FALSE(M2 == M1)
<< "Differing includeSuffixes should be different (commuted)";
}
TEST(MultilibTest, Construction1) {
Multilib M("gcc64", "os64", "inc64");
ASSERT_TRUE(M.gccSuffix() == "/gcc64");
ASSERT_TRUE(M.osSuffix() == "/os64");
ASSERT_TRUE(M.includeSuffix() == "/inc64");
}
TEST(MultilibTest, Construction2) {
Multilib M1;
Multilib M2("");
Multilib M3("", "");
Multilib M4("", "", "");
ASSERT_TRUE(M1 == M2)
<< "Default arguments to Multilib constructor broken (first argument)";
ASSERT_TRUE(M1 == M3)
<< "Default arguments to Multilib constructor broken (second argument)";
ASSERT_TRUE(M1 == M4)
<< "Default arguments to Multilib constructor broken (third argument)";
}
TEST(MultilibTest, Construction3) {
Multilib M = Multilib().flag("+f1").flag("+f2").flag("-f3");
for (Multilib::flags_list::const_iterator I = M.flags().begin(),
E = M.flags().end();
I != E; ++I) {
ASSERT_TRUE(llvm::StringSwitch<bool>(*I)
.Cases("+f1", "+f2", "-f3", true)
.Default(false));
}
}
static bool hasFlag(const Multilib &M, StringRef Flag) {
for (Multilib::flags_list::const_iterator I = M.flags().begin(),
E = M.flags().end();
I != E; ++I) {
if (*I == Flag)
return true;
else if (StringRef(*I).substr(1) == Flag.substr(1))
return false;
}
return false;
}
TEST(MultilibTest, SetConstruction1) {
// Single maybe
MultilibSet MS;
ASSERT_TRUE(MS.size() == 0);
MS.Maybe(Multilib("64").flag("+m64"));
ASSERT_TRUE(MS.size() == 2);
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
if (I->gccSuffix() == "/64")
ASSERT_TRUE(I->flags()[0] == "+m64");
else if (I->gccSuffix() == "")
ASSERT_TRUE(I->flags()[0] == "-m64");
else
FAIL() << "Unrecognized gccSufix: " << I->gccSuffix();
}
}
TEST(MultilibTest, SetConstruction2) {
// Double maybe
MultilibSet MS;
MS.Maybe(Multilib("sof").flag("+sof"));
MS.Maybe(Multilib("el").flag("+EL"));
ASSERT_TRUE(MS.size() == 4);
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
ASSERT_TRUE(I->isValid()) << "Multilb " << *I << " should be valid";
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
.Cases("", "/sof", "/el", "/sof/el", true)
.Default(false))
<< "Multilib " << *I << " wasn't expected";
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
.Case("", hasFlag(*I, "-sof"))
.Case("/sof", hasFlag(*I, "+sof"))
.Case("/el", hasFlag(*I, "-sof"))
.Case("/sof/el", hasFlag(*I, "+sof"))
.Default(false))
<< "Multilib " << *I << " didn't have the appropriate {+,-}sof flag";
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
.Case("", hasFlag(*I, "-EL"))
.Case("/sof", hasFlag(*I, "-EL"))
.Case("/el", hasFlag(*I, "+EL"))
.Case("/sof/el", hasFlag(*I, "+EL"))
.Default(false))
<< "Multilib " << *I << " didn't have the appropriate {+,-}EL flag";
}
}
TEST(MultilibTest, SetPushback) {
MultilibSet MS;
MS.push_back(Multilib("one"));
MS.push_back(Multilib("two"));
ASSERT_TRUE(MS.size() == 2);
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
.Cases("/one", "/two", true)
.Default(false));
}
MS.clear();
ASSERT_TRUE(MS.size() == 0);
}
TEST(MultilibTest, SetRegexFilter) {
MultilibSet MS;
MS.Maybe(Multilib("one"));
MS.Maybe(Multilib("two"));
MS.Maybe(Multilib("three"));
ASSERT_EQ(MS.size(), (unsigned)2 * 2 * 2)
<< "Size before filter was incorrect. Contents:\n" << MS;
MS.FilterOut("/one/two/three");
ASSERT_EQ(MS.size(), (unsigned)2 * 2 * 2 - 1)
<< "Size after filter was incorrect. Contents:\n" << MS;
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
ASSERT_TRUE(I->gccSuffix() != "/one/two/three")
<< "The filter should have removed " << *I;
}
}
TEST(MultilibTest, SetFilterObject) {
MultilibSet MS;
MS.Maybe(Multilib("orange"));
MS.Maybe(Multilib("pear"));
MS.Maybe(Multilib("plum"));
ASSERT_EQ((int)MS.size(), 1 /* Default */ +
1 /* pear */ +
1 /* plum */ +
1 /* pear/plum */ +
1 /* orange */ +
1 /* orange/pear */ +
1 /* orange/plum */ +
1 /* orange/pear/plum */ )
<< "Size before filter was incorrect. Contents:\n" << MS;
MS.FilterOut([](const Multilib &M) {
return StringRef(M.gccSuffix()).startswith("/p");
});
ASSERT_EQ((int)MS.size(), 1 /* Default */ +
1 /* orange */ +
1 /* orange/pear */ +
1 /* orange/plum */ +
1 /* orange/pear/plum */ )
<< "Size after filter was incorrect. Contents:\n" << MS;
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
ASSERT_FALSE(StringRef(I->gccSuffix()).startswith("/p"))
<< "The filter should have removed " << *I;
}
}
TEST(MultilibTest, SetSelection1) {
MultilibSet MS1 = MultilibSet()
.Maybe(Multilib("64").flag("+m64"));
Multilib::flags_list FlagM64;
FlagM64.push_back("+m64");
Multilib SelectionM64;
ASSERT_TRUE(MS1.select(FlagM64, SelectionM64))
<< "Flag set was {\"+m64\"}, but selection not found";
ASSERT_TRUE(SelectionM64.gccSuffix() == "/64")
<< "Selection picked " << SelectionM64 << " which was not expected";
Multilib::flags_list FlagNoM64;
FlagNoM64.push_back("-m64");
Multilib SelectionNoM64;
ASSERT_TRUE(MS1.select(FlagNoM64, SelectionNoM64))
<< "Flag set was {\"-m64\"}, but selection not found";
ASSERT_TRUE(SelectionNoM64.gccSuffix() == "")
<< "Selection picked " << SelectionNoM64 << " which was not expected";
}
TEST(MultilibTest, SetSelection2) {
MultilibSet MS2 = MultilibSet()
.Maybe(Multilib("el").flag("+EL"))
.Maybe(Multilib("sf").flag("+SF"));
for (unsigned I = 0; I < 4; ++I) {
bool IsEL = I & 0x1;
bool IsSF = I & 0x2;
Multilib::flags_list Flags;
if (IsEL)
Flags.push_back("+EL");
else
Flags.push_back("-EL");
if (IsSF)
Flags.push_back("+SF");
else
Flags.push_back("-SF");
Multilib Selection;
ASSERT_TRUE(MS2.select(Flags, Selection)) << "Selection failed for "
<< (IsEL ? "+EL" : "-EL") << " "
<< (IsSF ? "+SF" : "-SF");
std::string Suffix;
if (IsEL)
Suffix += "/el";
if (IsSF)
Suffix += "/sf";
ASSERT_EQ(Selection.gccSuffix(), Suffix) << "Selection picked " << Selection
<< " which was not expected ";
}
}
TEST(MultilibTest, SetCombineWith) {
MultilibSet Coffee;
Coffee.push_back(Multilib("coffee"));
MultilibSet Milk;
Milk.push_back(Multilib("milk"));
MultilibSet Latte;
ASSERT_EQ(Latte.size(), (unsigned)0);
Latte.combineWith(Coffee);
ASSERT_EQ(Latte.size(), (unsigned)1);
Latte.combineWith(Milk);
ASSERT_EQ(Latte.size(), (unsigned)2);
}

View File

@@ -0,0 +1,263 @@
//===- 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/TargetRegistry.h"
#include "llvm/Support/TargetSelect.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"}));
EXPECT_TRUE(C);
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"}));
EXPECT_TRUE(C);
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);
}
TEST(ToolChainTest, DefaultDriverMode) {
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 CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
InMemoryFileSystem);
CCDriver.setCheckInputsExist(false);
Driver CXXDriver("/home/test/bin/clang++", "arm-linux-gnueabi", Diags,
InMemoryFileSystem);
CXXDriver.setCheckInputsExist(false);
Driver CLDriver("/home/test/bin/clang-cl", "arm-linux-gnueabi", Diags,
InMemoryFileSystem);
CLDriver.setCheckInputsExist(false);
std::unique_ptr<Compilation> CC(CCDriver.BuildCompilation(
{ "/home/test/bin/clang", "foo.cpp"}));
std::unique_ptr<Compilation> CXX(CXXDriver.BuildCompilation(
{ "/home/test/bin/clang++", "foo.cpp"}));
std::unique_ptr<Compilation> CL(CLDriver.BuildCompilation(
{ "/home/test/bin/clang-cl", "foo.cpp"}));
EXPECT_TRUE(CC);
EXPECT_TRUE(CXX);
EXPECT_TRUE(CL);
EXPECT_TRUE(CCDriver.CCCIsCC());
EXPECT_TRUE(CXXDriver.CCCIsCXX());
EXPECT_TRUE(CLDriver.IsCLMode());
}
TEST(ToolChainTest, InvalidArgument) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags);
std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
{"-fsyntax-only", "-fan-unknown-option", "foo.cpp"}));
EXPECT_TRUE(C);
EXPECT_TRUE(C->containsError());
}
TEST(ToolChainTest, ParsedClangName) {
ParsedClangName Empty;
EXPECT_TRUE(Empty.TargetPrefix.empty());
EXPECT_TRUE(Empty.ModeSuffix.empty());
EXPECT_TRUE(Empty.DriverMode == nullptr);
EXPECT_FALSE(Empty.TargetIsValid);
ParsedClangName DriverOnly("clang", nullptr);
EXPECT_TRUE(DriverOnly.TargetPrefix.empty());
EXPECT_TRUE(DriverOnly.ModeSuffix == "clang");
EXPECT_TRUE(DriverOnly.DriverMode == nullptr);
EXPECT_FALSE(DriverOnly.TargetIsValid);
ParsedClangName DriverOnly2("clang++", "--driver-mode=g++");
EXPECT_TRUE(DriverOnly2.TargetPrefix.empty());
EXPECT_TRUE(DriverOnly2.ModeSuffix == "clang++");
EXPECT_STREQ(DriverOnly2.DriverMode, "--driver-mode=g++");
EXPECT_FALSE(DriverOnly2.TargetIsValid);
ParsedClangName TargetAndMode("i386", "clang-g++", "--driver-mode=g++", true);
EXPECT_TRUE(TargetAndMode.TargetPrefix == "i386");
EXPECT_TRUE(TargetAndMode.ModeSuffix == "clang-g++");
EXPECT_STREQ(TargetAndMode.DriverMode, "--driver-mode=g++");
EXPECT_TRUE(TargetAndMode.TargetIsValid);
}
TEST(ToolChainTest, GetTargetAndMode) {
llvm::InitializeAllTargets();
std::string IgnoredError;
if (!llvm::TargetRegistry::lookupTarget("x86_64", IgnoredError))
return;
ParsedClangName Res = ToolChain::getTargetAndModeFromProgramName("clang");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix == "clang");
EXPECT_TRUE(Res.DriverMode == nullptr);
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("clang++");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix == "clang++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("clang++6.0");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix == "clang++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("clang++-release");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix == "clang++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("x86_64-clang++");
EXPECT_TRUE(Res.TargetPrefix == "x86_64");
EXPECT_TRUE(Res.ModeSuffix == "clang++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_TRUE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName(
"x86_64-linux-gnu-clang-c++");
EXPECT_TRUE(Res.TargetPrefix == "x86_64-linux-gnu");
EXPECT_TRUE(Res.ModeSuffix == "clang-c++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_TRUE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName(
"x86_64-linux-gnu-clang-c++-tot");
EXPECT_TRUE(Res.TargetPrefix == "x86_64-linux-gnu");
EXPECT_TRUE(Res.ModeSuffix == "clang-c++");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=g++");
EXPECT_TRUE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("qqq");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix.empty());
EXPECT_TRUE(Res.DriverMode == nullptr);
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("x86_64-qqq");
EXPECT_TRUE(Res.TargetPrefix.empty());
EXPECT_TRUE(Res.ModeSuffix.empty());
EXPECT_TRUE(Res.DriverMode == nullptr);
EXPECT_FALSE(Res.TargetIsValid);
Res = ToolChain::getTargetAndModeFromProgramName("qqq-clang-cl");
EXPECT_TRUE(Res.TargetPrefix == "qqq");
EXPECT_TRUE(Res.ModeSuffix == "clang-cl");
EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl");
EXPECT_FALSE(Res.TargetIsValid);
}
} // end anonymous namespace.