diff options
Diffstat (limited to 'unittests/Transforms/Utils/SpecialCaseList.cpp')
-rw-r--r-- | unittests/Transforms/Utils/SpecialCaseList.cpp | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp index 9deee3c..07ac908 100644 --- a/unittests/Transforms/Utils/SpecialCaseList.cpp +++ b/unittests/Transforms/Utils/SpecialCaseList.cpp @@ -34,9 +34,22 @@ protected: M, ST, false, GlobalValue::ExternalLinkage, 0, Name); } - SpecialCaseList *makeSpecialCaseList(StringRef List) { + GlobalAlias *makeAlias(StringRef Name, GlobalValue *Aliasee) { + return new GlobalAlias(Aliasee->getType(), GlobalValue::ExternalLinkage, + Name, Aliasee, Aliasee->getParent()); + } + + SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { OwningPtr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List)); - return new SpecialCaseList(MB.get()); + return SpecialCaseList::create(MB.get(), Error); + } + + SpecialCaseList *makeSpecialCaseList(StringRef List) { + std::string Error; + SpecialCaseList *SCL = makeSpecialCaseList(List, Error); + assert(SCL); + assert(Error == ""); + return SCL; } LLVMContext Ctx; @@ -86,8 +99,6 @@ TEST_F(SpecialCaseListTest, FunctionIsIn) { SCL.reset(makeSpecialCaseList("fun:foo=functional\n")); EXPECT_TRUE(SCL->isIn(*Foo, "functional")); StringRef Category; - EXPECT_TRUE(SCL->findCategory(*Foo, Category)); - EXPECT_EQ("functional", Category); EXPECT_FALSE(SCL->isIn(*Bar, "functional")); } @@ -139,10 +150,48 @@ TEST_F(SpecialCaseListTest, GlobalIsIn) { EXPECT_TRUE(SCL->isIn(*Bar, "init")); } +TEST_F(SpecialCaseListTest, AliasIsIn) { + Module M("hello", Ctx); + Function *Foo = makeFunction("foo", M); + GlobalVariable *Bar = makeGlobal("bar", "t", M); + GlobalAlias *FooAlias = makeAlias("fooalias", Foo); + GlobalAlias *BarAlias = makeAlias("baralias", Bar); + + OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("fun:foo\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias)); + EXPECT_FALSE(SCL->isIn(*BarAlias)); + + SCL.reset(makeSpecialCaseList("global:bar\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias)); + EXPECT_FALSE(SCL->isIn(*BarAlias)); + + SCL.reset(makeSpecialCaseList("global:fooalias\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias)); + EXPECT_FALSE(SCL->isIn(*BarAlias)); + + SCL.reset(makeSpecialCaseList("fun:fooalias\n")); + EXPECT_TRUE(SCL->isIn(*FooAlias)); + EXPECT_FALSE(SCL->isIn(*BarAlias)); + + SCL.reset(makeSpecialCaseList("global:baralias=init\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); + EXPECT_TRUE(SCL->isIn(*BarAlias, "init")); + + SCL.reset(makeSpecialCaseList("type:t=init\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); + EXPECT_TRUE(SCL->isIn(*BarAlias, "init")); + + SCL.reset(makeSpecialCaseList("fun:baralias=init\n")); + EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); + EXPECT_FALSE(SCL->isIn(*BarAlias, "init")); +} + TEST_F(SpecialCaseListTest, Substring) { Module M("othello", Ctx); Function *F = makeFunction("tomfoolery", M); GlobalVariable *GV = makeGlobal("bartender", "t", M); + GlobalAlias *GA1 = makeAlias("buffoonery", F); + GlobalAlias *GA2 = makeAlias("foobar", GV); OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n" "fun:foo\n" @@ -150,9 +199,34 @@ TEST_F(SpecialCaseListTest, Substring) { EXPECT_FALSE(SCL->isIn(M)); EXPECT_FALSE(SCL->isIn(*F)); EXPECT_FALSE(SCL->isIn(*GV)); + EXPECT_FALSE(SCL->isIn(*GA1)); + EXPECT_FALSE(SCL->isIn(*GA2)); SCL.reset(makeSpecialCaseList("fun:*foo*\n")); EXPECT_TRUE(SCL->isIn(*F)); + EXPECT_TRUE(SCL->isIn(*GA1)); +} + +TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { + std::string Error; + EXPECT_EQ(0, makeSpecialCaseList("badline", Error)); + EXPECT_EQ("Malformed line 1: 'badline'", Error); + EXPECT_EQ(0, makeSpecialCaseList("src:bad[a-", Error)); + EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", + Error); + EXPECT_EQ(0, makeSpecialCaseList("src:a.c\n" + "fun:fun(a\n", + Error)); + EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", + Error); + EXPECT_EQ(0, SpecialCaseList::create("unexisting", Error)); + EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':")); +} + +TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { + OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("")); + Module M("foo", Ctx); + EXPECT_FALSE(SCL->isIn(M)); } } |