Add a space map unit test that creates a metadata sm and a disk sm

This commit is contained in:
Joe Thornber 2013-04-11 14:01:54 +01:00
parent dde775ef52
commit bf75b5c827
2 changed files with 25 additions and 1 deletions

View File

@ -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<sm_metadata_creator>();
}
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);
}
//----------------------------------------------------------------

View File

@ -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));
}
//----------------------------------------------------------------