]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: fix valgrind errors with librbd unit test
authorJason Dillaman <dillaman@redhat.com>
Fri, 24 Apr 2015 03:10:23 +0000 (23:10 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 28 Apr 2015 15:00:40 +0000 (11:00 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librbd/test_ImageWatcher.cc
src/test/librbd/test_internal.cc
src/test/librbd/test_librbd.cc

index 14871295b05fe1093037f73638ce4b872b7ae75f..4dc196a6db237b29636b44eeab960c2a67ae0e2b 100644 (file)
@@ -180,7 +180,7 @@ public:
       }
 
       m_aio_completions.erase(aio_completion);
-      delete aio_completion;
+      aio_completion->release();
     }
 
     m_callback_cond.Signal();
index 5c90e9030a0542530b9aa927a88d2b204ffb6ec5..c57792f5eb8d930b3238c6ce19eeca2919a47e32 100644 (file)
@@ -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) {
index 99aef663665dbbfcea4b5ef7b16c0e11b7f66928..22a8729e5f4c06eac5a1bbe46ae7d804b53e323a 100644 (file)
@@ -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]));
     }