]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_memstore_clone: use StoreTestFixture to do the setup/teardown 11190/head
authorKefu Chai <kchai@redhat.com>
Thu, 22 Sep 2016 06:09:04 +0000 (14:09 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 22 Sep 2016 07:50:47 +0000 (15:50 +0800)
rename test case name from `MemStore` to `MemStoreClone`, because
if we use `TEST_F` to group the tests into a fixture, `MemStore`
will be used as the class name of the fixture, and hence conflicts
with the existing `MemStore` class under testing.

but the object store is created and destroyed for every test. before
this change, we do this for every test case. if it's a concern
we need to use SetUpTestCase() and TearDownTestCase() instead.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/objectstore/CMakeLists.txt
src/test/objectstore/test_memstore_clone.cc

index b839bd7bc53b82296528c3c8e216c9015a50782c..5f7bd290e804fd45f5978fe715d5a82363264111 100644 (file)
@@ -9,10 +9,13 @@ install(TARGETS ceph_perf_objectstore
   DESTINATION bin)
 
 #ceph_test_objectstore
+add_library(store_test_fixture OBJECT store_test_fixture.cc)
+set_target_properties(store_test_fixture PROPERTIES
+  COMPILE_FLAGS ${UNITTEST_CXX_FLAGS})
+
 add_executable(ceph_test_objectstore
   store_test.cc
-  store_test_fixture.cc
-  )
+  $<TARGET_OBJECTS:store_test_fixture>)
 set_target_properties(ceph_test_objectstore PROPERTIES COMPILE_FLAGS
   ${UNITTEST_CXX_FLAGS})
 target_link_libraries(ceph_test_objectstore
@@ -139,6 +142,8 @@ add_ceph_unittest(unittest_transaction ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittes
 target_link_libraries(unittest_transaction os common)
 
 # unittest_memstore_clone
-add_executable(unittest_memstore_clone test_memstore_clone.cc)
+add_executable(unittest_memstore_clone
+  test_memstore_clone.cc
+  $<TARGET_OBJECTS:store_test_fixture>)
 add_ceph_unittest(unittest_memstore_clone ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_memstore_clone)
 target_link_libraries(unittest_memstore_clone os global)
index bf5b63cb1c6dd984559d456687c0a84498576cf9..090c6f4bc1fbd2b611762126472d5bf4815a174e 100644 (file)
 #include <gtest/gtest.h>
 #include "include/assert.h"
 #include "common/errno.h"
+#include "store_test_fixture.h"
 
 namespace {
 
-ObjectStore *g_store{nullptr};
 const coll_t cid;
 
 ghobject_t make_ghobject(const char *oid)
@@ -31,12 +31,32 @@ ghobject_t make_ghobject(const char *oid)
 
 } // anonymous namespace
 
+class MemStoreClone : public StoreTestFixture {
+public:
+  MemStoreClone()
+    : StoreTestFixture("memstore")
+  {}
+  void SetUp() override {
+    StoreTestFixture::SetUp();
+    if (HasFailure()) {
+      return;
+    }
+    ObjectStore::Transaction t;
+    t.create_collection(cid, 4);
+    unsigned r = store->apply_transaction(nullptr, std::move(t));
+    if (r != 0) {
+      derr << "failed to create collection with " << cpp_strerror(r) << dendl;
+    }
+    ASSERT_EQ(0U, r);
+  }
+};
+
 // src 11[11 11 11 11]11
 // dst 22 22 22 22 22 22
 // res 22 11 11 11 11 22
-TEST(MemStore, CloneRangeAllocated)
+TEST_F(MemStoreClone, CloneRangeAllocated)
 {
-  ASSERT_TRUE(g_store);
+  ASSERT_TRUE(store);
 
   const auto src = make_ghobject("src1");
   const auto dst = make_ghobject("dst1");
@@ -50,17 +70,17 @@ TEST(MemStore, CloneRangeAllocated)
   t.write(cid, src, 0, 12, srcbl);
   t.write(cid, dst, 0, 12, dstbl);
   t.clone_range(cid, src, dst, 2, 8, 2);
-  ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
-  ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
+  ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
+  ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
   ASSERT_EQ(expected, result);
 }
 
 // src __[__ __ __ __]__ 11 11
 // dst 22 22 22 22 22 22
 // res 22 00 00 00 00 22
-TEST(MemStore, CloneRangeHole)
+TEST_F(MemStoreClone, CloneRangeHole)
 {
-  ASSERT_TRUE(g_store);
+  ASSERT_TRUE(store);
 
   const auto src = make_ghobject("src2");
   const auto dst = make_ghobject("dst2");
@@ -74,17 +94,17 @@ TEST(MemStore, CloneRangeHole)
   t.write(cid, src, 12, 4, srcbl);
   t.write(cid, dst, 0, 12, dstbl);
   t.clone_range(cid, src, dst, 2, 8, 2);
-  ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
-  ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
+  ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
+  ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
   ASSERT_EQ(expected, result);
 }
 
 // src __[__ __ __ 11]11
 // dst 22 22 22 22 22 22
 // res 22 00 00 00 11 22
-TEST(MemStore, CloneRangeHoleStart)
+TEST_F(MemStoreClone, CloneRangeHoleStart)
 {
-  ASSERT_TRUE(g_store);
+  ASSERT_TRUE(store);
 
   const auto src = make_ghobject("src3");
   const auto dst = make_ghobject("dst3");
@@ -98,17 +118,17 @@ TEST(MemStore, CloneRangeHoleStart)
   t.write(cid, src, 8, 4, srcbl);
   t.write(cid, dst, 0, 12, dstbl);
   t.clone_range(cid, src, dst, 2, 8, 2);
-  ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
-  ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
+  ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
+  ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
   ASSERT_EQ(expected, result);
 }
 
 // src 11[11 __ __ 11]11
 // dst 22 22 22 22 22 22
 // res 22 11 00 00 11 22
-TEST(MemStore, CloneRangeHoleMiddle)
+TEST_F(MemStoreClone, CloneRangeHoleMiddle)
 {
-  ASSERT_TRUE(g_store);
+  ASSERT_TRUE(store);
 
   const auto src = make_ghobject("src4");
   const auto dst = make_ghobject("dst4");
@@ -123,17 +143,17 @@ TEST(MemStore, CloneRangeHoleMiddle)
   t.write(cid, src, 8, 4, srcbl);
   t.write(cid, dst, 0, 12, dstbl);
   t.clone_range(cid, src, dst, 2, 8, 2);
-  ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
-  ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
+  ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
+  ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
   ASSERT_EQ(expected, result);
 }
 
 // src 11[11 __ __ __]__ 11 11
 // dst 22 22 22 22 22 22
 // res 22 11 00 00 00 22
-TEST(MemStore, CloneRangeHoleEnd)
+TEST_F(MemStoreClone, CloneRangeHoleEnd)
 {
-  ASSERT_TRUE(g_store);
+  ASSERT_TRUE(store);
 
   const auto src = make_ghobject("src5");
   const auto dst = make_ghobject("dst5");
@@ -148,8 +168,8 @@ TEST(MemStore, CloneRangeHoleEnd)
   t.write(cid, src, 12, 4, srcbl);
   t.write(cid, dst, 0, 12, dstbl);
   t.clone_range(cid, src, dst, 2, 8, 2);
-  ASSERT_EQ(0u, g_store->apply_transaction(nullptr, std::move(t)));
-  ASSERT_EQ(12, g_store->read(cid, dst, 0, 12, result));
+  ASSERT_EQ(0u, store->apply_transaction(nullptr, std::move(t)));
+  ASSERT_EQ(12, store->read(cid, dst, 0, 12, result));
   ASSERT_EQ(expected, result);
 }
 
@@ -162,7 +182,7 @@ int main(int argc, char** argv)
   // default to memstore
   vector<const char*> defaults{
     "--osd_objectstore", "memstore",
-    "--osd_data", "memstore_clone_temp_dir",
+    "--osd_data", "memstore.test_temp_dir",
     "--memstore_page_size", "4",
   };
 
@@ -176,49 +196,6 @@ int main(int argc, char** argv)
   // release g_ceph_context on exit
   boost::intrusive_ptr<CephContext> cct{g_ceph_context, false};
 
-  // create and mount the objectstore
-  std::unique_ptr<ObjectStore> store{ObjectStore::create(
-      g_ceph_context,
-      g_conf->osd_objectstore,
-      g_conf->osd_data,
-      g_conf->osd_journal,
-      g_conf->osd_os_flags)};
-  if (!store) {
-    derr << "failed to create osd_objectstore=" << g_conf->osd_objectstore << dendl;
-    return EXIT_FAILURE;
-  }
-
-  int r = store->mkfs();
-  if (r < 0) {
-    derr << "failed to mkfs with " << cpp_strerror(r) << dendl;
-    return EXIT_FAILURE;
-  }
-
-  r = store->mount();
-  if (r < 0) {
-    derr << "failed to mount with " << cpp_strerror(r) << dendl;
-    return EXIT_FAILURE;
-  }
-  g_store = store.get();
-
-  ObjectStore::Transaction t;
-  t.create_collection(cid, 4);
-  r = store->apply_transaction(nullptr, std::move(t));
-  if (r < 0) {
-    derr << "failed to create collection with " << cpp_strerror(r) << dendl;
-    return EXIT_FAILURE;
-  }
-
-  // unmount the store on exit
-  auto umount = [] (ObjectStore *store) {
-    int r = store->umount();
-    if (r < 0) {
-      derr << "failed to unmount with " << cpp_strerror(r) << dendl;
-    }
-    g_store = nullptr;
-  };
-  std::unique_ptr<ObjectStore, decltype(umount)> umounter{store.get(), umount};
-
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }