]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
TestPGLog: verify that the tracker is tracking changes in the test cases
authorSamuel Just <sjust@redhat.com>
Fri, 13 May 2016 01:03:17 +0000 (18:03 -0700)
committerSamuel Just <sjust@redhat.com>
Thu, 14 Jul 2016 14:48:14 +0000 (07:48 -0700)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/osd/osd_types.h
src/test/osd/TestPGLog.cc

index 506447ca7ff96fab471f71959851cf11fb65fedf..e2d6325d800cdf1b1c0c81c53b8ddaf2e5c8ff0f 100644 (file)
@@ -3089,6 +3089,48 @@ public:
   bool is_clean() const {
     return tracker.is_clean();
   }
+  template <typename missing_t>
+  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<hobject_t, hobject_t::BitwiseComparator> changed;
+      tracker.get_changed([&](const hobject_t &hoid) { changed.insert(hoid); });
+      *oss << "changed: " << changed << "\n";
+    }
+    return ok;
+  }
 };
 template <bool TrackChanges>
 void encode(
index 0950671dc68ac4967d3e1832ccda5ca5a6db3c8e..52981063a0a8af44a366523bd28e9bb6ecedc42c 100644 (file)
@@ -173,9 +173,10 @@ public:
       const pg_log_entry_t &entry) {}
   };
 
+  template <typename missing_t>
   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());