From b031deda707e84abb68ba6f409910e0fad9f9a5f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 3 Dec 2017 01:53:18 -0800 Subject: [PATCH] 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 Reviewed-by: Nikos Nikoleris --- src/unittest/trietest.cc | 62 +++++++++++++++++++++++----------------- 1 file 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 #include +#include +#include #include "base/trie.hh" #include "base/types.hh" @@ -49,43 +51,51 @@ class TrieTestData : public testing::Test protected: typedef Trie 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(); } -- 2.30.2