diff options
author | Gabor Greif <ggreif@gmail.com> | 2012-11-12 10:01:17 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2012-11-12 10:01:17 +0000 |
commit | fea6a551a96a5c79e14cb026fab1544b9cc54d27 (patch) | |
tree | 4826d740d30a0c93b1ce7d2fbb29e8272f0e9db3 /llvm/unittests | |
parent | 166311301c8c83060090d9390887e5d58f25638f (diff) | |
download | bcm5719-llvm-fea6a551a96a5c79e14cb026fab1544b9cc54d27.tar.gz bcm5719-llvm-fea6a551a96a5c79e14cb026fab1544b9cc54d27.zip |
add unit test for waymarking algorithm (Use::getUser)
llvm-svn: 167720
Diffstat (limited to 'llvm/unittests')
-rw-r--r-- | llvm/unittests/VMCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/VMCore/WaymarkTest.cpp | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/llvm/unittests/VMCore/CMakeLists.txt b/llvm/unittests/VMCore/CMakeLists.txt index 4025c7a91fb..8d8bb3bb4d9 100644 --- a/llvm/unittests/VMCore/CMakeLists.txt +++ b/llvm/unittests/VMCore/CMakeLists.txt @@ -16,6 +16,7 @@ set(VMCoreSources TypesTest.cpp ValueMapTest.cpp VerifierTest.cpp + WaymarkTest.cpp ) # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug. diff --git a/llvm/unittests/VMCore/WaymarkTest.cpp b/llvm/unittests/VMCore/WaymarkTest.cpp new file mode 100644 index 00000000000..41228c90f9a --- /dev/null +++ b/llvm/unittests/VMCore/WaymarkTest.cpp @@ -0,0 +1,57 @@ +//===- llvm/unittest/VMCore/WaymarkTest.cpp - getUser() unit tests --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// we perform white-box tests +// +#define private public +#include "llvm/Use.h" +#undef private +#include "llvm/Function.h" +#include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" +#include "gtest/gtest.h" +#include <algorithm> + +namespace llvm { +namespace { + +Constant *char2constant(char c) { + return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c); +} + + +TEST(WaymarkTest, NativeArray) { + static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS"; + Value * values[22]; + std::transform(tail, tail + 22, values, char2constant); + FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true); + Function *F = Function::Create(FT, GlobalValue::ExternalLinkage); + const CallInst *A = CallInst::Create(F, makeArrayRef(values)); + ASSERT_NE(A, (const CallInst*)NULL); + ASSERT_EQ(1U + 22, A->getNumOperands()); + const Use *U = &A->getOperandUse(0); + const Use *Ue = &A->getOperandUse(22); + for (; U != Ue; ++U) + { + EXPECT_EQ(Ue + 1, U->getImpliedUser()); + } +} + +TEST(WaymarkTest, TwoBit) { + Use* many = (Use*)calloc(sizeof(Use), 8212); + ASSERT_TRUE(many); + Use::initTags(many, many + 8212); + for (const Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U) + { + EXPECT_EQ(Ue + 1, U->getImpliedUser()); + } +} + +} // end anonymous namespace +} // end namespace llvm |