diff options
author | Kefu Chai <kchai@redhat.com> | 2016-11-15 07:21:03 +0100 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2016-11-24 15:38:28 +0100 |
commit | cb1cda96713b2ec0f6418c4cbe3d964c2020729c (patch) | |
tree | 2172eb81f79a3a93c1b3d1b74f31bfadeeb0a216 /src/test/objectstore | |
parent | crushtool: s/exit(EXIT_FAILURE)/return EXIT_FAILURE/ (diff) | |
download | ceph-cb1cda96713b2ec0f6418c4cbe3d964c2020729c.tar.xz ceph-cb1cda96713b2ec0f6418c4cbe3d964c2020729c.zip |
common,test: g_ceph_context->put() upon return
prior to this change, global_init() could create a new CephContext
and assign it to g_ceph_context. it's our responsibilty to release
the CephContext explicitly using cct->put() before the application
quits. but sometimes, we fail to do so.
in this change, global_init() will return an intrusive_ptr<CephContext>,
which calls `g_ceph_context->put()` in its dtor. this ensures that
the CephContext is always destroyed before main() returns. so the
log is flushed before _log_exp_length is destroyed.
there are two cases where global_pre_init() is called directly.
- ceph_conf.cc: g_ceph_context->put() will be called by an intrusive_ptr<>
deleter.
- rgw_main.cc: global_init() is called later on on the success code
path, so it will be taken care of.
Fixes: http://tracker.ceph.com/issues/17762
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/test/objectstore')
-rw-r--r-- | src/test/objectstore/Allocator_test.cc | 26 | ||||
-rw-r--r-- | src/test/objectstore/BitAllocator_test.cc | 18 | ||||
-rw-r--r-- | src/test/objectstore/ObjectStoreTransactionBenchmark.cc | 3 | ||||
-rw-r--r-- | src/test/objectstore/TestRocksdbOptionParse.cc | 14 | ||||
-rw-r--r-- | src/test/objectstore/chain_xattr.cc | 3 | ||||
-rw-r--r-- | src/test/objectstore/store_test.cc | 7 | ||||
-rw-r--r-- | src/test/objectstore/test_bluefs.cc | 5 | ||||
-rw-r--r-- | src/test/objectstore/test_bluestore_types.cc | 7 | ||||
-rw-r--r-- | src/test/objectstore/test_idempotent.cc | 3 | ||||
-rw-r--r-- | src/test/objectstore/test_idempotent_sequence.cc | 6 | ||||
-rw-r--r-- | src/test/objectstore/test_kv.cc | 3 | ||||
-rw-r--r-- | src/test/objectstore/test_memstore_clone.cc | 11 | ||||
-rw-r--r-- | src/test/objectstore/workload_generator.cc | 6 |
13 files changed, 36 insertions, 76 deletions
diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index 6b854f3f3a3..53d1d9d7f24 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -4,18 +4,18 @@ * In memory space allocator test cases. * Author: Ramesh Chander, Ramesh.Chander@sandisk.com */ -#include "os/bluestore/Allocator.h" -#include "global/global_init.h" #include <iostream> -#include "include/Context.h" -#include "common/ceph_argparse.h" -#include "global/global_init.h" +#include <gtest/gtest.h> + #include "common/Mutex.h" #include "common/Cond.h" #include "common/errno.h" #include "include/stringify.h" -#include <gtest/gtest.h> -#include <os/bluestore/BitAllocator.h> +#include "include/Context.h" +#include "os/bluestore/Allocator.h" +#include "os/bluestore/BitAllocator.h" +#include "test/unit.h" + #if GTEST_HAS_PARAM_TEST @@ -239,15 +239,3 @@ INSTANTIATE_TEST_CASE_P( TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {} #endif - -int main(int argc, char **argv) -{ - vector<const char*> args; - argv_to_vec(argc, (const char **)argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/src/test/objectstore/BitAllocator_test.cc b/src/test/objectstore/BitAllocator_test.cc index a9944ccced9..ff946afffab 100644 --- a/src/test/objectstore/BitAllocator_test.cc +++ b/src/test/objectstore/BitAllocator_test.cc @@ -7,14 +7,15 @@ #include "include/Context.h" #include "common/ceph_argparse.h" -#include "global/global_init.h" #include "os/bluestore/BitAllocator.h" +#include "test/unit.h" #include <stdio.h> #include <assert.h> #include <math.h> #include <sstream> #include <gtest/gtest.h> + #define bmap_test_assert(x) ASSERT_EQ(true, (x)) #define NUM_THREADS 16 #define MAX_BLOCKS (1024 * 1024 * 1) @@ -730,18 +731,3 @@ TEST(BitAllocator, test_bmap_alloc_concurrent) } } - -int main(int argc, char **argv) -{ - vector<const char*> args; - argv_to_vec(argc, (const char **)argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - - ::testing::InitGoogleTest(&argc, argv); - int r = RUN_ALL_TESTS(); - g_ceph_context->put(); - return r; -} diff --git a/src/test/objectstore/ObjectStoreTransactionBenchmark.cc b/src/test/objectstore/ObjectStoreTransactionBenchmark.cc index 46fd25dcebb..279b10b9969 100644 --- a/src/test/objectstore/ObjectStoreTransactionBenchmark.cc +++ b/src/test/objectstore/ObjectStoreTransactionBenchmark.cc @@ -246,7 +246,8 @@ int main(int argc, char **argv) vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->apply_changes(NULL); Cycles::init(); diff --git a/src/test/objectstore/TestRocksdbOptionParse.cc b/src/test/objectstore/TestRocksdbOptionParse.cc index b42d60dd154..d58f42c3925 100644 --- a/src/test/objectstore/TestRocksdbOptionParse.cc +++ b/src/test/objectstore/TestRocksdbOptionParse.cc @@ -1,12 +1,12 @@ #include <gtest/gtest.h> #include "include/Context.h" -#include "common/ceph_argparse.h" -#include "global/global_init.h" #include "rocksdb/db.h" #include "rocksdb/env.h" #include "rocksdb/thread_status.h" #include "kv/RocksDBStore.h" +#include "test/unit.h" #include <iostream> + using namespace std; const string dir("rocksdb.test_temp_dir"); @@ -73,13 +73,3 @@ TEST(RocksDBOption, interpret) { //high pri threads is flusher_threads ASSERT_EQ(5, num_high_pri_threads); } - -int main(int argc, char **argv) { - vector<const char*> args; - argv_to_vec(argc, (const char **)argv, args); - env_to_vec(args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/src/test/objectstore/chain_xattr.cc b/src/test/objectstore/chain_xattr.cc index a05e8755dd1..34654295d77 100644 --- a/src/test/objectstore/chain_xattr.cc +++ b/src/test/objectstore/chain_xattr.cc @@ -432,7 +432,8 @@ int main(int argc, char **argv) { vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->set_val("err_to_stderr", "false"); g_ceph_context->_conf->set_val("log_to_stderr", "false"); diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 877f5a31371..b96eb021311 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -5563,7 +5563,8 @@ int main(int argc, char **argv) { argv_to_vec(argc, (const char **)argv, args); env_to_vec(args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->set_val("osd_journal_size", "400"); @@ -5599,9 +5600,7 @@ int main(int argc, char **argv) { g_ceph_context->_conf->apply_changes(NULL); ::testing::InitGoogleTest(&argc, argv); - int r = RUN_ALL_TESTS(); - g_ceph_context->put(); - return r; + return RUN_ALL_TESTS(); } /* diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index d189eeac712..01763fec35c 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -577,8 +577,9 @@ int main(int argc, char **argv) { def_args.push_back("--debug-bluefs=1/20"); def_args.push_back("--debug-bdev=1/20"); - global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, - 0); + auto cct = global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, + 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->set_val( "enable_experimental_unrecoverable_data_corrupting_features", diff --git a/src/test/objectstore/test_bluestore_types.cc b/src/test/objectstore/test_bluestore_types.cc index ea6613c5e84..d68beba7c79 100644 --- a/src/test/objectstore/test_bluestore_types.cc +++ b/src/test/objectstore/test_bluestore_types.cc @@ -1011,10 +1011,9 @@ int main(int argc, char **argv) { vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); env_to_vec(args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); ::testing::InitGoogleTest(&argc, argv); - int r = RUN_ALL_TESTS(); - g_ceph_context->put(); - return r; + return RUN_ALL_TESTS(); } diff --git a/src/test/objectstore/test_idempotent.cc b/src/test/objectstore/test_idempotent.cc index edb8e9b3bfc..6b465b12f27 100644 --- a/src/test/objectstore/test_idempotent.cc +++ b/src/test/objectstore/test_idempotent.cc @@ -45,7 +45,8 @@ int main(int argc, char **argv) { vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->apply_changes(NULL); diff --git a/src/test/objectstore/test_idempotent_sequence.cc b/src/test/objectstore/test_idempotent_sequence.cc index 75ebc3377d3..0216b78f334 100644 --- a/src/test/objectstore/test_idempotent_sequence.cc +++ b/src/test/objectstore/test_idempotent_sequence.cc @@ -203,9 +203,9 @@ int main(int argc, const char *argv[]) our_name = argv[0]; argv_to_vec(argc, argv, args); - global_init(&def_args, args, - CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, - CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + auto cct = global_init(&def_args, args, + CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); common_init_finish(g_ceph_context); g_ceph_context->_conf->apply_changes(NULL); diff --git a/src/test/objectstore/test_kv.cc b/src/test/objectstore/test_kv.cc index 8aed8ade72a..d55841c9434 100644 --- a/src/test/objectstore/test_kv.cc +++ b/src/test/objectstore/test_kv.cc @@ -278,7 +278,8 @@ int main(int argc, char **argv) { argv_to_vec(argc, (const char **)argv, args); env_to_vec(args); - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); g_ceph_context->_conf->set_val( "enable_experimental_unrecoverable_data_corrupting_features", diff --git a/src/test/objectstore/test_memstore_clone.cc b/src/test/objectstore/test_memstore_clone.cc index 090c6f4bc1f..6607530f032 100644 --- a/src/test/objectstore/test_memstore_clone.cc +++ b/src/test/objectstore/test_memstore_clone.cc @@ -173,10 +173,6 @@ TEST_F(MemStoreClone, CloneRangeHoleEnd) ASSERT_EQ(expected, result); } -// enable boost::intrusive_ptr<CephContext> -void intrusive_ptr_add_ref(CephContext *cct) { cct->get(); } -void intrusive_ptr_release(CephContext *cct) { cct->put(); } - int main(int argc, char** argv) { // default to memstore @@ -189,13 +185,10 @@ int main(int argc, char** argv) vector<const char*> args; argv_to_vec(argc, (const char **)argv, args); - global_init(&defaults, args, CEPH_ENTITY_TYPE_CLIENT, - CODE_ENVIRONMENT_UTILITY, 0); + auto cct = global_init(&defaults, args, CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); - // release g_ceph_context on exit - boost::intrusive_ptr<CephContext> cct{g_ceph_context, false}; - ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/test/objectstore/workload_generator.cc b/src/test/objectstore/workload_generator.cc index bbe3c74675e..2c55fb27bc0 100644 --- a/src/test/objectstore/workload_generator.cc +++ b/src/test/objectstore/workload_generator.cc @@ -568,9 +568,9 @@ int main(int argc, const char *argv[]) // def_args.push_back("workload_gen_dir/journal"); argv_to_vec(argc, argv, args); - global_init(&def_args, args, - CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, - CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + auto cct = global_init(&def_args, args, + CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); common_init_finish(g_ceph_context); g_ceph_context->_conf->apply_changes(NULL); |