From 8b651b3522397d899aeb41f591d75fd6aebb5383 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 2 Jun 2021 17:54:18 +0800 Subject: [PATCH] test/objectstore/unittest_alloc_aging: init cct * 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 --- .../Allocator_aging_fragmentation.cc | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/test/objectstore/Allocator_aging_fragmentation.cc b/src/test/objectstore/Allocator_aging_fragmentation.cc index 78a0047a35d..8641b010748 100755 --- a/src/test/objectstore/Allocator_aging_fragmentation.cc +++ b/src/test/objectstore/Allocator_aging_fragmentation.cc @@ -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 { protected: boost::scoped_ptr at; gen_type rng; + static boost::intrusive_ptr cct; + public: boost::scoped_ptr 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 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 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 << -- 2.39.5