summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2017-11-22 18:11:58 -0800
committerGabe Black <gabeblack@google.com>2017-11-28 11:00:01 +0000
commit601fa8a25c8aa2eff809a7011e9751f4bfff488a (patch)
tree3a9ab92feb471d9bd562c55291af0590e0e77bb5
parent16d6ed6660337b7293072da8a8f6ff6f4d9dbb4e (diff)
downloadgem5-601fa8a25c8aa2eff809a7011e9751f4bfff488a.tar.xz
tests: Reimplement the bituniontest as a googletest.
The implementation is very similar to the old test structurally, and should test all the same things. Change-Id: I58f1559d0943f2494ef06ee1d7ee5314a3852a8c Reviewed-on: https://gem5-review.googlesource.com/6085 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
-rw-r--r--src/unittest/SConscript2
-rw-r--r--src/unittest/bituniontest.cc64
2 files changed, 39 insertions, 27 deletions
diff --git a/src/unittest/SConscript b/src/unittest/SConscript
index 70e3c2f95..cca3336b2 100644
--- a/src/unittest/SConscript
+++ b/src/unittest/SConscript
@@ -32,7 +32,7 @@ Import('*')
Source('unittest.cc')
-UnitTest('bituniontest', 'bituniontest.cc')
+GTest('bituniontest', 'bituniontest.cc')
UnitTest('bitvectest', 'bitvectest.cc')
UnitTest('circlebuf', 'circlebuf.cc')
UnitTest('cprintftest', 'cprintftest.cc')
diff --git a/src/unittest/bituniontest.cc b/src/unittest/bituniontest.cc
index 4146b28dd..1f24e7e66 100644
--- a/src/unittest/bituniontest.cc
+++ b/src/unittest/bituniontest.cc
@@ -27,15 +27,15 @@
* Authors: Gabe Black
*/
+#include <gtest/gtest.h>
+
#include <cassert>
#include <iostream>
#include "base/bitunion.hh"
#include "base/cprintf.hh"
-#include "unittest/unittest.hh"
using namespace std;
-using UnitTest::setCase;
namespace {
@@ -96,39 +96,46 @@ EmptyThirtyTwo emptyThirtyTwo;
EmptySixteen emptySixteen;
EmptyEight emptyEight(0);
-int
-main()
-{
- SixtyFour sixtyFour = 0;
+class BitUnionData : public testing::Test {
+ protected:
+ SixtyFour sixtyFour;
+
+ void SetUp() override { sixtyFour = 0; }
+};
- setCase("normal bitfield");
+TEST_F(BitUnionData, NormalBitfield)
+{
EXPECT_EQ(sixtyFour.byte5, 0);
sixtyFour.byte5 = 0xff;
EXPECT_EQ(sixtyFour, 0xff00000000);
sixtyFour.byte5 = 0xfff;
EXPECT_EQ(sixtyFour, 0xff00000000);
EXPECT_EQ(sixtyFour.byte5, 0xff);
- sixtyFour = 0;
+}
- setCase("single bitfield");
+TEST_F(BitUnionData, SingleBitfield)
+{
EXPECT_EQ(sixtyFour.bit2, 0);
sixtyFour.bit2 = 0x1;
EXPECT_EQ(sixtyFour, 0x4);
EXPECT_EQ(sixtyFour.bit2, 0x1);
- sixtyFour = 0;
+}
- setCase("read only bitfield");
+TEST_F(BitUnionData, ReadOnlyBitfield)
+{
EXPECT_EQ(sixtyFour.byte5RO, 0);
sixtyFour.byte5 = 0xff;
EXPECT_EQ(sixtyFour.byte5RO, 0xff);
- sixtyFour = 0;
+}
- setCase("write only bitfield");
+TEST_F(BitUnionData, WriteOnlyBitfield)
+{
sixtyFour.byte5WO = 0xff;
EXPECT_EQ(sixtyFour, 0xff00000000);
- sixtyFour = 0;
+}
- setCase("sub bitunions and their bitfields");
+TEST_F(BitUnionData, SubBitUnions)
+{
EXPECT_EQ(sixtyFour.byte6.bit41, 0);
sixtyFour.byte6 = 0x2;
EXPECT_EQ(sixtyFour.byte6.bit41, 1);
@@ -137,9 +144,10 @@ main()
sixtyFour.byte6 = 0xff;
sixtyFour.byte6.bit41 = 0;
EXPECT_EQ(sixtyFour, 0xfd0000000000);
- sixtyFour = 0;
+}
- setCase("normal, read only, and write only signed bitfields");
+TEST_F(BitUnionData, SignedBitfields)
+{
sixtyFour.byte6 = 0xff;
EXPECT_EQ(sixtyFour.byte6Signed, -1);
EXPECT_EQ(sixtyFour.byte6SignedRO, -1);
@@ -147,28 +155,34 @@ main()
EXPECT_EQ(sixtyFour.byte6Signed, 0);
EXPECT_EQ(sixtyFour.byte6SignedRO, 0);
EXPECT_EQ(sixtyFour.byte6, 0);
- sixtyFour = 0;
+}
- setCase("bitunion declared inside a struct");
+TEST_F(BitUnionData, InsideStruct)
+{
ContainingStruct containing;
containing.contained = 0;
containing.contained.topNibble = 0xd;
EXPECT_EQ(containing.contained, 0xd000000000000000);
+}
- setCase("bitunion declared inside a function");
+TEST_F(BitUnionData, InsideFunction)
+{
EXPECT_EQ(containingFunc(0xfffff, 0), 0xe7fff);
+}
- setCase("assigning bitfields to other bitfields");
+TEST_F(BitUnionData, BitfieldToBitfieldAssignment)
+{
SixtyFour otherSixtyFour = 0;
sixtyFour.bit2 = 1;
otherSixtyFour.byte6.bit41 = sixtyFour.bit2;
EXPECT_EQ(otherSixtyFour, 0x20000000000);
otherSixtyFour.bit2 = sixtyFour.bit2;
EXPECT_EQ(otherSixtyFour, 0x20000000004);
+}
- setCase("bitunion operators");
- sixtyFour = 0;
- otherSixtyFour = 0x4;
+TEST_F(BitUnionData, Operators)
+{
+ SixtyFour otherSixtyFour = 0x4;
sixtyFour = otherSixtyFour;
EXPECT_EQ(sixtyFour, 0x4);
sixtyFour = 0;
@@ -177,6 +191,4 @@ main()
EXPECT_TRUE(sixtyFour != otherSixtyFour);
sixtyFour = otherSixtyFour;
EXPECT_TRUE(sixtyFour == otherSixtyFour);
-
- return UnitTest::printResults();
}