Convert bitset_t to gmock

This commit is contained in:
Joe Thornber
2013-03-22 14:36:31 +00:00
parent 1e141f83bb
commit 0a70c17268
9 changed files with 58 additions and 68 deletions

View File

@ -64,11 +64,6 @@ namespace persistent_data {
unsigned nr_entries_in_last_block;
unsigned nr_total_blocks;
};
unsigned calc_max_entries(size_t value_size, size_t block_size)
{
return (block_size - sizeof(struct array_block_disk)) / value_size;
}
}
template <typename ValueTraits>

View File

@ -27,7 +27,7 @@
namespace persistent_data {
namespace bitset_detail {
struct bitset_traits {
typedef base::__le64 disk_type;
typedef base::le64 disk_type;
typedef uint64_t value_type;
typedef no_op_ref_counter<uint64_t> ref_counter;
@ -36,7 +36,7 @@ namespace persistent_data {
}
static void pack(value_type const &value, disk_type &disk) {
disk = base::to_disk<base::__le64>(value);
disk = base::to_disk<base::le64>(value);
}
};
}

View File

@ -25,7 +25,7 @@ using namespace base;
bool
base::test_bit_le(void const *bits, unsigned b)
{
__le64 const *w = reinterpret_cast<__le64 const *>(bits);
le64 const *w = reinterpret_cast<le64 const *>(bits);
w += b / 64;
uint64_t v = to_cpu<uint64_t>(*w);
@ -37,20 +37,20 @@ base::test_bit_le(void const *bits, unsigned b)
void
base::set_bit_le(void *bits, unsigned b)
{
__le64 *w = reinterpret_cast<__le64 *>(bits);
le64 *w = reinterpret_cast<le64 *>(bits);
w += b / 64;
uint64_t v = to_cpu<uint64_t>(*w);
uint64_t mask = 1;
mask = mask << (b % 64);
v |= mask;
*w = to_disk<__le64>(v);
*w = to_disk<le64>(v);
}
void
base::clear_bit_le(void *bits, unsigned b)
{
__le64 *w = reinterpret_cast<__le64 *>(bits);
le64 *w = reinterpret_cast<le64 *>(bits);
w += b / 64;
uint64_t v = to_cpu<uint64_t>(*w);
@ -58,7 +58,7 @@ base::clear_bit_le(void *bits, unsigned b)
mask = mask << (b % 64);
mask = ~mask;
v &= mask;
*w = to_disk<__le64>(v);
*w = to_disk<le64>(v);
}
//----------------------------------------------------------------

View File

@ -51,11 +51,11 @@ namespace {
virtual void prepare(buffer<> &b, block_address location) const {
bitmap_header *data = reinterpret_cast<bitmap_header *>(&b);
data->blocknr = to_disk<base::__le64, uint64_t>(location);
data->blocknr = to_disk<base::le64, uint64_t>(location);
crc32c sum(BITMAP_CSUM_XOR);
sum.append(&data->not_used, MD_BLOCK_SIZE - sizeof(uint32_t));
data->csum = to_disk<base::__le32>(sum.get_sum());
data->csum = to_disk<base::le32>(sum.get_sum());
}
};
@ -83,11 +83,11 @@ namespace {
virtual void prepare(buffer<> &b, block_address location) const {
metadata_index *mi = reinterpret_cast<metadata_index *>(&b);
mi->blocknr_ = to_disk<base::__le64, uint64_t>(location);
mi->blocknr_ = to_disk<base::le64, uint64_t>(location);
crc32c sum(INDEX_CSUM_XOR);
sum.append(&mi->padding_, MD_BLOCK_SIZE - sizeof(uint32_t));
mi->csum_ = to_disk<base::__le32>(sum.get_sum());
mi->csum_ = to_disk<base::le32>(sum.get_sum());
}
};
@ -194,7 +194,7 @@ namespace {
};
struct ref_count_traits {
typedef __le32 disk_type;
typedef le32 disk_type;
typedef uint32_t value_type;
typedef no_op_ref_counter<uint32_t> ref_counter;

View File

@ -31,9 +31,9 @@ namespace persistent_data {
namespace sm_disk_detail {
struct index_entry_disk {
__le64 blocknr_;
__le32 nr_free_;
__le32 none_free_before_;
le64 blocknr_;
le32 nr_free_;
le32 none_free_before_;
} __attribute__ ((packed));
struct index_entry {
@ -54,9 +54,9 @@ namespace persistent_data {
}
static void pack(value_type const &value, disk_type &disk) {
disk.blocknr_ = to_disk<__le64>(value.blocknr_);
disk.nr_free_ = to_disk<__le32>(value.nr_free_);
disk.none_free_before_ = to_disk<__le32>(value.none_free_before_);
disk.blocknr_ = to_disk<le64>(value.blocknr_);
disk.nr_free_ = to_disk<le32>(value.nr_free_);
disk.none_free_before_ = to_disk<le32>(value.none_free_before_);
}
};
@ -64,18 +64,18 @@ namespace persistent_data {
unsigned const ENTRIES_PER_BYTE = 4;
struct metadata_index {
__le32 csum_;
__le32 padding_;
__le64 blocknr_;
le32 csum_;
le32 padding_;
le64 blocknr_;
struct index_entry_disk index[MAX_METADATA_BITMAPS];
} __attribute__ ((packed));
struct sm_root_disk {
__le64 nr_blocks_;
__le64 nr_allocated_;
__le64 bitmap_root_;
__le64 ref_count_root_;
le64 nr_blocks_;
le64 nr_allocated_;
le64 bitmap_root_;
le64 ref_count_root_;
} __attribute__ ((packed));
struct sm_root {
@ -98,17 +98,17 @@ namespace persistent_data {
}
static void pack(value_type const &value, disk_type &disk) {
disk.nr_blocks_ = to_disk<__le64>(value.nr_blocks_);
disk.nr_allocated_ = to_disk<__le64>(value.nr_allocated_);
disk.bitmap_root_ = to_disk<__le64>(value.bitmap_root_);
disk.ref_count_root_ = to_disk<__le64>(value.ref_count_root_);
disk.nr_blocks_ = to_disk<le64>(value.nr_blocks_);
disk.nr_allocated_ = to_disk<le64>(value.nr_allocated_);
disk.bitmap_root_ = to_disk<le64>(value.bitmap_root_);
disk.ref_count_root_ = to_disk<le64>(value.ref_count_root_);
}
};
struct bitmap_header {
__le32 csum;
__le32 not_used;
__le64 blocknr;
le32 csum;
le32 not_used;
le64 blocknr;
} __attribute__ ((packed));
}
}