tests: Reimplement the bituniontest as a googletest.
authorGabe Black <gabeblack@google.com>
Thu, 23 Nov 2017 02:11:58 +0000 (18:11 -0800)
committerGabe Black <gabeblack@google.com>
Tue, 28 Nov 2017 11:00:01 +0000 (11:00 +0000)
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>

src/unittest/SConscript
src/unittest/bituniontest.cc

index 70e3c2f950a0265f6149f94f22c04f73b5707a77..cca3336b2690ad1736fe989fa9575749d39f5289 100644 (file)
@@ -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')
index 4146b28dd95ba886ff4d0c422a3721373dd41698..1f24e7e66d4d6bbdd8a40f42c8411d6b0e21916c 100644 (file)
  * 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();
 }