]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
src/test/crimson: unify the two TestBlock implemenations
authorSamuel Just <sjust@redhat.com>
Thu, 11 Jun 2020 18:53:56 +0000 (11:53 -0700)
committerSamuel Just <sjust@redhat.com>
Fri, 19 Jun 2020 19:59:26 +0000 (12:59 -0700)
cache.cc is going to need a way to generate an appopriately
typed extent from a delta or on disk block based on the
type tag.  Thus, there can only be one TestBlock for now
unless it becomes at some point worth making it dynamic.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/test/crimson/seastore/test_block.h [new file with mode: 0644]
src/test/crimson/seastore/test_seastore_cache.cc
src/test/crimson/seastore/test_transaction_manager.cc

diff --git a/src/test/crimson/seastore/test_block.h b/src/test/crimson/seastore/test_block.h
new file mode 100644 (file)
index 0000000..3277511
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include "crimson/os/seastore/transaction_manager.h"
+
+namespace crimson::os::seastore {
+
+struct test_extent_desc_t {
+  size_t len = 0;
+  unsigned checksum = 0;
+
+  bool operator==(const test_extent_desc_t &rhs) const {
+    return (len == rhs.len &&
+           checksum == rhs.checksum);
+  }
+  bool operator!=(const test_extent_desc_t &rhs) const {
+    return !(*this == rhs);
+  }
+};
+
+inline std::ostream &operator<<(
+  std::ostream &lhs, const test_extent_desc_t &rhs) {
+  return lhs << "test_extent_desc_t(len=" << rhs.len
+            << ", checksum=" << rhs.checksum << ")";
+}
+
+struct TestBlock : crimson::os::seastore::LogicalCachedExtent {
+  constexpr static segment_off_t SIZE = 4<<10;
+  using Ref = TCachedExtentRef<TestBlock>;
+
+  TestBlock(ceph::bufferptr &&ptr) : LogicalCachedExtent(std::move(ptr)) {}
+  TestBlock(const TestBlock &other) : LogicalCachedExtent(other) {}
+
+  CachedExtentRef duplicate_for_write() final {
+    return CachedExtentRef(new TestBlock(*this));
+  };
+
+  static constexpr extent_types_t TYPE = extent_types_t::TEST_BLOCK;
+  extent_types_t get_type() const final {
+    return TYPE;
+  }
+
+  ceph::bufferlist get_delta() final {
+    return ceph::bufferlist();
+  }
+
+  void set_contents(char c) {
+    ::memset(get_bptr().c_str(), c, get_length());
+  }
+
+  int checksum() {
+    return ceph_crc32c(
+      1,
+      (const unsigned char *)get_bptr().c_str(),
+      get_length());
+  }
+
+  test_extent_desc_t get_desc() {
+    return { get_length(), get_crc32c(1) };
+  }
+
+  void apply_delta(paddr_t delta_base, ceph::bufferlist &bl) final {
+    ceph_assert(0 == "TODO");
+  }
+};
+using TestBlockRef = TCachedExtentRef<TestBlock>;
+
+}
index 797d080e194f5e7e07a047a462a26da94a4288ef..e5dda0d23237c59d9c2b4ef9b4c205daeb552f4e 100644 (file)
@@ -7,6 +7,8 @@
 #include "crimson/os/seastore/cache.h"
 #include "crimson/os/seastore/segment_manager/ephemeral.h"
 
+#include "test/crimson/seastore/test_block.h"
+
 using namespace crimson;
 using namespace crimson::os;
 using namespace crimson::os::seastore;
@@ -17,42 +19,6 @@ namespace {
   }
 }
 
-struct CacheTestBlock : CachedExtent {
-  constexpr static segment_off_t SIZE = 4<<10;
-  using Ref = TCachedExtentRef<CacheTestBlock>;
-
-  template <typename... T>
-  CacheTestBlock(T&&... t) : CachedExtent(std::forward<T>(t)...) {}
-
-  CachedExtentRef duplicate_for_write() final {
-    return CachedExtentRef(new CacheTestBlock(*this));
-  };
-
-  static constexpr extent_types_t TYPE = extent_types_t::TEST_BLOCK;
-  extent_types_t get_type() const final {
-    return TYPE;
-  }
-
-  ceph::bufferlist get_delta() final {
-    return ceph::bufferlist();
-  }
-
-  void apply_delta(paddr_t delta_base, ceph::bufferlist &bl) final {
-    ceph_assert(0 == "TODO");
-  }
-
-  void set_contents(char c) {
-    ::memset(get_bptr().c_str(), c, get_length());
-  }
-
-  int checksum() {
-    return ceph_crc32c(
-      1,
-      (const unsigned char *)get_bptr().c_str(),
-      get_length());
-  }
-};
-
 struct cache_test_t : public seastar_test_suite_t {
   segment_manager::EphemeralSegmentManager segment_manager;
   Cache cache;
@@ -135,9 +101,9 @@ TEST_F(cache_test_t, test_addr_fixup)
     int csum = 0;
     {
       auto t = get_transaction();
-      auto extent = cache.alloc_new_extent<CacheTestBlock>(
+      auto extent = cache.alloc_new_extent<TestBlock>(
        *t,
-       CacheTestBlock::SIZE);
+       TestBlock::SIZE);
       extent->set_contents('c');
       csum = extent->checksum();
       auto ret = submit_transaction(std::move(t)).get0();
@@ -146,10 +112,10 @@ TEST_F(cache_test_t, test_addr_fixup)
     }
     {
       auto t = get_transaction();
-      auto extent = cache.get_extent<CacheTestBlock>(
+      auto extent = cache.get_extent<TestBlock>(
        *t,
        addr,
-       CacheTestBlock::SIZE).unsafe_get0();
+       TestBlock::SIZE).unsafe_get0();
       ASSERT_EQ(extent->get_paddr(), addr);
       ASSERT_EQ(extent->checksum(), csum);
     }
@@ -165,9 +131,9 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // write out initial test block
       auto t = get_transaction();
-      auto extent = cache.alloc_new_extent<CacheTestBlock>(
+      auto extent = cache.alloc_new_extent<TestBlock>(
        *t,
-       CacheTestBlock::SIZE);
+       TestBlock::SIZE);
       extent->set_contents('c');
       csum = extent->checksum();
       auto reladdr = extent->get_paddr();
@@ -175,10 +141,10 @@ TEST_F(cache_test_t, test_dirty_extent)
       {
        // test that read with same transaction sees new block though
        // uncommitted
-       auto extent = cache.get_extent<CacheTestBlock>(
+       auto extent = cache.get_extent<TestBlock>(
          *t,
          reladdr,
-         CacheTestBlock::SIZE).unsafe_get0();
+         TestBlock::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_clean());
        ASSERT_TRUE(extent->is_pending());
        ASSERT_TRUE(extent->get_paddr().is_relative());
@@ -192,26 +158,26 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // test that consecutive reads on the same extent get the same ref
       auto t = get_transaction();
-      auto extent = cache.get_extent<CacheTestBlock>(
+      auto extent = cache.get_extent<TestBlock>(
        *t,
        addr,
-       CacheTestBlock::SIZE).unsafe_get0();
+       TestBlock::SIZE).unsafe_get0();
       auto t2 = get_transaction();
-      auto extent2 = cache.get_extent<CacheTestBlock>(
+      auto extent2 = cache.get_extent<TestBlock>(
        *t2,
        addr,
-       CacheTestBlock::SIZE).unsafe_get0();
+       TestBlock::SIZE).unsafe_get0();
       ASSERT_EQ(&*extent, &*extent2);
     }
     {
       // read back test block
       auto t = get_transaction();
-      auto extent = cache.get_extent<CacheTestBlock>(
+      auto extent = cache.get_extent<TestBlock>(
        *t,
        addr,
-       CacheTestBlock::SIZE).unsafe_get0();
+       TestBlock::SIZE).unsafe_get0();
       // duplicate and reset contents
-      extent = cache.duplicate_for_write(*t, extent)->cast<CacheTestBlock>();
+      extent = cache.duplicate_for_write(*t, extent)->cast<TestBlock>();
       extent->set_contents('c');
       csum2 = extent->checksum();
       ASSERT_EQ(extent->get_paddr(), addr);
@@ -219,10 +185,10 @@ TEST_F(cache_test_t, test_dirty_extent)
        // test that concurrent read with fresh transaction sees old
         // block
        auto t2 = get_transaction();
-       auto extent = cache.get_extent<CacheTestBlock>(
+       auto extent = cache.get_extent<TestBlock>(
          *t2,
          addr,
-         CacheTestBlock::SIZE).unsafe_get0();
+         TestBlock::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_clean());
        ASSERT_FALSE(extent->is_pending());
        ASSERT_EQ(addr, extent->get_paddr());
@@ -231,10 +197,10 @@ TEST_F(cache_test_t, test_dirty_extent)
       }
       {
        // test that read with same transaction sees new block
-       auto extent = cache.get_extent<CacheTestBlock>(
+       auto extent = cache.get_extent<TestBlock>(
          *t,
          addr,
-         CacheTestBlock::SIZE).unsafe_get0();
+         TestBlock::SIZE).unsafe_get0();
        ASSERT_TRUE(extent->is_dirty());
        ASSERT_TRUE(extent->is_pending());
        ASSERT_EQ(addr, extent->get_paddr());
@@ -252,10 +218,10 @@ TEST_F(cache_test_t, test_dirty_extent)
     {
       // test that fresh transaction now sees newly dirty block
       auto t = get_transaction();
-      auto extent = cache.get_extent<CacheTestBlock>(
+      auto extent = cache.get_extent<TestBlock>(
        *t,
        addr,
-       CacheTestBlock::SIZE).unsafe_get0();
+       TestBlock::SIZE).unsafe_get0();
       ASSERT_TRUE(extent->is_dirty());
       ASSERT_EQ(addr, extent->get_paddr());
       ASSERT_EQ(extent->get_version(), 1);
index e0d8ef7f694c5be30568c208de3d466638a4e154..7ef6187183f6060b8d20330cf15f54c3337e4644 100644 (file)
@@ -7,6 +7,8 @@
 #include "crimson/os/seastore/transaction_manager.h"
 #include "crimson/os/seastore/segment_manager.h"
 
+#include "test/crimson/seastore/test_block.h"
+
 using namespace crimson;
 using namespace crimson::os;
 using namespace crimson::os::seastore;
@@ -17,24 +19,6 @@ namespace {
   }
 }
 
-struct test_extent_desc_t {
-  size_t len = 0;
-  unsigned checksum = 0;
-
-  bool operator==(const test_extent_desc_t &rhs) const {
-    return (len == rhs.len &&
-           checksum == rhs.checksum);
-  }
-  bool operator!=(const test_extent_desc_t &rhs) const {
-    return !(*this == rhs);
-  }
-};
-
-std::ostream &operator<<(std::ostream &lhs, const test_extent_desc_t &rhs) {
-  return lhs << "test_extent_desc_t(len=" << rhs.len
-            << ", checksum=" << rhs.checksum << ")";
-}
-
 struct test_extent_record_t {
   test_extent_desc_t desc;
   unsigned refcount = 0;
@@ -60,40 +44,6 @@ std::ostream &operator<<(std::ostream &lhs, const test_extent_record_t &rhs) {
             << ", refcount=" << rhs.refcount << ")";
 }
 
-
-struct TestBlock : LogicalCachedExtent {
-  using Ref = TCachedExtentRef<TestBlock>;
-
-  TestBlock(ceph::bufferptr &&ptr) : LogicalCachedExtent(std::move(ptr)) {}
-  TestBlock(const TestBlock &other) : LogicalCachedExtent(other) {}
-
-  CachedExtentRef duplicate_for_write() final {
-    return CachedExtentRef(new TestBlock(*this));
-  };
-
-  static constexpr extent_types_t TYPE = extent_types_t::TEST_BLOCK;
-  extent_types_t get_type() const final {
-    return TYPE;
-  }
-
-  ceph::bufferlist get_delta() final {
-    return ceph::bufferlist();
-  }
-
-  void set_contents(char c) {
-    ::memset(get_bptr().c_str(), c, get_length());
-  }
-
-  test_extent_desc_t get_desc() {
-    return { get_length(), get_crc32c(1) };
-  }
-
-  void apply_delta(paddr_t delta_base, ceph::bufferlist &bl) final {
-    ceph_assert(0 == "TODO");
-  }
-};
-using TestBlockRef = TCachedExtentRef<TestBlock>;
-
 struct transaction_manager_test_t : public seastar_test_suite_t {
   std::unique_ptr<SegmentManager> segment_manager;
   Journal journal;
@@ -129,6 +79,7 @@ struct transaction_manager_test_t : public seastar_test_suite_t {
       })
     );
   }
+
   struct test_extents_t : std::map<laddr_t, test_extent_record_t> {
   private:
     void check_available(laddr_t addr, extent_len_t len) {