1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Now that googletest can print ConstantRange, use EXPECT_EQ when testing for

equality. Prefer EXPECT_EQ(foo, Full) over EXPECT_TRUE(foo.isFullSet()) because
the former will print out the contents of the constant range that failed.

llvm-svn: 81094
This commit is contained in:
Nick Lewycky 2009-09-05 18:27:40 +00:00
parent 25713a50a3
commit 729d642928

View File

@ -79,21 +79,21 @@ TEST_F(ConstantRangeTest, Basics) {
}
TEST_F(ConstantRangeTest, Equality) {
EXPECT_TRUE(Full == Full);
EXPECT_TRUE(Empty == Empty);
EXPECT_TRUE(One == One);
EXPECT_TRUE(Some == Some);
EXPECT_TRUE(Wrap == Wrap);
EXPECT_TRUE(Full != Empty);
EXPECT_TRUE(Full != One);
EXPECT_TRUE(Full != Some);
EXPECT_TRUE(Full != Wrap);
EXPECT_TRUE(Empty != One);
EXPECT_TRUE(Empty != Some);
EXPECT_TRUE(Empty != Wrap);
EXPECT_TRUE(One != Some);
EXPECT_TRUE(One != Wrap);
EXPECT_TRUE(Some != Wrap);
EXPECT_EQ(Full, Full);
EXPECT_EQ(Empty, Empty);
EXPECT_EQ(One, One);
EXPECT_EQ(Some, Some);
EXPECT_EQ(Wrap, Wrap);
EXPECT_NE(Full, Empty);
EXPECT_NE(Full, One);
EXPECT_NE(Full, Some);
EXPECT_NE(Full, Wrap);
EXPECT_NE(Empty, One);
EXPECT_NE(Empty, Some);
EXPECT_NE(Empty, Wrap);
EXPECT_NE(One, Some);
EXPECT_NE(One, Wrap);
EXPECT_NE(Some, Wrap);
}
TEST_F(ConstantRangeTest, SingleElement) {
@ -152,7 +152,7 @@ TEST_F(ConstantRangeTest, Trunc) {
ConstantRange TWrap = Wrap.truncate(10);
EXPECT_TRUE(TFull.isFullSet());
EXPECT_TRUE(TEmpty.isEmptySet());
EXPECT_TRUE(TOne == ConstantRange(APInt(One.getLower()).trunc(10),
EXPECT_EQ(TOne, ConstantRange(APInt(One.getLower()).trunc(10),
APInt(One.getUpper()).trunc(10)));
EXPECT_TRUE(TSome.isFullSet());
}
@ -163,14 +163,14 @@ TEST_F(ConstantRangeTest, ZExt) {
ConstantRange ZOne = One.zeroExtend(20);
ConstantRange ZSome = Some.zeroExtend(20);
ConstantRange ZWrap = Wrap.zeroExtend(20);
EXPECT_TRUE(ZFull == ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
EXPECT_TRUE(ZEmpty.isEmptySet());
EXPECT_TRUE(ZOne == ConstantRange(APInt(One.getLower()).zext(20),
APInt(One.getUpper()).zext(20)));
EXPECT_TRUE(ZSome == ConstantRange(APInt(Some.getLower()).zext(20),
APInt(Some.getUpper()).zext(20)));
EXPECT_TRUE(ZWrap == ConstantRange(APInt(Wrap.getLower()).zext(20),
APInt(Wrap.getUpper()).zext(20)));
EXPECT_EQ(ZOne, ConstantRange(APInt(One.getLower()).zext(20),
APInt(One.getUpper()).zext(20)));
EXPECT_EQ(ZSome, ConstantRange(APInt(Some.getLower()).zext(20),
APInt(Some.getUpper()).zext(20)));
EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20),
APInt(Wrap.getUpper()).zext(20)));
}
TEST_F(ConstantRangeTest, SExt) {
@ -179,31 +179,31 @@ TEST_F(ConstantRangeTest, SExt) {
ConstantRange SOne = One.signExtend(20);
ConstantRange SSome = Some.signExtend(20);
ConstantRange SWrap = Wrap.signExtend(20);
EXPECT_TRUE(SFull == ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
APInt(20, INT16_MAX + 1, true)));
EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
APInt(20, INT16_MAX + 1, true)));
EXPECT_TRUE(SEmpty.isEmptySet());
EXPECT_TRUE(SOne == ConstantRange(APInt(One.getLower()).sext(20),
APInt(One.getUpper()).sext(20)));
EXPECT_TRUE(SSome == ConstantRange(APInt(Some.getLower()).sext(20),
APInt(Some.getUpper()).sext(20)));
EXPECT_TRUE(SWrap == ConstantRange(APInt(Wrap.getLower()).sext(20),
APInt(Wrap.getUpper()).sext(20)));
EXPECT_EQ(SOne, ConstantRange(APInt(One.getLower()).sext(20),
APInt(One.getUpper()).sext(20)));
EXPECT_EQ(SSome, ConstantRange(APInt(Some.getLower()).sext(20),
APInt(Some.getUpper()).sext(20)));
EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20),
APInt(Wrap.getUpper()).sext(20)));
}
TEST_F(ConstantRangeTest, IntersectWith) {
EXPECT_TRUE(Empty.intersectWith(Full).isEmptySet());
EXPECT_TRUE(Empty.intersectWith(Empty).isEmptySet());
EXPECT_TRUE(Empty.intersectWith(One).isEmptySet());
EXPECT_TRUE(Empty.intersectWith(Some).isEmptySet());
EXPECT_TRUE(Empty.intersectWith(Wrap).isEmptySet());
EXPECT_TRUE(Full.intersectWith(Full).isFullSet());
EXPECT_TRUE(Some.intersectWith(Some) == Some);
EXPECT_TRUE(Some.intersectWith(One) == One);
EXPECT_TRUE(Full.intersectWith(One) == One);
EXPECT_TRUE(Full.intersectWith(Some) == Some);
EXPECT_TRUE(Some.intersectWith(Wrap).isEmptySet());
EXPECT_TRUE(One.intersectWith(Wrap).isEmptySet());
EXPECT_TRUE(One.intersectWith(Wrap) == Wrap.intersectWith(One));
EXPECT_EQ(Empty.intersectWith(Full), Empty);
EXPECT_EQ(Empty.intersectWith(Empty), Empty);
EXPECT_EQ(Empty.intersectWith(One), Empty);
EXPECT_EQ(Empty.intersectWith(Some), Empty);
EXPECT_EQ(Empty.intersectWith(Wrap), Empty);
EXPECT_EQ(Full.intersectWith(Full), Full);
EXPECT_EQ(Some.intersectWith(Some), Some);
EXPECT_EQ(Some.intersectWith(One), One);
EXPECT_EQ(Full.intersectWith(One), One);
EXPECT_EQ(Full.intersectWith(Some), Some);
EXPECT_EQ(Some.intersectWith(Wrap), Empty);
EXPECT_EQ(One.intersectWith(Wrap), Empty);
EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
// Klee generated testcase from PR4545.
// The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
@ -214,139 +214,139 @@ TEST_F(ConstantRangeTest, IntersectWith) {
}
TEST_F(ConstantRangeTest, UnionWith) {
EXPECT_TRUE(Wrap.unionWith(One) ==
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
EXPECT_TRUE(One.unionWith(Wrap) == Wrap.unionWith(One));
EXPECT_TRUE(Empty.unionWith(Empty).isEmptySet());
EXPECT_TRUE(Full.unionWith(Full).isFullSet());
EXPECT_TRUE(Some.unionWith(Wrap).isFullSet());
EXPECT_EQ(Wrap.unionWith(One),
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
EXPECT_EQ(Empty.unionWith(Empty), Empty);
EXPECT_EQ(Full.unionWith(Full), Full);
EXPECT_EQ(Some.unionWith(Wrap), Full);
// PR4545
EXPECT_TRUE(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
ConstantRange(APInt(16, 0), APInt(16, 8))) ==
ConstantRange(APInt(16, 14), APInt(16, 8)));
EXPECT_TRUE(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
ConstantRange(APInt(16, 4), APInt(16, 0))) ==
EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
ConstantRange(APInt(16, 0), APInt(16, 8))),
ConstantRange(APInt(16, 14), APInt(16, 8)));
EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
ConstantRange(APInt(16, 4), APInt(16, 0))),
ConstantRange(16));
EXPECT_TRUE(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
ConstantRange(APInt(16, 2), APInt(16, 1))) ==
EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
ConstantRange(APInt(16, 2), APInt(16, 1))),
ConstantRange(16));
}
TEST_F(ConstantRangeTest, SubtractAPInt) {
EXPECT_TRUE(Full.subtract(APInt(16, 4)).isFullSet());
EXPECT_TRUE(Empty.subtract(APInt(16, 4)).isEmptySet());
EXPECT_TRUE(Some.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
EXPECT_TRUE(Wrap.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
EXPECT_TRUE(One.subtract(APInt(16, 4)) ==
ConstantRange(APInt(16, 0x6)));
EXPECT_EQ(Full.subtract(APInt(16, 4)), Full);
EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty);
EXPECT_EQ(Some.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
EXPECT_EQ(Wrap.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
EXPECT_EQ(One.subtract(APInt(16, 4)),
ConstantRange(APInt(16, 0x6)));
}
TEST_F(ConstantRangeTest, Add) {
EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet());
EXPECT_TRUE(Full.add(Full) == Full);
EXPECT_TRUE(Full.add(Empty) == Empty);
EXPECT_TRUE(Full.add(One) == Full);
EXPECT_TRUE(Full.add(Some) == Full);
EXPECT_TRUE(Full.add(Wrap) == Full);
EXPECT_TRUE(Empty.add(Empty) == Empty);
EXPECT_TRUE(Empty.add(One) == Empty);
EXPECT_TRUE(Empty.add(Some) == Empty);
EXPECT_TRUE(Empty.add(Wrap) == Empty);
EXPECT_TRUE(Empty.add(APInt(16, 4)).isEmptySet());
EXPECT_TRUE(Some.add(APInt(16, 4)) ==
EXPECT_EQ(Full.add(APInt(16, 4)), Full);
EXPECT_EQ(Full.add(Full), Full);
EXPECT_EQ(Full.add(Empty), Empty);
EXPECT_EQ(Full.add(One), Full);
EXPECT_EQ(Full.add(Some), Full);
EXPECT_EQ(Full.add(Wrap), Full);
EXPECT_EQ(Empty.add(Empty), Empty);
EXPECT_EQ(Empty.add(One), Empty);
EXPECT_EQ(Empty.add(Some), Empty);
EXPECT_EQ(Empty.add(Wrap), Empty);
EXPECT_EQ(Empty.add(APInt(16, 4)), Empty);
EXPECT_EQ(Some.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
EXPECT_TRUE(Wrap.add(APInt(16, 4)) ==
EXPECT_EQ(Wrap.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
EXPECT_TRUE(One.add(APInt(16, 4)) ==
EXPECT_EQ(One.add(APInt(16, 4)),
ConstantRange(APInt(16, 0xe)));
}
TEST_F(ConstantRangeTest, Multiply) {
EXPECT_TRUE(Full.multiply(Full) == Full);
EXPECT_TRUE(Full.multiply(Empty) == Empty);
EXPECT_TRUE(Full.multiply(One) == Full);
EXPECT_TRUE(Full.multiply(Some) == Full);
EXPECT_TRUE(Full.multiply(Wrap) == Full);
EXPECT_TRUE(Empty.multiply(Empty) == Empty);
EXPECT_TRUE(Empty.multiply(One) == Empty);
EXPECT_TRUE(Empty.multiply(Some) == Empty);
EXPECT_TRUE(Empty.multiply(Wrap) == Empty);
EXPECT_TRUE(One.multiply(One) == ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xa + 1)));
EXPECT_TRUE(One.multiply(Some) == ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xaa9 + 1)));
EXPECT_TRUE(One.multiply(Wrap).isFullSet());
EXPECT_TRUE(Some.multiply(Some).isFullSet());
EXPECT_TRUE(Some.multiply(Wrap) == Full);
EXPECT_TRUE(Wrap.multiply(Wrap) == Full);
EXPECT_EQ(Full.multiply(Full), Full);
EXPECT_EQ(Full.multiply(Empty), Empty);
EXPECT_EQ(Full.multiply(One), Full);
EXPECT_EQ(Full.multiply(Some), Full);
EXPECT_EQ(Full.multiply(Wrap), Full);
EXPECT_EQ(Empty.multiply(Empty), Empty);
EXPECT_EQ(Empty.multiply(One), Empty);
EXPECT_EQ(Empty.multiply(Some), Empty);
EXPECT_EQ(Empty.multiply(Wrap), Empty);
EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xa + 1)));
EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
APInt(16, 0xa*0xaa9 + 1)));
EXPECT_EQ(One.multiply(Wrap), Full);
EXPECT_EQ(Some.multiply(Some), Full);
EXPECT_EQ(Some.multiply(Wrap), Full);
EXPECT_EQ(Wrap.multiply(Wrap), Full);
// http://llvm.org/PR4545
EXPECT_TRUE(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))) ==
ConstantRange(4, /*isFullSet=*/true));
EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
ConstantRange(APInt(4, 6), APInt(4, 2))),
ConstantRange(4, /*isFullSet=*/true));
}
TEST_F(ConstantRangeTest, UMax) {
EXPECT_TRUE(Full.umax(Full).isFullSet());
EXPECT_TRUE(Full.umax(Empty).isEmptySet());
EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Full.umax(Wrap).isFullSet());
EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Empty.umax(Empty) == Empty);
EXPECT_TRUE(Empty.umax(Some) == Empty);
EXPECT_TRUE(Empty.umax(Wrap) == Empty);
EXPECT_TRUE(Empty.umax(One) == Empty);
EXPECT_TRUE(Some.umax(Some) == Some);
EXPECT_TRUE(Some.umax(Wrap) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(Some.umax(One) == Some);
EXPECT_EQ(Full.umax(Full), Full);
EXPECT_EQ(Full.umax(Empty), Empty);
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(Full.umax(Wrap), Full);
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(Empty.umax(Empty), Empty);
EXPECT_EQ(Empty.umax(Some), Empty);
EXPECT_EQ(Empty.umax(Wrap), Empty);
EXPECT_EQ(Empty.umax(One), Empty);
EXPECT_EQ(Some.umax(Some), Some);
EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(Some.umax(One), Some);
// TODO: ConstantRange is currently over-conservative here.
EXPECT_TRUE(Wrap.umax(Wrap) == Full);
EXPECT_TRUE(Wrap.umax(One) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_TRUE(One.umax(One) == One);
EXPECT_EQ(Wrap.umax(Wrap), Full);
EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
EXPECT_EQ(One.umax(One), One);
}
TEST_F(ConstantRangeTest, SMax) {
EXPECT_TRUE(Full.smax(Full).isFullSet());
EXPECT_TRUE(Full.smax(Empty).isEmptySet());
EXPECT_TRUE(Full.smax(Some) == ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_TRUE(Full.smax(Wrap).isFullSet());
EXPECT_TRUE(Full.smax(One) == ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_TRUE(Empty.smax(Empty) == Empty);
EXPECT_TRUE(Empty.smax(Some) == Empty);
EXPECT_TRUE(Empty.smax(Wrap) == Empty);
EXPECT_TRUE(Empty.smax(One) == Empty);
EXPECT_TRUE(Some.smax(Some) == Some);
EXPECT_TRUE(Some.smax(Wrap) == ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_TRUE(Some.smax(One) == Some);
EXPECT_TRUE(Wrap.smax(One) == ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_TRUE(One.smax(One) == One);
EXPECT_EQ(Full.smax(Full), Full);
EXPECT_EQ(Full.smax(Empty), Empty);
EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_EQ(Full.smax(Wrap), Full);
EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
APInt::getSignedMinValue(16)));
EXPECT_EQ(Empty.smax(Empty), Empty);
EXPECT_EQ(Empty.smax(Some), Empty);
EXPECT_EQ(Empty.smax(Wrap), Empty);
EXPECT_EQ(Empty.smax(One), Empty);
EXPECT_EQ(Some.smax(Some), Some);
EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_EQ(Some.smax(One), Some);
EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
APInt(16, (uint64_t)INT16_MIN)));
EXPECT_EQ(One.smax(One), One);
}
TEST_F(ConstantRangeTest, UDiv) {
EXPECT_TRUE(Full.udiv(Full) == Full);
EXPECT_TRUE(Full.udiv(Empty) == Empty);
EXPECT_TRUE(Full.udiv(One) == ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_TRUE(Full.udiv(Some) == ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_TRUE(Full.udiv(Wrap) == Full);
EXPECT_TRUE(Empty.udiv(Empty) == Empty);
EXPECT_TRUE(Empty.udiv(One) == Empty);
EXPECT_TRUE(Empty.udiv(Some) == Empty);
EXPECT_TRUE(Empty.udiv(Wrap) == Empty);
EXPECT_TRUE(One.udiv(One) == ConstantRange(APInt(16, 1)));
EXPECT_TRUE(One.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 2)));
EXPECT_TRUE(One.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xb)));
EXPECT_TRUE(Some.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 0x111)));
EXPECT_TRUE(Some.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_TRUE(Wrap.udiv(Wrap) == Full);
EXPECT_EQ(Full.udiv(Full), Full);
EXPECT_EQ(Full.udiv(Empty), Empty);
EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
APInt(16, 0xffff / 0xa + 1)));
EXPECT_EQ(Full.udiv(Wrap), Full);
EXPECT_EQ(Empty.udiv(Empty), Empty);
EXPECT_EQ(Empty.udiv(One), Empty);
EXPECT_EQ(Empty.udiv(Some), Empty);
EXPECT_EQ(Empty.udiv(Wrap), Empty);
EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
EXPECT_EQ(Wrap.udiv(Wrap), Full);
}
} // anonymous namespace