From: Samuel Just Date: Fri, 13 May 2016 01:03:17 +0000 (-0700) Subject: TestPGLog: verify that the tracker is tracking changes in the test cases X-Git-Tag: ses5-milestone5~325^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c47d14a59ba4d57eec92fe881fec48c4ba79e429;p=ceph.git TestPGLog: verify that the tracker is tracking changes in the test cases Signed-off-by: Samuel Just --- diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 506447ca7ff..e2d6325d800 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -3089,6 +3089,48 @@ public: bool is_clean() const { return tracker.is_clean(); } + template + bool debug_verify_from_init( + const missing_t &init_missing, + ostream *oss) const { + if (!TrackChanges) + return true; + auto check_missing(init_missing.get_items()); + tracker.get_changed([&](const hobject_t &hoid) { + check_missing.erase(hoid); + if (missing.count(hoid)) { + check_missing.insert(*(missing.find(hoid))); + } + }); + bool ok = true; + if (check_missing.size() != missing.size()) { + if (oss) { + *oss << "Size mismatch, check: " << check_missing.size() + << ", actual: " << missing.size() << "\n"; + } + ok = false; + } + for (auto &i: missing) { + if (!check_missing.count(i.first)) { + if (oss) + *oss << "check_missing missing " << i.first << "\n"; + ok = false; + } else if (check_missing[i.first] != i.second) { + if (oss) + *oss << "check_missing missing item mismatch on " << i.first + << ", check: " << check_missing[i.first] + << ", actual: " << i.second << "\n"; + ok = false; + } + } + if (oss && !ok) { + *oss << "check_missing: " << check_missing << "\n"; + set changed; + tracker.get_changed([&](const hobject_t &hoid) { changed.insert(hoid); }); + *oss << "changed: " << changed << "\n"; + } + return ok; + } }; template void encode( diff --git a/src/test/osd/TestPGLog.cc b/src/test/osd/TestPGLog.cc index 0950671dc68..52981063a0a 100644 --- a/src/test/osd/TestPGLog.cc +++ b/src/test/osd/TestPGLog.cc @@ -173,9 +173,10 @@ public: const pg_log_entry_t &entry) {} }; + template void verify_missing( const TestCase &tcase, - const pg_missing_t &missing) { + const missing_t &missing) { ASSERT_EQ(tcase.final.get_items().size(), missing.get_items().size()); for (auto i = missing.get_items().begin(); i != missing.get_items().end(); @@ -184,6 +185,8 @@ public: EXPECT_EQ(tcase.final.get_items().find(i->first)->second.need, i->second.need); EXPECT_EQ(tcase.final.get_items().find(i->first)->second.have, i->second.have); } + bool correct = missing.debug_verify_from_init(tcase.init, &(std::cout)); + ASSERT_TRUE(correct); } void verify_sideeffects( @@ -216,6 +219,7 @@ public: pg_info_t info = tcase.get_divinfo(); missing = tcase.init; + missing.flush(); IndexedLog olog; olog = tcase.get_fullauth(); @@ -566,6 +570,7 @@ TEST_F(PGLogTest, merge_old_entry) { missing.rm(ne.soid, ne.version); } + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_FALSE(remove_snap.empty()); EXPECT_TRUE(t.empty()); @@ -635,6 +640,7 @@ TEST_F(PGLogTest, merge_old_entry) { oe.op = pg_log_entry_t::MODIFY; missing.add_next_event(oe); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.empty()); EXPECT_TRUE(t.empty()); @@ -644,6 +650,7 @@ TEST_F(PGLogTest, merge_old_entry) { TestHandler h(remove_snap); merge_old_entry(t, oe, info, &h); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.size() > 0); EXPECT_TRUE(t.empty()); @@ -669,6 +676,7 @@ TEST_F(PGLogTest, merge_old_entry) { oe.prior_version = eversion_t(2,1); missing_add(oe.soid, oe.prior_version, eversion_t()); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.empty()); EXPECT_TRUE(t.empty()); @@ -677,6 +685,7 @@ TEST_F(PGLogTest, merge_old_entry) { TestHandler h(remove_snap); merge_old_entry(t, oe, info, &h); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.empty()); EXPECT_TRUE(t.empty()); @@ -782,6 +791,7 @@ TEST_F(PGLogTest, merge_old_entry) { missing.add(oe.soid, eversion_t(1,1), eversion_t()); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_TRUE(remove_snap.empty()); EXPECT_TRUE(t.empty()); @@ -791,6 +801,7 @@ TEST_F(PGLogTest, merge_old_entry) { TestHandler h(remove_snap); merge_old_entry(t, oe, info, &h); + missing.flush(); EXPECT_FALSE(is_dirty()); EXPECT_EQ(oe.soid, remove_snap.front()); EXPECT_TRUE(t.empty());