Skip to content

Commit

Permalink
add unit test for waymarking algorithm (Use::getUser)
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167720 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ggreif committed Nov 12, 2012
1 parent 4db8833 commit 9a5f90a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions unittests/VMCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
57 changes: 57 additions & 0 deletions unittests/VMCore/WaymarkTest.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9a5f90a

Please sign in to comment.