Skip to content

Commit

Permalink
tests: verify librbd blocking aio code path
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 4cf4148)
  • Loading branch information
Jason Dillaman committed Jun 5, 2015
1 parent d433c2c commit 9a5427f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/librbd/test_librbd.cc
Expand Up @@ -1973,6 +1973,65 @@ TEST(LibRBD, TestPendingAio)
ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
}

TEST(LibRBD, BlockingAIO)
{
librados::Rados rados;
librados::IoCtx ioctx;
string pool_name = get_temp_pool_name();

ASSERT_EQ("", create_one_pool_pp(pool_name, rados));
ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx));

librbd::RBD rbd;
std::string name = "testimg";
uint64_t size = 1 << 20;
int order = 18;
ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), size, &order));

CephContext *cct = reinterpret_cast<CephContext*>(ioctx.cct());
cct->_conf->set_val_or_die("rbd_non_blocking_aio", "0");

librbd::Image image;
ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), NULL));

bufferlist bl;
bl.append(std::string(256, '1'));

librbd::RBD::AioCompletion *write_comp =
new librbd::RBD::AioCompletion(NULL, NULL);
ASSERT_EQ(0, image.aio_write(0, bl.length(), bl, write_comp));

librbd::RBD::AioCompletion *flush_comp =
new librbd::RBD::AioCompletion(NULL, NULL);
ASSERT_EQ(0, image.aio_flush(flush_comp));
ASSERT_EQ(0, flush_comp->wait_for_complete());
ASSERT_EQ(0, flush_comp->get_return_value());
flush_comp->release();

ASSERT_EQ(1, write_comp->is_complete());
ASSERT_EQ(0, write_comp->get_return_value());
write_comp->release();

librbd::RBD::AioCompletion *discard_comp =
new librbd::RBD::AioCompletion(NULL, NULL);
ASSERT_EQ(0, image.aio_discard(128, 128, discard_comp));
ASSERT_EQ(0, discard_comp->wait_for_complete());
discard_comp->release();

librbd::RBD::AioCompletion *read_comp =
new librbd::RBD::AioCompletion(NULL, NULL);
bufferlist read_bl;
image.aio_read(0, bl.length(), read_bl, read_comp);
ASSERT_EQ(0, read_comp->wait_for_complete());
ASSERT_EQ(bl.length(), read_comp->get_return_value());
read_comp->release();

bufferlist expected_bl;
expected_bl.append(std::string(128, '1'));
expected_bl.append(std::string(128, '\0'));
ASSERT_TRUE(expected_bl.contents_equal(read_bl));
}

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 9a5427f

Please sign in to comment.