[mempool] more tests
This commit is contained in:
parent
73a69abfd2
commit
34c039d7dc
@ -33,16 +33,16 @@ copier::issue(copy_op const &op)
|
|||||||
throw runtime_error("couldn't allocate buffer");
|
throw runtime_error("couldn't allocate buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_job job(op, *data);
|
copy_job job(op, data);
|
||||||
job.op.read_complete = job.op.write_complete = false;
|
job.op.read_complete = job.op.write_complete = false;
|
||||||
unsigned key = genkey(); // used as context for the io_engine
|
unsigned key = genkey(); // used as context for the io_engine
|
||||||
|
|
||||||
cerr << "data = " << &(*data) << "\n";
|
cerr << "data = " << data << "\n";
|
||||||
engine_.issue_io(src_handle_,
|
engine_.issue_io(src_handle_,
|
||||||
io_engine::READ,
|
io_engine::READ,
|
||||||
to_sector(op.src_b),
|
to_sector(op.src_b),
|
||||||
to_sector(op.src_e),
|
to_sector(op.src_e),
|
||||||
*data,
|
data,
|
||||||
key);
|
key);
|
||||||
jobs_.insert(make_pair(key, job));
|
jobs_.insert(make_pair(key, job));
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,15 @@ mempool::~mempool()
|
|||||||
::free(mem_);
|
::free(mem_);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<void *>
|
void *
|
||||||
mempool::alloc()
|
mempool::alloc()
|
||||||
{
|
{
|
||||||
if (free_.empty())
|
if (free_.empty())
|
||||||
return optional<void *>();
|
return nullptr;
|
||||||
|
|
||||||
mempool_detail::alloc_block &b = free_.front();
|
mempool_detail::alloc_block &b = free_.front();
|
||||||
free_.pop_front();
|
free_.pop_front();
|
||||||
return optional<void *>(reinterpret_cast<void *>(&b));
|
return reinterpret_cast<void *>(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -23,7 +23,7 @@ namespace bcache {
|
|||||||
mempool(size_t block_size, size_t total_mem, size_t alignment = 8);
|
mempool(size_t block_size, size_t total_mem, size_t alignment = 8);
|
||||||
~mempool();
|
~mempool();
|
||||||
|
|
||||||
boost::optional<void *> alloc();
|
void *alloc();
|
||||||
void free(void *data);
|
void free(void *data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -65,7 +65,7 @@ TEST_F(MempoolTests, alignments_observed)
|
|||||||
if (!md)
|
if (!md)
|
||||||
throw runtime_error("couldn't alloc");
|
throw runtime_error("couldn't alloc");
|
||||||
|
|
||||||
ASSERT_THAT(aligned(*md, bs), Eq(true));
|
ASSERT_TRUE(aligned(md, bs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ TEST_F(MempoolTests, alloc_free_cycle)
|
|||||||
|
|
||||||
for (unsigned i = 0; i < 10000; i++) {
|
for (unsigned i = 0; i < 10000; i++) {
|
||||||
auto md = mp.alloc();
|
auto md = mp.alloc();
|
||||||
mp.free(*md);
|
mp.free(md);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +86,11 @@ TEST_F(MempoolTests, exhaust_pool)
|
|||||||
|
|
||||||
for (unsigned i = 0; i < 100; i++) {
|
for (unsigned i = 0; i < 100; i++) {
|
||||||
auto md = mp.alloc();
|
auto md = mp.alloc();
|
||||||
|
ASSERT_NE(md, nullptr);
|
||||||
ASSERT_THAT(*md, NEq(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto md = mp.alloc();
|
auto md = mp.alloc();
|
||||||
ASSERT(*md, Eq(0));
|
ASSERT_EQ(md, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user