Small work on metadata_checker tests.

This commit is contained in:
Joe Thornber 2013-04-26 15:55:45 +01:00
parent b1e0ca2207
commit 441cba7185
5 changed files with 17 additions and 4 deletions

View File

@ -11,7 +11,7 @@ namespace {
unsigned const SECTOR_TO_BLOCK_SHIFT = 3;
uint32_t const SUPERBLOCK_CSUM_SEED = 160774;
struct validator : public block_manager<>::validator {
struct sb_validator : public block_manager<>::validator {
virtual void check(buffer<> const &b, block_address location) const {
superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&b);
crc32c sum(SUPERBLOCK_CSUM_SEED);
@ -34,7 +34,7 @@ namespace {
block_manager<>::validator::ptr
thin_provisioning::superblock_validator()
{
return block_manager<>::validator::ptr(new validator);
return block_manager<>::validator::ptr(new sb_validator);
}
//----------------------------------------------------------------

View File

@ -40,6 +40,7 @@ lib/libgmock.a: $(GMOCK_DEPS)
TEST_SOURCE=\
unit-tests/gmock_main.cc \
unit-tests/test_utils.cc \
\
unit-tests/array_block_t.cc \
unit-tests/array_t.cc \

View File

@ -120,8 +120,7 @@ namespace {
}
void corrupt_superblock() {
block_manager<>::write_ref wr = bm_->write_lock(0);
wr.data()[57] = 0;
zero_block(bm_, SUPERBLOCK_LOCATION);
}
with_temp_directory dir_;

11
unit-tests/test_utils.cc Normal file
View File

@ -0,0 +1,11 @@
#include "test_utils.h"
//----------------------------------------------------------------
void test::zero_block(block_manager<>::ptr bm, block_address b)
{
block_manager<>::write_ref wr = bm->write_lock(b);
memset(&wr.data(), 0, sizeof(wr.data()));
}
//----------------------------------------------------------------

View File

@ -35,6 +35,8 @@ namespace test {
new block_manager<BlockSize>(path, nr, MAX_HELD_LOCKS,
block_io<BlockSize>::CREATE));
}
void zero_block(block_manager<>::ptr bm, block_address b);
}
//----------------------------------------------------------------