summaryrefslogtreecommitdiffstats
path: root/unittests/Transforms
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-07-09 22:03:12 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-07-09 22:03:12 +0000
commitc7087f8e423c8f3eda453d7fc3843191dac4143b (patch)
treedc18ec6d641b7563c997ba67637570b65baefe5a /unittests/Transforms
parentc5afb9ed5eb9aeb3eff5158e15844705e8a9ee2d (diff)
downloadexternal_llvm-c7087f8e423c8f3eda453d7fc3843191dac4143b.zip
external_llvm-c7087f8e423c8f3eda453d7fc3843191dac4143b.tar.gz
external_llvm-c7087f8e423c8f3eda453d7fc3843191dac4143b.tar.bz2
Add some SpecialCaseList unit tests.
Differential Revision: http://llvm-reviews.chandlerc.com/D1091 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms')
-rw-r--r--unittests/Transforms/Utils/CMakeLists.txt1
-rw-r--r--unittests/Transforms/Utils/SpecialCaseList.cpp117
2 files changed, 118 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/CMakeLists.txt b/unittests/Transforms/Utils/CMakeLists.txt
index 730d83b..0656390 100644
--- a/unittests/Transforms/Utils/CMakeLists.txt
+++ b/unittests/Transforms/Utils/CMakeLists.txt
@@ -6,4 +6,5 @@ add_llvm_unittest(UtilsTests
Cloning.cpp
IntegerDivision.cpp
Local.cpp
+ SpecialCaseList.cpp
)
diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp
new file mode 100644
index 0000000..1c10317
--- /dev/null
+++ b/unittests/Transforms/Utils/SpecialCaseList.cpp
@@ -0,0 +1,117 @@
+//===- SpecialCaseList.cpp - Unit tests for SpecialCaseList ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/Function.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Transforms/Utils/SpecialCaseList.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+class SpecialCaseListTest : public ::testing::Test {
+protected:
+ Function *makeFunction(StringRef Name, Module &M) {
+ return Function::Create(FunctionType::get(Type::getVoidTy(Ctx), false),
+ GlobalValue::ExternalLinkage,
+ Name,
+ &M);
+ }
+
+ GlobalVariable *makeGlobal(StringRef Name, StringRef StructName, Module &M) {
+ StructType *ST =
+ StructType::create(StructName, Type::getInt32Ty(Ctx), (Type*)0);
+ return new GlobalVariable(
+ M, ST, false, GlobalValue::ExternalLinkage, 0, Name);
+ }
+
+ SpecialCaseList *makeSpecialCaseList(StringRef List) {
+ OwningPtr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List));
+ return new SpecialCaseList(MB.get());
+ }
+
+ LLVMContext Ctx;
+};
+
+TEST_F(SpecialCaseListTest, ModuleIsIn) {
+ Module M("hello", Ctx);
+ Function *F = makeFunction("foo", M);
+ GlobalVariable *GV = makeGlobal("bar", "t", M);
+
+ OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("# This is a comment.\n"
+ "\n"
+ "src:hello\n"));
+ EXPECT_TRUE(SCL->isIn(M));
+ EXPECT_TRUE(SCL->isIn(*F));
+ EXPECT_TRUE(SCL->isIn(*GV));
+
+ SCL.reset(makeSpecialCaseList("src:he*o\n"));
+ EXPECT_TRUE(SCL->isIn(M));
+ EXPECT_TRUE(SCL->isIn(*F));
+ EXPECT_TRUE(SCL->isIn(*GV));
+
+ SCL.reset(makeSpecialCaseList("src:hi\n"));
+ EXPECT_FALSE(SCL->isIn(M));
+ EXPECT_FALSE(SCL->isIn(*F));
+ EXPECT_FALSE(SCL->isIn(*GV));
+}
+
+TEST_F(SpecialCaseListTest, FunctionIsIn) {
+ Module M("hello", Ctx);
+ Function *Foo = makeFunction("foo", M);
+ Function *Bar = makeFunction("bar", M);
+
+ OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("fun:foo\n"));
+ EXPECT_TRUE(SCL->isIn(*Foo));
+ EXPECT_FALSE(SCL->isIn(*Bar));
+
+ SCL.reset(makeSpecialCaseList("fun:b*\n"));
+ EXPECT_FALSE(SCL->isIn(*Foo));
+ EXPECT_TRUE(SCL->isIn(*Bar));
+
+ SCL.reset(makeSpecialCaseList("fun:f*\n"
+ "fun:bar\n"));
+ EXPECT_TRUE(SCL->isIn(*Foo));
+ EXPECT_TRUE(SCL->isIn(*Bar));
+}
+
+TEST_F(SpecialCaseListTest, GlobalIsIn) {
+ Module M("hello", Ctx);
+ GlobalVariable *Foo = makeGlobal("foo", "t1", M);
+ GlobalVariable *Bar = makeGlobal("bar", "t2", M);
+
+ OwningPtr<SpecialCaseList> SCL(makeSpecialCaseList("global:foo\n"));
+ EXPECT_TRUE(SCL->isIn(*Foo));
+ EXPECT_FALSE(SCL->isIn(*Bar));
+ EXPECT_FALSE(SCL->isInInit(*Foo));
+ EXPECT_FALSE(SCL->isInInit(*Bar));
+
+ SCL.reset(makeSpecialCaseList("global-init:foo\n"));
+ EXPECT_FALSE(SCL->isIn(*Foo));
+ EXPECT_FALSE(SCL->isIn(*Bar));
+ EXPECT_TRUE(SCL->isInInit(*Foo));
+ EXPECT_FALSE(SCL->isInInit(*Bar));
+
+ SCL.reset(makeSpecialCaseList("global-init-type:t2\n"));
+ EXPECT_FALSE(SCL->isIn(*Foo));
+ EXPECT_FALSE(SCL->isIn(*Bar));
+ EXPECT_FALSE(SCL->isInInit(*Foo));
+ EXPECT_TRUE(SCL->isInInit(*Bar));
+
+ SCL.reset(makeSpecialCaseList("global-init-src:hello\n"));
+ EXPECT_FALSE(SCL->isIn(*Foo));
+ EXPECT_FALSE(SCL->isIn(*Bar));
+ EXPECT_TRUE(SCL->isInInit(*Foo));
+ EXPECT_TRUE(SCL->isInInit(*Bar));
+}
+
+}