1*0a6a1f1dSLionel Sambuc //===- unittests/Driver/MultilibTest.cpp --- Multilib tests ---------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc //
10*0a6a1f1dSLionel Sambuc // Unit tests for Multilib and MultilibSet
11*0a6a1f1dSLionel Sambuc //
12*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
13*0a6a1f1dSLionel Sambuc
14*0a6a1f1dSLionel Sambuc #include "clang/Driver/Multilib.h"
15*0a6a1f1dSLionel Sambuc #include "clang/Basic/LLVM.h"
16*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringRef.h"
17*0a6a1f1dSLionel Sambuc #include "llvm/ADT/StringSwitch.h"
18*0a6a1f1dSLionel Sambuc #include "gtest/gtest.h"
19*0a6a1f1dSLionel Sambuc
20*0a6a1f1dSLionel Sambuc using namespace clang::driver;
21*0a6a1f1dSLionel Sambuc using namespace clang;
22*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,MultilibValidity)23*0a6a1f1dSLionel Sambuc TEST(MultilibTest, MultilibValidity) {
24*0a6a1f1dSLionel Sambuc
25*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib().isValid()) << "Empty multilib is not valid";
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib().flag("+foo").isValid())
28*0a6a1f1dSLionel Sambuc << "Single indicative flag is not valid";
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib().flag("-foo").isValid())
31*0a6a1f1dSLionel Sambuc << "Single contraindicative flag is not valid";
32*0a6a1f1dSLionel Sambuc
33*0a6a1f1dSLionel Sambuc ASSERT_FALSE(Multilib().flag("+foo").flag("-foo").isValid())
34*0a6a1f1dSLionel Sambuc << "Conflicting flags should invalidate the Multilib";
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib().flag("+foo").flag("+foo").isValid())
37*0a6a1f1dSLionel Sambuc << "Multilib should be valid even if it has the same flag twice";
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib().flag("+foo").flag("-foobar").isValid())
40*0a6a1f1dSLionel Sambuc << "Seemingly conflicting prefixes shouldn't actually conflict";
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqReflexivity1)43*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqReflexivity1) {
44*0a6a1f1dSLionel Sambuc Multilib M;
45*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M == M) << "Multilib::operator==() is not reflexive";
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqReflexivity2)48*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqReflexivity2) {
49*0a6a1f1dSLionel Sambuc ASSERT_TRUE(Multilib() == Multilib())
50*0a6a1f1dSLionel Sambuc << "Separately constructed default multilibs are not equal";
51*0a6a1f1dSLionel Sambuc }
52*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqReflexivity3)53*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqReflexivity3) {
54*0a6a1f1dSLionel Sambuc Multilib M1, M2;
55*0a6a1f1dSLionel Sambuc M1.flag("+foo");
56*0a6a1f1dSLionel Sambuc M2.flag("+foo");
57*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqInequivalence1)60*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqInequivalence1) {
61*0a6a1f1dSLionel Sambuc Multilib M1, M2;
62*0a6a1f1dSLionel Sambuc M1.flag("+foo");
63*0a6a1f1dSLionel Sambuc M2.flag("-foo");
64*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
65*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M2 == M1)
66*0a6a1f1dSLionel Sambuc << "Multilibs with conflicting flags are not the same (commuted)";
67*0a6a1f1dSLionel Sambuc }
68*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqInequivalence2)69*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqInequivalence2) {
70*0a6a1f1dSLionel Sambuc Multilib M1, M2;
71*0a6a1f1dSLionel Sambuc M2.flag("+foo");
72*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
73*0a6a1f1dSLionel Sambuc }
74*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqEquivalence1)75*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqEquivalence1) {
76*0a6a1f1dSLionel Sambuc Multilib M1, M2;
77*0a6a1f1dSLionel Sambuc M1.flag("+foo");
78*0a6a1f1dSLionel Sambuc M2.flag("+foo").flag("+foo");
79*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2) << "Flag duplication shouldn't affect equivalence";
80*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M2 == M1)
81*0a6a1f1dSLionel Sambuc << "Flag duplication shouldn't affect equivalence (commuted)";
82*0a6a1f1dSLionel Sambuc }
83*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqEquivalence2)84*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqEquivalence2) {
85*0a6a1f1dSLionel Sambuc Multilib M1("64");
86*0a6a1f1dSLionel Sambuc Multilib M2;
87*0a6a1f1dSLionel Sambuc M2.gccSuffix("/64");
88*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2)
89*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::gccSuffix()";
90*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M2 == M1)
91*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::gccSuffix() (commuted)";
92*0a6a1f1dSLionel Sambuc }
93*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqEquivalence3)94*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqEquivalence3) {
95*0a6a1f1dSLionel Sambuc Multilib M1("", "32");
96*0a6a1f1dSLionel Sambuc Multilib M2;
97*0a6a1f1dSLionel Sambuc M2.osSuffix("/32");
98*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2)
99*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::osSuffix()";
100*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M2 == M1)
101*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::osSuffix() (commuted)";
102*0a6a1f1dSLionel Sambuc }
103*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqEquivalence4)104*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqEquivalence4) {
105*0a6a1f1dSLionel Sambuc Multilib M1("", "", "16");
106*0a6a1f1dSLionel Sambuc Multilib M2;
107*0a6a1f1dSLionel Sambuc M2.includeSuffix("/16");
108*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2)
109*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::includeSuffix()";
110*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M2 == M1)
111*0a6a1f1dSLionel Sambuc << "Constructor argument must match Multilib::includeSuffix() (commuted)";
112*0a6a1f1dSLionel Sambuc }
113*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqInequivalence3)114*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqInequivalence3) {
115*0a6a1f1dSLionel Sambuc Multilib M1("foo");
116*0a6a1f1dSLionel Sambuc Multilib M2("bar");
117*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M1 == M2) << "Differing gccSuffixes should be different";
118*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M2 == M1)
119*0a6a1f1dSLionel Sambuc << "Differing gccSuffixes should be different (commuted)";
120*0a6a1f1dSLionel Sambuc }
121*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqInequivalence4)122*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqInequivalence4) {
123*0a6a1f1dSLionel Sambuc Multilib M1("", "foo");
124*0a6a1f1dSLionel Sambuc Multilib M2("", "bar");
125*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M1 == M2) << "Differing osSuffixes should be different";
126*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M2 == M1)
127*0a6a1f1dSLionel Sambuc << "Differing osSuffixes should be different (commuted)";
128*0a6a1f1dSLionel Sambuc }
129*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,OpEqInequivalence5)130*0a6a1f1dSLionel Sambuc TEST(MultilibTest, OpEqInequivalence5) {
131*0a6a1f1dSLionel Sambuc Multilib M1("", "", "foo");
132*0a6a1f1dSLionel Sambuc Multilib M2("", "", "bar");
133*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M1 == M2) << "Differing includeSuffixes should be different";
134*0a6a1f1dSLionel Sambuc ASSERT_FALSE(M2 == M1)
135*0a6a1f1dSLionel Sambuc << "Differing includeSuffixes should be different (commuted)";
136*0a6a1f1dSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,Construction1)138*0a6a1f1dSLionel Sambuc TEST(MultilibTest, Construction1) {
139*0a6a1f1dSLionel Sambuc Multilib M("gcc64", "os64", "inc64");
140*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M.gccSuffix() == "/gcc64");
141*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M.osSuffix() == "/os64");
142*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M.includeSuffix() == "/inc64");
143*0a6a1f1dSLionel Sambuc }
144*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,Construction2)145*0a6a1f1dSLionel Sambuc TEST(MultilibTest, Construction2) {
146*0a6a1f1dSLionel Sambuc Multilib M1;
147*0a6a1f1dSLionel Sambuc Multilib M2("");
148*0a6a1f1dSLionel Sambuc Multilib M3("", "");
149*0a6a1f1dSLionel Sambuc Multilib M4("", "", "");
150*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M2)
151*0a6a1f1dSLionel Sambuc << "Default arguments to Multilib constructor broken (first argument)";
152*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M3)
153*0a6a1f1dSLionel Sambuc << "Default arguments to Multilib constructor broken (second argument)";
154*0a6a1f1dSLionel Sambuc ASSERT_TRUE(M1 == M4)
155*0a6a1f1dSLionel Sambuc << "Default arguments to Multilib constructor broken (third argument)";
156*0a6a1f1dSLionel Sambuc }
157*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,Construction3)158*0a6a1f1dSLionel Sambuc TEST(MultilibTest, Construction3) {
159*0a6a1f1dSLionel Sambuc Multilib M = Multilib().flag("+f1").flag("+f2").flag("-f3");
160*0a6a1f1dSLionel Sambuc for (Multilib::flags_list::const_iterator I = M.flags().begin(),
161*0a6a1f1dSLionel Sambuc E = M.flags().end();
162*0a6a1f1dSLionel Sambuc I != E; ++I) {
163*0a6a1f1dSLionel Sambuc ASSERT_TRUE(llvm::StringSwitch<bool>(*I)
164*0a6a1f1dSLionel Sambuc .Cases("+f1", "+f2", "-f3", true)
165*0a6a1f1dSLionel Sambuc .Default(false));
166*0a6a1f1dSLionel Sambuc }
167*0a6a1f1dSLionel Sambuc }
168*0a6a1f1dSLionel Sambuc
hasFlag(const Multilib & M,StringRef Flag)169*0a6a1f1dSLionel Sambuc static bool hasFlag(const Multilib &M, StringRef Flag) {
170*0a6a1f1dSLionel Sambuc for (Multilib::flags_list::const_iterator I = M.flags().begin(),
171*0a6a1f1dSLionel Sambuc E = M.flags().end();
172*0a6a1f1dSLionel Sambuc I != E; ++I) {
173*0a6a1f1dSLionel Sambuc if (*I == Flag)
174*0a6a1f1dSLionel Sambuc return true;
175*0a6a1f1dSLionel Sambuc else if (StringRef(*I).substr(1) == Flag.substr(1))
176*0a6a1f1dSLionel Sambuc return false;
177*0a6a1f1dSLionel Sambuc }
178*0a6a1f1dSLionel Sambuc return false;
179*0a6a1f1dSLionel Sambuc }
180*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetConstruction1)181*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetConstruction1) {
182*0a6a1f1dSLionel Sambuc // Single maybe
183*0a6a1f1dSLionel Sambuc MultilibSet MS;
184*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS.size() == 0);
185*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("64").flag("+m64"));
186*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS.size() == 2);
187*0a6a1f1dSLionel Sambuc for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
188*0a6a1f1dSLionel Sambuc if (I->gccSuffix() == "/64")
189*0a6a1f1dSLionel Sambuc ASSERT_TRUE(I->flags()[0] == "+m64");
190*0a6a1f1dSLionel Sambuc else if (I->gccSuffix() == "")
191*0a6a1f1dSLionel Sambuc ASSERT_TRUE(I->flags()[0] == "-m64");
192*0a6a1f1dSLionel Sambuc else
193*0a6a1f1dSLionel Sambuc FAIL() << "Unrecognized gccSufix: " << I->gccSuffix();
194*0a6a1f1dSLionel Sambuc }
195*0a6a1f1dSLionel Sambuc }
196*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetConstruction2)197*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetConstruction2) {
198*0a6a1f1dSLionel Sambuc // Double maybe
199*0a6a1f1dSLionel Sambuc MultilibSet MS;
200*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("sof").flag("+sof"));
201*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("el").flag("+EL"));
202*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS.size() == 4);
203*0a6a1f1dSLionel Sambuc for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
204*0a6a1f1dSLionel Sambuc ASSERT_TRUE(I->isValid()) << "Multilb " << *I << " should be valid";
205*0a6a1f1dSLionel Sambuc ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
206*0a6a1f1dSLionel Sambuc .Cases("", "/sof", "/el", "/sof/el", true)
207*0a6a1f1dSLionel Sambuc .Default(false))
208*0a6a1f1dSLionel Sambuc << "Multilib " << *I << " wasn't expected";
209*0a6a1f1dSLionel Sambuc ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
210*0a6a1f1dSLionel Sambuc .Case("", hasFlag(*I, "-sof"))
211*0a6a1f1dSLionel Sambuc .Case("/sof", hasFlag(*I, "+sof"))
212*0a6a1f1dSLionel Sambuc .Case("/el", hasFlag(*I, "-sof"))
213*0a6a1f1dSLionel Sambuc .Case("/sof/el", hasFlag(*I, "+sof"))
214*0a6a1f1dSLionel Sambuc .Default(false))
215*0a6a1f1dSLionel Sambuc << "Multilib " << *I << " didn't have the appropriate {+,-}sof flag";
216*0a6a1f1dSLionel Sambuc ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
217*0a6a1f1dSLionel Sambuc .Case("", hasFlag(*I, "-EL"))
218*0a6a1f1dSLionel Sambuc .Case("/sof", hasFlag(*I, "-EL"))
219*0a6a1f1dSLionel Sambuc .Case("/el", hasFlag(*I, "+EL"))
220*0a6a1f1dSLionel Sambuc .Case("/sof/el", hasFlag(*I, "+EL"))
221*0a6a1f1dSLionel Sambuc .Default(false))
222*0a6a1f1dSLionel Sambuc << "Multilib " << *I << " didn't have the appropriate {+,-}EL flag";
223*0a6a1f1dSLionel Sambuc }
224*0a6a1f1dSLionel Sambuc }
225*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetPushback)226*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetPushback) {
227*0a6a1f1dSLionel Sambuc MultilibSet MS;
228*0a6a1f1dSLionel Sambuc MS.push_back(Multilib("one"));
229*0a6a1f1dSLionel Sambuc MS.push_back(Multilib("two"));
230*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS.size() == 2);
231*0a6a1f1dSLionel Sambuc for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
232*0a6a1f1dSLionel Sambuc ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
233*0a6a1f1dSLionel Sambuc .Cases("/one", "/two", true)
234*0a6a1f1dSLionel Sambuc .Default(false));
235*0a6a1f1dSLionel Sambuc }
236*0a6a1f1dSLionel Sambuc MS.clear();
237*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS.size() == 0);
238*0a6a1f1dSLionel Sambuc }
239*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetRegexFilter)240*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetRegexFilter) {
241*0a6a1f1dSLionel Sambuc MultilibSet MS;
242*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("one"));
243*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("two"));
244*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("three"));
245*0a6a1f1dSLionel Sambuc ASSERT_EQ(MS.size(), (unsigned)2 * 2 * 2)
246*0a6a1f1dSLionel Sambuc << "Size before filter was incorrect. Contents:\n" << MS;
247*0a6a1f1dSLionel Sambuc MS.FilterOut("/one/two/three");
248*0a6a1f1dSLionel Sambuc ASSERT_EQ(MS.size(), (unsigned)2 * 2 * 2 - 1)
249*0a6a1f1dSLionel Sambuc << "Size after filter was incorrect. Contents:\n" << MS;
250*0a6a1f1dSLionel Sambuc for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
251*0a6a1f1dSLionel Sambuc ASSERT_TRUE(I->gccSuffix() != "/one/two/three")
252*0a6a1f1dSLionel Sambuc << "The filter should have removed " << *I;
253*0a6a1f1dSLionel Sambuc }
254*0a6a1f1dSLionel Sambuc }
255*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetFilterObject)256*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetFilterObject) {
257*0a6a1f1dSLionel Sambuc // Filter object
258*0a6a1f1dSLionel Sambuc struct StartsWithP : public MultilibSet::FilterCallback {
259*0a6a1f1dSLionel Sambuc bool operator()(const Multilib &M) const override {
260*0a6a1f1dSLionel Sambuc return StringRef(M.gccSuffix()).startswith("/p");
261*0a6a1f1dSLionel Sambuc }
262*0a6a1f1dSLionel Sambuc };
263*0a6a1f1dSLionel Sambuc MultilibSet MS;
264*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("orange"));
265*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("pear"));
266*0a6a1f1dSLionel Sambuc MS.Maybe(Multilib("plum"));
267*0a6a1f1dSLionel Sambuc ASSERT_EQ((int)MS.size(), 1 /* Default */ +
268*0a6a1f1dSLionel Sambuc 1 /* pear */ +
269*0a6a1f1dSLionel Sambuc 1 /* plum */ +
270*0a6a1f1dSLionel Sambuc 1 /* pear/plum */ +
271*0a6a1f1dSLionel Sambuc 1 /* orange */ +
272*0a6a1f1dSLionel Sambuc 1 /* orange/pear */ +
273*0a6a1f1dSLionel Sambuc 1 /* orange/plum */ +
274*0a6a1f1dSLionel Sambuc 1 /* orange/pear/plum */ )
275*0a6a1f1dSLionel Sambuc << "Size before filter was incorrect. Contents:\n" << MS;
276*0a6a1f1dSLionel Sambuc MS.FilterOut(StartsWithP());
277*0a6a1f1dSLionel Sambuc ASSERT_EQ((int)MS.size(), 1 /* Default */ +
278*0a6a1f1dSLionel Sambuc 1 /* orange */ +
279*0a6a1f1dSLionel Sambuc 1 /* orange/pear */ +
280*0a6a1f1dSLionel Sambuc 1 /* orange/plum */ +
281*0a6a1f1dSLionel Sambuc 1 /* orange/pear/plum */ )
282*0a6a1f1dSLionel Sambuc << "Size after filter was incorrect. Contents:\n" << MS;
283*0a6a1f1dSLionel Sambuc for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
284*0a6a1f1dSLionel Sambuc ASSERT_FALSE(StringRef(I->gccSuffix()).startswith("/p"))
285*0a6a1f1dSLionel Sambuc << "The filter should have removed " << *I;
286*0a6a1f1dSLionel Sambuc }
287*0a6a1f1dSLionel Sambuc }
288*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetSelection1)289*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetSelection1) {
290*0a6a1f1dSLionel Sambuc MultilibSet MS1 = MultilibSet()
291*0a6a1f1dSLionel Sambuc .Maybe(Multilib("64").flag("+m64"));
292*0a6a1f1dSLionel Sambuc
293*0a6a1f1dSLionel Sambuc Multilib::flags_list FlagM64;
294*0a6a1f1dSLionel Sambuc FlagM64.push_back("+m64");
295*0a6a1f1dSLionel Sambuc Multilib SelectionM64;
296*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS1.select(FlagM64, SelectionM64))
297*0a6a1f1dSLionel Sambuc << "Flag set was {\"+m64\"}, but selection not found";
298*0a6a1f1dSLionel Sambuc ASSERT_TRUE(SelectionM64.gccSuffix() == "/64")
299*0a6a1f1dSLionel Sambuc << "Selection picked " << SelectionM64 << " which was not expected";
300*0a6a1f1dSLionel Sambuc
301*0a6a1f1dSLionel Sambuc Multilib::flags_list FlagNoM64;
302*0a6a1f1dSLionel Sambuc FlagNoM64.push_back("-m64");
303*0a6a1f1dSLionel Sambuc Multilib SelectionNoM64;
304*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS1.select(FlagNoM64, SelectionNoM64))
305*0a6a1f1dSLionel Sambuc << "Flag set was {\"-m64\"}, but selection not found";
306*0a6a1f1dSLionel Sambuc ASSERT_TRUE(SelectionNoM64.gccSuffix() == "")
307*0a6a1f1dSLionel Sambuc << "Selection picked " << SelectionNoM64 << " which was not expected";
308*0a6a1f1dSLionel Sambuc }
309*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetSelection2)310*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetSelection2) {
311*0a6a1f1dSLionel Sambuc MultilibSet MS2 = MultilibSet()
312*0a6a1f1dSLionel Sambuc .Maybe(Multilib("el").flag("+EL"))
313*0a6a1f1dSLionel Sambuc .Maybe(Multilib("sf").flag("+SF"));
314*0a6a1f1dSLionel Sambuc
315*0a6a1f1dSLionel Sambuc for (unsigned I = 0; I < 4; ++I) {
316*0a6a1f1dSLionel Sambuc bool IsEL = I & 0x1;
317*0a6a1f1dSLionel Sambuc bool IsSF = I & 0x2;
318*0a6a1f1dSLionel Sambuc Multilib::flags_list Flags;
319*0a6a1f1dSLionel Sambuc if (IsEL)
320*0a6a1f1dSLionel Sambuc Flags.push_back("+EL");
321*0a6a1f1dSLionel Sambuc else
322*0a6a1f1dSLionel Sambuc Flags.push_back("-EL");
323*0a6a1f1dSLionel Sambuc
324*0a6a1f1dSLionel Sambuc if (IsSF)
325*0a6a1f1dSLionel Sambuc Flags.push_back("+SF");
326*0a6a1f1dSLionel Sambuc else
327*0a6a1f1dSLionel Sambuc Flags.push_back("-SF");
328*0a6a1f1dSLionel Sambuc
329*0a6a1f1dSLionel Sambuc Multilib Selection;
330*0a6a1f1dSLionel Sambuc ASSERT_TRUE(MS2.select(Flags, Selection)) << "Selection failed for "
331*0a6a1f1dSLionel Sambuc << (IsEL ? "+EL" : "-EL") << " "
332*0a6a1f1dSLionel Sambuc << (IsSF ? "+SF" : "-SF");
333*0a6a1f1dSLionel Sambuc
334*0a6a1f1dSLionel Sambuc std::string Suffix;
335*0a6a1f1dSLionel Sambuc if (IsEL)
336*0a6a1f1dSLionel Sambuc Suffix += "/el";
337*0a6a1f1dSLionel Sambuc if (IsSF)
338*0a6a1f1dSLionel Sambuc Suffix += "/sf";
339*0a6a1f1dSLionel Sambuc
340*0a6a1f1dSLionel Sambuc ASSERT_EQ(Selection.gccSuffix(), Suffix) << "Selection picked " << Selection
341*0a6a1f1dSLionel Sambuc << " which was not expected ";
342*0a6a1f1dSLionel Sambuc }
343*0a6a1f1dSLionel Sambuc }
344*0a6a1f1dSLionel Sambuc
TEST(MultilibTest,SetCombineWith)345*0a6a1f1dSLionel Sambuc TEST(MultilibTest, SetCombineWith) {
346*0a6a1f1dSLionel Sambuc MultilibSet Coffee;
347*0a6a1f1dSLionel Sambuc Coffee.push_back(Multilib("coffee"));
348*0a6a1f1dSLionel Sambuc MultilibSet Milk;
349*0a6a1f1dSLionel Sambuc Milk.push_back(Multilib("milk"));
350*0a6a1f1dSLionel Sambuc MultilibSet Latte;
351*0a6a1f1dSLionel Sambuc ASSERT_EQ(Latte.size(), (unsigned)0);
352*0a6a1f1dSLionel Sambuc Latte.combineWith(Coffee);
353*0a6a1f1dSLionel Sambuc ASSERT_EQ(Latte.size(), (unsigned)1);
354*0a6a1f1dSLionel Sambuc Latte.combineWith(Milk);
355*0a6a1f1dSLionel Sambuc ASSERT_EQ(Latte.size(), (unsigned)2);
356*0a6a1f1dSLionel Sambuc }
357