summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2010-03-21 10:49:05 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2010-03-21 10:49:05 +0000
commit2f12f10af369d468b14617276446166383d692ed (patch)
tree2caca31db4facdc95c23930c0c745c8ef0dee97d /unittests
parentc69102774f9739c81ae1285ed9ae62405071c63c (diff)
Notes
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/APFloatTest.cpp2
-rw-r--r--unittests/ADT/APIntTest.cpp2
-rw-r--r--unittests/ADT/SmallVectorTest.cpp2
-rw-r--r--unittests/Support/LeakDetectorTest.cpp2
-rw-r--r--unittests/VMCore/InstructionsTest.cpp87
5 files changed, 94 insertions, 1 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp
index 571996013e36c..964b04da473c1 100644
--- a/unittests/ADT/APFloatTest.cpp
+++ b/unittests/ADT/APFloatTest.cpp
@@ -374,6 +374,7 @@ TEST(APFloatTest, makeNaN) {
}
#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
TEST(APFloatTest, SemanticsDeath) {
EXPECT_DEATH(APFloat(APFloat::IEEEsingle, 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
EXPECT_DEATH(APFloat(APFloat::IEEEdouble, 0.0 ).convertToFloat(), "Float semantics are not IEEEsingle");
@@ -573,5 +574,6 @@ TEST(APFloatTest, StringHexadecimalExponentDeath) {
EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p-"), "Exponent has no digits");
}
#endif
+#endif
}
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 0b13aa402ea18..d08e86abaa752 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -328,6 +328,7 @@ TEST(APIntTest, Log2) {
}
#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
TEST(APIntTest, StringDeath) {
EXPECT_DEATH(APInt(0, "", 0), "Bitwidth too small");
EXPECT_DEATH(APInt(32, "", 0), "Invalid string length");
@@ -340,5 +341,6 @@ TEST(APIntTest, StringDeath) {
EXPECT_DEATH(APInt(32, "1L", 10), "Invalid character in digit string");
}
#endif
+#endif
}
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp
index 8a817966cb8fd..d7dc3af52febc 100644
--- a/unittests/ADT/SmallVectorTest.cpp
+++ b/unittests/ADT/SmallVectorTest.cpp
@@ -384,7 +384,7 @@ TEST_F(SmallVectorTest, ConstVectorTest) {
// Direct array access.
TEST_F(SmallVectorTest, DirectVectorTest) {
EXPECT_EQ(0u, theVector.size());
- EXPECT_EQ(4u, theVector.capacity());
+ EXPECT_LE(4u, theVector.capacity());
EXPECT_EQ(0, Constructable::getNumConstructorCalls());
theVector.end()[0] = 1;
theVector.end()[1] = 2;
diff --git a/unittests/Support/LeakDetectorTest.cpp b/unittests/Support/LeakDetectorTest.cpp
index 85ef04676dcdc..d198c7a8bda0b 100644
--- a/unittests/Support/LeakDetectorTest.cpp
+++ b/unittests/Support/LeakDetectorTest.cpp
@@ -15,6 +15,7 @@ using namespace llvm;
namespace {
#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
TEST(LeakDetector, Death1) {
LeakDetector::addGarbageObject((void*) 1);
LeakDetector::addGarbageObject((void*) 2);
@@ -25,5 +26,6 @@ TEST(LeakDetector, Death1) {
"Cache != o && \"Object already in set!\"");
}
#endif
+#endif
}
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
index 2d98cad27fb8b..c1baa74487aa7 100644
--- a/unittests/VMCore/InstructionsTest.cpp
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -8,8 +8,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Instructions.h"
+#include "llvm/BasicBlock.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
+#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"
namespace llvm {
@@ -20,11 +22,13 @@ TEST(InstructionsTest, ReturnInst) {
// test for PR6589
const ReturnInst* r0 = ReturnInst::Create(C);
+ EXPECT_EQ(r0->getNumOperands(), 0U);
EXPECT_EQ(r0->op_begin(), r0->op_end());
const IntegerType* Int1 = IntegerType::get(C, 1);
Constant* One = ConstantInt::get(Int1, 1, true);
const ReturnInst* r1 = ReturnInst::Create(C, One);
+ EXPECT_EQ(r1->getNumOperands(), 1U);
User::const_op_iterator b(r1->op_begin());
EXPECT_NE(b, r1->op_end());
EXPECT_EQ(*b, One);
@@ -37,5 +41,88 @@ TEST(InstructionsTest, ReturnInst) {
delete r1;
}
+TEST(InstructionsTest, BranchInst) {
+ LLVMContext &C(getGlobalContext());
+
+ // Make a BasicBlocks
+ BasicBlock* bb0 = BasicBlock::Create(C);
+ BasicBlock* bb1 = BasicBlock::Create(C);
+
+ // Mandatory BranchInst
+ const BranchInst* b0 = BranchInst::Create(bb0);
+
+ EXPECT_TRUE(b0->isUnconditional());
+ EXPECT_FALSE(b0->isConditional());
+ EXPECT_EQ(b0->getNumSuccessors(), 1U);
+
+ // check num operands
+ EXPECT_EQ(b0->getNumOperands(), 1U);
+
+ EXPECT_NE(b0->op_begin(), b0->op_end());
+ EXPECT_EQ(next(b0->op_begin()), b0->op_end());
+
+ EXPECT_EQ(next(b0->op_begin()), b0->op_end());
+
+ const IntegerType* Int1 = IntegerType::get(C, 1);
+ Constant* One = ConstantInt::get(Int1, 1, true);
+
+ // Conditional BranchInst
+ BranchInst* b1 = BranchInst::Create(bb0, bb1, One);
+
+ EXPECT_FALSE(b1->isUnconditional());
+ EXPECT_TRUE(b1->isConditional());
+ EXPECT_EQ(b1->getNumSuccessors(), 2U);
+
+ // check num operands
+ EXPECT_EQ(b1->getNumOperands(), 3U);
+
+ User::const_op_iterator b(b1->op_begin());
+
+ // check COND
+ EXPECT_NE(b, b1->op_end());
+ EXPECT_EQ(*b, One);
+ EXPECT_EQ(b1->getOperand(0), One);
+ EXPECT_EQ(b1->getCondition(), One);
+ ++b;
+
+ // check ELSE
+ EXPECT_EQ(*b, bb1);
+ EXPECT_EQ(b1->getOperand(1), bb1);
+ EXPECT_EQ(b1->getSuccessor(1), bb1);
+ ++b;
+
+ // check THEN
+ EXPECT_EQ(*b, bb0);
+ EXPECT_EQ(b1->getOperand(2), bb0);
+ EXPECT_EQ(b1->getSuccessor(0), bb0);
+ ++b;
+
+ EXPECT_EQ(b, b1->op_end());
+
+ // shrink it
+ b1->setUnconditionalDest(bb1);
+
+ // check num operands
+ EXPECT_EQ(b1->getNumOperands(), 1U);
+
+ User::const_op_iterator c(b1->op_begin());
+ EXPECT_NE(c, b1->op_end());
+
+ // check THEN
+ EXPECT_EQ(*c, bb1);
+ EXPECT_EQ(b1->getOperand(0), bb1);
+ EXPECT_EQ(b1->getSuccessor(0), bb1);
+ ++c;
+
+ EXPECT_EQ(c, b1->op_end());
+
+ // clean up
+ delete b0;
+ delete b1;
+
+ delete bb0;
+ delete bb1;
+}
+
} // end anonymous namespace
} // end namespace llvm