test_librbd: add a simple io to clone test

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
This commit is contained in:
Josh Durgin 2012-07-30 10:41:41 -07:00
parent 12c9a7d5df
commit 965271dbec
2 changed files with 22 additions and 1 deletions

View File

@ -429,6 +429,16 @@ class TestClone(object):
eq(self.clone.overlap(), IMG_SIZE / 2)
def test_resize_io(self):
parent_data = self.image.read(IMG_SIZE / 2, 256)
self.clone.resize(IMG_SIZE / 2 + 128)
child_data = self.clone.read(IMG_SIZE / 2, 128)
eq(child_data, parent_data[:128])
self.clone.resize(IMG_SIZE)
child_data = self.clone.read(IMG_SIZE / 2, 256)
eq(child_data, parent_data[:128] + ('\0' * 128))
self.clone.resize(IMG_SIZE / 2 + 1)
child_data = self.clone.read(IMG_SIZE / 2, 1)
eq(child_data, parent_data[0])
self.clone.resize(0)
self.clone.resize(IMG_SIZE)
child_data = self.clone.read(IMG_SIZE / 2, 256)

View File

@ -989,6 +989,9 @@ TEST(LibRBD, TestClone)
ASSERT_EQ(0, rbd_open(ioctx, "parent", &parent, NULL));
printf("made parent image \"parent\"\n");
char *data = (char *)"testdata";
ASSERT_EQ((ssize_t)strlen(data), rbd_write(parent, 0, strlen(data), data));
// can't clone a non-snapshot, expect failure
EXPECT_NE(0, rbd_clone(ioctx, "parent", NULL, ioctx, "child", features, &order));
@ -1004,7 +1007,15 @@ TEST(LibRBD, TestClone)
ASSERT_EQ(0, rbd_clone(ioctx, "parent", "parent_snap", ioctx, "child", features,
&order));
ASSERT_EQ(0, rbd_open(ioctx, "child", &child, NULL));
printf("made and opened clone \"child\"\n");
printf("made and opened clone \"child\"\n");
// check read
read_test_data(child, data, 0, strlen(data));
// check write
ASSERT_EQ((ssize_t)strlen(data), rbd_write(child, 20, strlen(data), data));
read_test_data(child, data, 20, strlen(data));
read_test_data(child, data, 0, strlen(data));
// check attributes
ASSERT_EQ(0, rbd_stat(parent, &pinfo, sizeof(pinfo)));