From bf75b5c827dc18a3dbfc2113ea32795986f0527a Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 11 Apr 2013 14:01:54 +0100 Subject: [PATCH] Add a space map unit test that creates a metadata sm and a disk sm --- unit-tests/space_map_t.cc | 22 ++++++++++++++++++++++ unit-tests/thin_metadata_t.cc | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/unit-tests/space_map_t.cc b/unit-tests/space_map_t.cc index 1e002a1..daeef10 100644 --- a/unit-tests/space_map_t.cc +++ b/unit-tests/space_map_t.cc @@ -254,6 +254,15 @@ namespace { test_set_affects_nr_allocated, test_high_ref_counts }; + + void + copy_space_maps(space_map::ptr lhs, space_map::ptr rhs) { + for (block_address b = 0; b < rhs->get_nr_blocks(); b++) { + uint32_t count = rhs->get_count(b); + if (count > 0) + lhs->set_count(b, rhs->get_count(b)); + } + } } //---------------------------------------------------------------- @@ -285,4 +294,17 @@ TEST(SpaceMapTests, test_sm_metadata) test_sm_reopen(); } +TEST(SpaceMapTests, test_metadata_and_disk) +{ + block_manager<>::ptr bm( + new block_manager<>("./test.data", NR_BLOCKS, MAX_LOCKS, block_io<>::READ_WRITE)); + space_map::ptr core_sm(new core_map(NR_BLOCKS)); + transaction_manager::ptr tm(new transaction_manager(bm, core_sm)); + persistent_space_map::ptr metadata_sm = persistent_data::create_metadata_sm(tm, NR_BLOCKS); + copy_space_maps(metadata_sm, core_sm); + tm->set_sm(metadata_sm); + + persistent_space_map::ptr data_sm_ = create_disk_sm(tm, NR_BLOCKS * 2); +} + //---------------------------------------------------------------- diff --git a/unit-tests/thin_metadata_t.cc b/unit-tests/thin_metadata_t.cc index a7c69b4..f28fb33 100644 --- a/unit-tests/thin_metadata_t.cc +++ b/unit-tests/thin_metadata_t.cc @@ -17,6 +17,7 @@ using namespace thin_provisioning; //---------------------------------------------------------------- namespace { + // FIXME: duplication with block.tcc, factor out a file_utils unit void rm_f(string path) { struct stat info; int r = ::stat(path.c_str(), &info); @@ -37,7 +38,6 @@ namespace { ::unlink(path.c_str()); } - // FIXME: duplication with block.tcc, factor out a file_utils unit void create_sized_file(string const &path, uint64_t file_size) { int fd = ::open(path.c_str(), O_CREAT | O_TRUNC | O_RDWR, 0666); if (fd < 0) @@ -68,3 +68,5 @@ TEST(ThinMetadataTests, create) create_sized_file(path, 4096 * 1024); metadata::ptr md(new metadata(path, metadata::CREATE, 128, 102400)); } + +//----------------------------------------------------------------