summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2009-03-24 21:36:09 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2009-03-24 21:36:09 +0000
commit2e734269e3f354e52bd9e55d791e1885aa7d4cd8 (patch)
tree7d89cfa14aaf6fd455fc1e780cbfe127bb801bbb /unittests
parentabc061c0889ca8a624b5c57097a07aaacbf70f43 (diff)
Converted a1.ll to unittests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67652 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/APIntTest.cpp87
-rw-r--r--unittests/Makefile2
-rw-r--r--unittests/VMCore/ConstantsTest.cpp98
-rw-r--r--unittests/VMCore/Makefile15
4 files changed, 197 insertions, 5 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index cca512463ce..bb54cd935d7 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -7,13 +7,29 @@
//
//===----------------------------------------------------------------------===//
+#include <ostream>
+#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/SmallString.h"
using namespace llvm;
namespace {
+// Make the Google Test failure output equivalent to APInt::dump()
+std::ostream& operator<<(std::ostream &OS, const llvm::APInt& I) {
+ llvm::raw_os_ostream raw_os(OS);
+
+ SmallString<40> S, U;
+ I.toStringUnsigned(U);
+ I.toStringSigned(S);
+ raw_os << "APInt(" << I.getBitWidth()<< "b, "
+ << U.c_str() << "u " << S.c_str() << "s)";
+ raw_os.flush();
+ return OS;
+}
+
// Test that APInt shift left works when bitwidth > 64 and shiftamt == 0
TEST(APIntTest, ShiftLeftByZero) {
APInt One = APInt::getNullValue(65) + 1;
@@ -22,7 +38,7 @@ TEST(APIntTest, ShiftLeftByZero) {
EXPECT_EQ(false, Shl[1]);
}
-TEST(APIntTest, I128NegativeCount) {
+TEST(APIntTest, i128_NegativeCount) {
APInt Minus3(128, (uint64_t)-3, true);
EXPECT_EQ(126u, Minus3.countLeadingOnes());
EXPECT_EQ(-3, Minus3.getSExtValue());
@@ -37,7 +53,7 @@ TEST(APIntTest, I128NegativeCount) {
EXPECT_EQ(-1, Minus1.getSExtValue());
}
-TEST(APIntTest, I33Count) {
+TEST(APIntTest, i33_Count) {
APInt i33minus2(33, -2, true);
EXPECT_EQ(0u, i33minus2.countLeadingZeros());
EXPECT_EQ(32u, i33minus2.countLeadingOnes());
@@ -48,7 +64,7 @@ TEST(APIntTest, I33Count) {
EXPECT_EQ(((uint64_t)-2)&((1ull<<33) -1), i33minus2.getZExtValue());
}
-TEST(APIntTest, I65Count) {
+TEST(APIntTest, i65_Count) {
APInt i65minus(65, 0, true);
i65minus.set(64);
EXPECT_EQ(0u, i65minus.countLeadingZeros());
@@ -58,7 +74,7 @@ TEST(APIntTest, I65Count) {
EXPECT_EQ(1u, i65minus.countPopulation());
}
-TEST(APIntTest, I128PositiveCount) {
+TEST(APIntTest, i128_PositiveCount) {
APInt u128max = APInt::getAllOnesValue(128);
EXPECT_EQ(128u, u128max.countLeadingOnes());
EXPECT_EQ(0u, u128max.countLeadingZeros());
@@ -97,4 +113,67 @@ TEST(APIntTest, I128PositiveCount) {
EXPECT_EQ(1u, one.getZExtValue());
}
+TEST(APIntTest, i1) {
+ const APInt neg_two(1, -2, true);
+ const APInt neg_one(1, -1, true);
+ const APInt zero(1, 0);
+ const APInt one(1, 1);
+ const APInt two(1, 2);
+
+ EXPECT_EQ(0, neg_two.getSExtValue());
+ EXPECT_EQ(-1, neg_one.getSExtValue());
+ EXPECT_EQ(1u, neg_one.getZExtValue());
+ EXPECT_EQ(0u, zero.getZExtValue());
+ EXPECT_EQ(-1, one.getSExtValue());
+ EXPECT_EQ(1u, one.getZExtValue());
+ EXPECT_EQ(0u, two.getZExtValue());
+ EXPECT_EQ(0, two.getSExtValue());
+
+ // Basic equalities for 1-bit values.
+ EXPECT_EQ(zero, two);
+ EXPECT_EQ(zero, neg_two);
+ EXPECT_EQ(one, neg_one);
+ EXPECT_EQ(two, neg_two);
+
+ // Additions.
+ EXPECT_EQ(two, one + one);
+ EXPECT_EQ(zero, neg_one + one);
+ EXPECT_EQ(neg_two, neg_one + neg_one);
+
+ // Subtractions.
+ EXPECT_EQ(neg_two, neg_one - one);
+ EXPECT_EQ(two, one - neg_one);
+ EXPECT_EQ(zero, one - one);
+
+ // Shifts.
+ EXPECT_EQ(zero, one << one);
+ EXPECT_EQ(one, one << zero);
+ EXPECT_EQ(zero, one.shl(1));
+ EXPECT_EQ(one, one.shl(0));
+ EXPECT_EQ(zero, one.lshr(1));
+ EXPECT_EQ(zero, one.ashr(1));
+
+ // Multiplies.
+ EXPECT_EQ(neg_one, neg_one * one);
+ EXPECT_EQ(neg_one, one * neg_one);
+ EXPECT_EQ(one, neg_one * neg_one);
+ EXPECT_EQ(one, one * one);
+
+ // Divides.
+ EXPECT_EQ(neg_one, one.sdiv(neg_one));
+ EXPECT_EQ(neg_one, neg_one.sdiv(one));
+ EXPECT_EQ(one, neg_one.sdiv(neg_one));
+ EXPECT_EQ(one, one.sdiv(one));
+
+ EXPECT_EQ(neg_one, one.udiv(neg_one));
+ EXPECT_EQ(neg_one, neg_one.udiv(one));
+ EXPECT_EQ(one, neg_one.udiv(neg_one));
+ EXPECT_EQ(one, one.udiv(one));
+
+ // Remainders.
+ EXPECT_EQ(zero, neg_one.srem(one));
+ EXPECT_EQ(zero, neg_one.urem(one));
+ EXPECT_EQ(zero, one.srem(neg_one));
+}
+
}
diff --git a/unittests/Makefile b/unittests/Makefile
index 2a13b8d536d..1ff54111026 100644
--- a/unittests/Makefile
+++ b/unittests/Makefile
@@ -16,7 +16,7 @@ BUILD_ARCHIVE = 1
CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
CPP.Flags += -Wno-variadic-macros
-PARALLEL_DIRS = ADT Support
+PARALLEL_DIRS = ADT Support VMCore
include $(LEVEL)/Makefile.common
diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp
new file mode 100644
index 00000000000..1f30f2522f1
--- /dev/null
+++ b/unittests/VMCore/ConstantsTest.cpp
@@ -0,0 +1,98 @@
+//===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+TEST(ConstantsTest, Integer_i1) {
+ const IntegerType* Int1 = IntegerType::get(1);
+ Constant* One = ConstantInt::get(Int1, 1, true);
+ Constant* Zero = ConstantInt::get(Int1, 0);
+ Constant* NegOne = ConstantInt::get(Int1, -1, true);
+ Constant* Undef = UndefValue::get(Int1);
+
+ // Input: @b = constant i1 add(i1 1 , i1 1)
+ // Output: @b = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One));
+
+ // @c = constant i1 add(i1 -1, i1 1)
+ // @c = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One));
+
+ // @d = constant i1 add(i1 -1, i1 -1)
+ // @d = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne));
+
+ // @e = constant i1 sub(i1 -1, i1 1)
+ // @e = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One));
+
+ // @f = constant i1 sub(i1 1 , i1 -1)
+ // @f = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne));
+
+ // @g = constant i1 sub(i1 1 , i1 1)
+ // @g = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getSub(One, One));
+
+ // @h = constant i1 shl(i1 1 , i1 1) ; undefined
+ // @h = constant i1 undef
+ EXPECT_EQ(Undef, ConstantExpr::getShl(One, One));
+
+ // @i = constant i1 shl(i1 1 , i1 0)
+ // @i = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getShl(One, Zero));
+
+ // @j = constant i1 lshr(i1 1, i1 1) ; undefined
+ // @j = constant i1 undef
+ EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One));
+
+ // @m = constant i1 ashr(i1 1, i1 1) ; undefined
+ // @m = constant i1 undef
+ EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One));
+
+ // @n = constant i1 mul(i1 -1, i1 1)
+ // @n = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One));
+
+ // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow
+ // @o = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One));
+
+ // @p = constant i1 sdiv(i1 1 , i1 -1); overflow
+ // @p = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne));
+
+ // @q = constant i1 udiv(i1 -1, i1 1)
+ // @q = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One));
+
+ // @r = constant i1 udiv(i1 1, i1 -1)
+ // @r = constant i1 true
+ EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne));
+
+ // @s = constant i1 srem(i1 -1, i1 1) ; overflow
+ // @s = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One));
+
+ // @t = constant i1 urem(i1 -1, i1 1)
+ // @t = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One));
+
+ // @u = constant i1 srem(i1 1, i1 -1) ; overflow
+ // @u = constant i1 false
+ EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne));
+}
+
+} // end anonymous namespace
+} // end namespace llvm
diff --git a/unittests/VMCore/Makefile b/unittests/VMCore/Makefile
new file mode 100644
index 00000000000..1aa1560c3c3
--- /dev/null
+++ b/unittests/VMCore/Makefile
@@ -0,0 +1,15 @@
+##===- unittests/VMCore/Makefile ---------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TESTNAME = VMCore
+LINK_COMPONENTS := core support
+
+include $(LEVEL)/Makefile.config
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest