summaryrefslogtreecommitdiff
path: root/src/unittest/trietest.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2017-12-03 01:53:18 -0800
committerGabe Black <gabeblack@google.com>2017-12-12 19:46:59 +0000
commitb031deda707e84abb68ba6f409910e0fad9f9a5f (patch)
tree32d32cb3f78d6c549a40685e32e1c0542d30454a /src/unittest/trietest.cc
parent3297cd0f6ed9d6b5ad3bbbf477b9b74dfba5b472 (diff)
downloadgem5-b031deda707e84abb68ba6f409910e0fad9f9a5f.tar.xz
tests: Plumb dumps of the test trie into the gtest macros.
With this change, when one of the tests fails, it will output a dump of the trie data structure, making it a little easier to tell what happened. Change-Id: I0816ed727ef0b50fefd7ec485356b4fe8790bfe1 Reviewed-on: https://gem5-review.googlesource.com/6267 Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src/unittest/trietest.cc')
-rw-r--r--src/unittest/trietest.cc62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/unittest/trietest.cc b/src/unittest/trietest.cc
index 4738ebd64..154200973 100644
--- a/src/unittest/trietest.cc
+++ b/src/unittest/trietest.cc
@@ -31,6 +31,8 @@
#include <gtest/gtest.h>
#include <iostream>
+#include <sstream>
+#include <string>
#include "base/trie.hh"
#include "base/types.hh"
@@ -49,43 +51,51 @@ class TrieTestData : public testing::Test
protected:
typedef Trie<Addr, uint32_t> TrieType;
TrieType trie;
+
+ std::string
+ dumpTrie()
+ {
+ std::stringstream ss;
+ trie.dump("test trie", ss);
+ return ss.str();
+ }
};
TEST_F(TrieTestData, Empty)
{
- EXPECT_EQ(trie.lookup(0x123456701234567), nullptr);
+ EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
}
TEST_F(TrieTestData, SingleEntry)
{
trie.insert(0x0123456789abcdef, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x123456701234567), nullptr);
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(1));
+ EXPECT_EQ(trie.lookup(0x123456701234567), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(1)) << dumpTrie();
}
TEST_F(TrieTestData, TwoOverlappingEntries)
{
trie.insert(0x0123456789abcdef, 40, ptr(1));
trie.insert(0x0123456789abcdef, 36, ptr(2));
- EXPECT_EQ(trie.lookup(0x123456700000000), nullptr);
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2));
+ EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
}
TEST_F(TrieTestData, TwoOverlappingEntriesReversed)
{
trie.insert(0x0123456789abcdef, 36, ptr(2));
trie.insert(0x0123456789abcdef, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x123456700000000), nullptr);
- EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2));
+ EXPECT_EQ(trie.lookup(0x123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x123456789ab0000), ptr(2)) << dumpTrie();
}
TEST_F(TrieTestData, TwoIndependentEntries)
{
trie.insert(0x0123456789abcdef, 40, ptr(2));
trie.insert(0x0123456776543210, 40, ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(2));
- EXPECT_EQ(trie.lookup(0x0123456776000000), ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr);
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456776000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
}
TEST_F(TrieTestData, TwoEntries)
@@ -95,10 +105,10 @@ TEST_F(TrieTestData, TwoEntries)
trie.insert(0x0123456780000000, 40, ptr(3));
trie.insert(0x0123456700000000, 40, ptr(2));
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2));
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4));
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
}
TEST_F(TrieTestData, RemovingEntries)
@@ -110,22 +120,22 @@ TEST_F(TrieTestData, RemovingEntries)
node1 = trie.insert(0x0123456700000000, 40, ptr(2));
node2 = trie.insert(0x0123456700000000, 32, ptr(10));
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(10));
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(10));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(10));
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(10)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(10)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(10)) << dumpTrie();
trie.remove(node2);
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2));
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4));
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), ptr(2)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
trie.remove(node1);
- EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1));
- EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr);
- EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3));
- EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4));
+ EXPECT_EQ(trie.lookup(0x0123000000000000), ptr(1)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456700000000), nullptr) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456780000000), ptr(3)) << dumpTrie();
+ EXPECT_EQ(trie.lookup(0x0123456789000000), ptr(4)) << dumpTrie();
}