From: Jason Dillaman Date: Fri, 24 Apr 2015 03:10:23 +0000 (-0400) Subject: tests: fix valgrind errors with librbd unit test X-Git-Tag: v9.0.1~47^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ed5472a10eb515e2a177a640c3f6ed929db9ee4f;p=ceph.git tests: fix valgrind errors with librbd unit test Signed-off-by: Jason Dillaman --- diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index 14871295b05f..4dc196a6db23 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -180,7 +180,7 @@ public: } m_aio_completions.erase(aio_completion); - delete aio_completion; + aio_completion->release(); } m_callback_cond.Signal(); diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 5c90e9030a05..c57792f5eb8d 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -250,12 +250,17 @@ TEST_F(TestInternal, AioWriteRequestsLock) { DummyContext *ctx = new DummyContext(); librbd::AioCompletion *c = librbd::aio_create_completion_internal(ctx, librbd::rbd_ctx_cb); + c->get(); ASSERT_EQ(0, aio_write(ictx, 0, buffer.size(), buffer.c_str(), c, 0)); bool is_owner; ASSERT_EQ(0, librbd::is_exclusive_lock_owner(ictx, &is_owner)); ASSERT_FALSE(is_owner); ASSERT_FALSE(c->is_complete()); + + unlock_image(); + ASSERT_EQ(0, c->wait_for_complete()); + c->put(); } TEST_F(TestInternal, AioDiscardRequestsLock) { @@ -268,12 +273,17 @@ TEST_F(TestInternal, AioDiscardRequestsLock) { DummyContext *ctx = new DummyContext(); librbd::AioCompletion *c = librbd::aio_create_completion_internal(ctx, librbd::rbd_ctx_cb); + c->get(); ASSERT_EQ(0, aio_discard(ictx, 0, 256, c)); bool is_owner; ASSERT_EQ(0, librbd::is_exclusive_lock_owner(ictx, &is_owner)); ASSERT_FALSE(is_owner); ASSERT_FALSE(c->is_complete()); + + unlock_image(); + ASSERT_EQ(0, c->wait_for_complete()); + c->put(); } TEST_F(TestInternal, CancelAsyncResize) { diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 99aef663665d..22a8729e5f4c 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -145,10 +145,12 @@ public: _unique_pool_names.clear(); _image_number = 0; ASSERT_EQ("", connect_cluster(&_cluster)); + ASSERT_EQ("", connect_cluster_pp(_rados)); } static void TearDownTestCase() { rados_shutdown(_cluster); + _rados.wait_for_latest_osdmap(); _pool_names.insert(_pool_names.end(), _unique_pool_names.begin(), _unique_pool_names.end()); for (size_t i = 1; i < _pool_names.size(); ++i) { @@ -181,16 +183,17 @@ public: } std::string create_pool(bool unique = false) { + librados::Rados rados; std::string pool_name; if (unique) { pool_name = get_temp_pool_name(); - EXPECT_EQ("", create_one_pool_pp(pool_name, _rados)); + EXPECT_EQ("", create_one_pool_pp(pool_name, rados)); _unique_pool_names.push_back(pool_name); } else if (m_pool_number < _pool_names.size()) { pool_name = _pool_names[m_pool_number]; } else { pool_name = get_temp_pool_name(); - EXPECT_EQ("", create_one_pool_pp(pool_name, _rados)); + EXPECT_EQ("", create_one_pool_pp(pool_name, rados)); _pool_names.push_back(pool_name); } ++m_pool_number; @@ -837,6 +840,7 @@ TEST_F(TestLibRBD, TestIO) rbd_aio_create_completion(NULL, (rbd_callback_t) simple_read_cb, &comp); ASSERT_EQ(-EINVAL, rbd_aio_write(image, info.size, 1, test_data, comp)); ASSERT_EQ(-EINVAL, rbd_aio_read(image, info.size, 1, test_data, comp)); + rbd_aio_release(comp); ASSERT_PASSED(validate_object_map, image); ASSERT_EQ(0, rbd_close(image)); @@ -914,6 +918,7 @@ TEST_F(TestLibRBD, TestIOWithIOHint) ASSERT_EQ(-EINVAL, rbd_aio_write(image, info.size, 1, test_data, comp)); ASSERT_EQ(-EINVAL, rbd_aio_read2(image, info.size, 1, test_data, comp, LIBRADOS_OP_FLAG_FADVISE_DONTNEED)); + rbd_aio_release(comp); ASSERT_PASSED(validate_object_map, image); ASSERT_EQ(0, rbd_close(image)); @@ -1121,6 +1126,7 @@ TEST_F(TestLibRBD, TestIOPPWithIOHint) ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), NULL)); char test_data[TEST_IO_SIZE + 1]; + test_data[TEST_IO_SIZE] = '\0'; int i; for (i = 0; i < TEST_IO_SIZE; ++i) { @@ -1954,14 +1960,15 @@ TEST_F(TestLibRBD, FlushAioPP) for (i = 0; i < TEST_IO_SIZE; ++i) { test_data[i] = (char) (rand() % (126 - 33) + 33); } + test_data[TEST_IO_SIZE] = '\0'; librbd::RBD::AioCompletion *write_comps[num_aios]; + ceph::bufferlist bls[num_aios]; for (i = 0; i < num_aios; ++i) { - ceph::bufferlist bl; - bl.append(test_data, strlen(test_data)); + bls[i].append(test_data, strlen(test_data)); write_comps[i] = new librbd::RBD::AioCompletion(NULL, NULL); uint64_t offset = rand() % (size - TEST_IO_SIZE); - ASSERT_EQ(0, image.aio_write(offset, TEST_IO_SIZE, bl, + ASSERT_EQ(0, image.aio_write(offset, TEST_IO_SIZE, bls[i], write_comps[i])); }