]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/objectstore/unittest_alloc_aging: init cct
authorKefu Chai <kchai@redhat.com>
Wed, 2 Jun 2021 09:54:18 +0000 (17:54 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 4 Jun 2021 06:07:29 +0000 (14:07 +0800)
* initialize the cct use by test, otherwise g_ceph_context is
  not set at all.
* instead of using g_ceph_context, use static member variable cct.
  less dependency to the global instance.
* setup and teardown the cct for test suite, because global_init()
  initialize g_ceph_context, which cannot be set multiple times.

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

index 78a0047a35da4b6d6021052c3c635c023e132d2c..8641b010748f917b8b11e45ad258cac3a5d2b9b6 100755 (executable)
@@ -12,6 +12,7 @@
 #include "common/ceph_mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
+#include "global/global_init.h"
 #include "include/stringify.h"
 #include "include/Context.h"
 #include "os/bluestore/Allocator.h"
@@ -21,7 +22,7 @@
 typedef boost::mt11213b gen_type;
 
 #include "common/debug.h"
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_
 
 struct Scenario {
@@ -74,6 +75,8 @@ class AllocTest : public ::testing::TestWithParam<std::string> {
 protected:
   boost::scoped_ptr<AllocTracker> at;
   gen_type rng;
+  static boost::intrusive_ptr<CephContext> cct;
+
 public:
   boost::scoped_ptr<Allocator> alloc;
   AllocTest(): alloc(nullptr) {}
@@ -96,6 +99,8 @@ public:
   void do_free(uint64_t low_mark);
   uint32_t free_random();
 
+  void TearDown() final;
+  static void SetUpTestSuite();
   static void TearDownTestSuite();
 };
 
@@ -150,12 +155,13 @@ public:
   }
 };
 
+boost::intrusive_ptr<CephContext> AllocTest::cct;
 
 void AllocTest::init_alloc(const std::string& allocator_name, int64_t size, uint64_t min_alloc_size) {
   this->capacity = size;
   this->alloc_unit = min_alloc_size;
   rng.seed(0);
-  alloc.reset(Allocator::create(g_ceph_context, allocator_name, size,
+  alloc.reset(Allocator::create(cct.get(), allocator_name, size,
                                min_alloc_size));
   at.reset(new AllocTracker());
 }
@@ -229,7 +235,7 @@ void AllocTest::doAgingTest(
     uint64_t high_mark, uint64_t low_mark, uint32_t iterations, double leak_factor)
 {
   assert(isp2(alloc_unit));
-  g_ceph_context->_conf->bdev_block_size = alloc_unit;
+  cct->_conf->bdev_block_size = alloc_unit;
   PExtentVector allocated, tmp;
   init_alloc(allocator_name, capacity, alloc_unit);
   alloc->init_add_free(0, capacity);
@@ -299,8 +305,26 @@ void AllocTest::doAgingTest(
   r.frag_score += frag_score;
 }
 
+void AllocTest::SetUpTestSuite()
+{
+  vector<const char*> args;
+  cct = global_init(NULL, args,
+                   CEPH_ENTITY_TYPE_CLIENT,
+                   CODE_ENVIRONMENT_UTILITY,
+                   CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
+  common_init_finish(cct.get());
+}
+
+void AllocTest::TearDown()
+{
+  at.reset();
+  alloc.reset();
+}
+
 void AllocTest::TearDownTestSuite()
 {
+  cct.reset();
+
   std::cout << "Summary: " << std::endl;
   for (auto& r: results_per_allocator) {
     std::cout << r.first <<