Skip to content

Commit

Permalink
os/bluestore: add ut test cases for different zone sizes
Browse files Browse the repository at this point in the history
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Jun 26, 2016
1 parent 71ee5ca commit 8a8260f
Showing 1 changed file with 108 additions and 104 deletions.
212 changes: 108 additions & 104 deletions src/test/objectstore/BitAllocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,138 +344,142 @@ TEST(BitAllocator, test_zone_alloc)

TEST(BitAllocator, test_bmap_alloc)
{
int64_t total_blocks = 1024 * 4;
int64_t zone_size = 1024;
int64_t allocated = 0;
int64_t start_block = 0;

BitAllocator *alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
for (int round = 0; round < 3; round++) {
// Test zone of different sizes: 512, 1024, 2048
int64_t zone_size = 512ull << round;
int64_t total_blocks = 1024 * 4;
int64_t allocated = 0;
int64_t start_block = 0;

for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}
BitAllocator *alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);

for (int64_t i = 0; i < total_blocks; i++) {
alloc->free_blocks(i, 1);
}
}
for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}

for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks / zone_size; i++) {
allocated = alloc->alloc_blocks(zone_size, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == i * zone_size);
for (int64_t i = 0; i < total_blocks; i++) {
alloc->free_blocks(i, 1);
}
}

for (int64_t i = 0; i < total_blocks / zone_size; i++) {
alloc->free_blocks(i * zone_size, zone_size);
for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks / zone_size; i++) {
allocated = alloc->alloc_blocks(zone_size, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == i * zone_size);
}

for (int64_t i = 0; i < total_blocks / zone_size; i++) {
alloc->free_blocks(i * zone_size, zone_size);
}
}
}

allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);

allocated = alloc->alloc_blocks(zone_size - 1, &start_block);
bmap_test_assert(allocated == zone_size - 1);
bmap_test_assert(start_block == 1);
allocated = alloc->alloc_blocks(zone_size - 1, &start_block);
bmap_test_assert(allocated == zone_size - 1);
bmap_test_assert(start_block == 1);

allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);

allocated = alloc->alloc_blocks(zone_size, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == zone_size * 2);
allocated = alloc->alloc_blocks(zone_size, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == zone_size * 2);

// Dis contiguous blocks allocations
delete alloc;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
// Dis contiguous blocks allocations
delete alloc;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);

for (int64_t i = 0; i < alloc->size(); i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
}
for (int i = 0; i < alloc->size(); i += 2) {
alloc->free_blocks(i, 1);
}
for (int64_t i = 0; i < alloc->size(); i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
}
for (int i = 0; i < alloc->size(); i += 2) {
alloc->free_blocks(i, 1);
}

int64_t blocks[alloc->size() / 2];
memset(blocks, 0, sizeof(blocks));
allocated = alloc->alloc_blocks_dis(alloc->size()/2, blocks);
bmap_test_assert(allocated == alloc->size() / 2);
int64_t blocks[alloc->size() / 2];
memset(blocks, 0, sizeof(blocks));
allocated = alloc->alloc_blocks_dis(alloc->size()/2, blocks);
bmap_test_assert(allocated == alloc->size() / 2);

allocated = alloc->alloc_blocks_dis(1, blocks);
bmap_test_assert(allocated == 0);
allocated = alloc->alloc_blocks_dis(1, blocks);
bmap_test_assert(allocated == 0);

alloc->free_blocks(alloc->size()/2, 1);
allocated = alloc->alloc_blocks_dis(1, blocks);
alloc->free_blocks(alloc->size()/2, 1);
allocated = alloc->alloc_blocks_dis(1, blocks);

bmap_test_assert(allocated == 1);
bmap_test_assert(blocks[0] == alloc->size()/2);
bmap_test_assert(allocated == 1);
bmap_test_assert(blocks[0] == alloc->size()/2);

alloc->free_blocks(0, alloc->size());
delete alloc;
alloc->free_blocks(0, alloc->size());
delete alloc;

// unaligned zones
total_blocks = 1024 * 2 + 11;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
// unaligned zones
total_blocks = 1024 * 2 + 11;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);

for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}
for (int64_t iter = 0; iter < 4; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
allocated = alloc->alloc_blocks(1, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}

for (int64_t i = 0; i < total_blocks; i++) {
alloc->free_blocks(i, 1);
}
}
delete alloc;

// Make three > 3 levels tree and check allocations and dealloc
// in a loop
int64_t alloc_size = 16;
total_blocks = pow(zone_size, 2) * 4;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT, false);
for (int64_t iter = 0; iter < 3; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
allocated = alloc->alloc_blocks(alloc_size, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
for (int64_t i = 0; i < total_blocks; i++) {
alloc->free_blocks(i, 1);
}
}
delete alloc;

// Make three > 3 levels tree and check allocations and dealloc
// in a loop
int64_t alloc_size = 16;
total_blocks = pow(zone_size, 2) * 4;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT, false);
for (int64_t iter = 0; iter < 3; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
allocated = alloc->alloc_blocks(alloc_size, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
}

for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
alloc->free_blocks(i * alloc_size, alloc_size);
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
alloc->free_blocks(i * alloc_size, alloc_size);
}
}
}

delete alloc;
alloc = new BitAllocator(1024, zone_size, CONCURRENT, true);

alloc->free_blocks(1, 1023);
alloc->alloc_blocks(16, &start_block);
delete alloc;

total_blocks = pow(zone_size, 2) * 4;
alloc_size = 16;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT, false);
for (int64_t iter = 0; iter < 3; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
bmap_test_assert(alloc->reserve_blocks(alloc_size));
allocated = alloc->alloc_blocks_res(alloc_size, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
}
delete alloc;
alloc = new BitAllocator(1024, zone_size, CONCURRENT, true);

alloc->free_blocks(1, 1023);
alloc->alloc_blocks(16, &start_block);
delete alloc;

total_blocks = pow(zone_size, 2) * 4;
alloc_size = 16;
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT, false);
for (int64_t iter = 0; iter < 3; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
bmap_test_assert(alloc->reserve_blocks(alloc_size));
allocated = alloc->alloc_blocks_res(alloc_size, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
}

for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
alloc->free_blocks(i * alloc_size, alloc_size);
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
alloc->free_blocks(i * alloc_size, alloc_size);
}
}
}

delete alloc;
delete alloc;
}
}

void
Expand Down

0 comments on commit 8a8260f

Please sign in to comment.