--- /dev/null
+// -*- 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>;
+
+}
#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;
}
}
-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;
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();
}
{
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);
}
{
// 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();
{
// 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());
{
// 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);
// 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());
}
{
// 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());
{
// 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);
#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;
}
}
-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;
<< ", 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;
})
);
}
+
struct test_extents_t : std::map<laddr_t, test_extent_record_t> {
private:
void check_available(laddr_t addr, extent_len_t len) {