From: Kefu Chai Date: Wed, 22 Jan 2020 04:30:34 +0000 (+0800) Subject: test/unittest_lockdep: do not start extra threads X-Git-Tag: v15.1.0~109^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2dc50b5f91476cf10429dbcdd52b00e32f599d5c;p=ceph.git test/unittest_lockdep: do not start extra threads also, stop linking against libglobal Fixes: https://tracker.ceph.com/issues/43403 Signed-off-by: Kefu Chai --- diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt index f5c23649d218..6ca76b7b5bcd 100644 --- a/src/test/common/CMakeLists.txt +++ b/src/test/common/CMakeLists.txt @@ -23,10 +23,9 @@ endif() # unittest_lockdep add_executable(unittest_lockdep - test_lockdep.cc - ) + test_lockdep.cc) add_ceph_unittest(unittest_lockdep) -target_link_libraries(unittest_lockdep ceph-common global) +target_link_libraries(unittest_lockdep ceph-common) # FreeBSD only has shims to support NUMA, no functional code. if(LINUX) diff --git a/src/test/common/test_lockdep.cc b/src/test/common/test_lockdep.cc index 0198f50d5074..2e83efa1ebf5 100644 --- a/src/test/common/test_lockdep.cc +++ b/src/test/common/test_lockdep.cc @@ -1,20 +1,45 @@ // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#include "common/ceph_context.h" -#include "include/util.h" #include "gtest/gtest.h" + +#include "common/ceph_argparse.h" +#include "common/ceph_context.h" #include "common/ceph_mutex.h" -#include "global/global_context.h" -#include "global/global_init.h" +#include "common/common_init.h" #include "common/lockdep.h" +#include "include/util.h" #include "include/coredumpctl.h" #include "log/Log.h" -TEST(lockdep, abba) +class lockdep : public ::testing::Test { - ASSERT_TRUE(g_lockdep); +protected: + void SetUp() override { +#ifdef CEPH_DEBUG_MUTEX + GTEST_SKIP() << "WARNING: CEPH_DEBUG_MUTEX is not defined, lockdep will not work"; +#endif + CephInitParameters params(CEPH_ENTITY_TYPE_CLIENT); + cct = common_preinit(params, CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + cct->_conf->cluster = "ceph"; + cct->_conf.set_val("lockdep", "true"); + cct->_conf.apply_changes(nullptr); + ASSERT_TRUE(g_lockdep); + } + void TearDown() final + { + if (cct) { + cct->put(); + cct = nullptr; + } + } +protected: + CephContext *cct = nullptr; +}; +TEST_F(lockdep, abba) +{ ceph::mutex a(ceph::make_mutex("a")), b(ceph::make_mutex("b")); a.lock(); ASSERT_TRUE(ceph_mutex_is_locked(a)); @@ -31,10 +56,8 @@ TEST(lockdep, abba) b.unlock(); } -TEST(lockdep, recursive) +TEST_F(lockdep, recursive) { - ASSERT_TRUE(g_lockdep); - ceph::mutex a(ceph::make_mutex("a")); a.lock(); PrCtl unset_dumpable; @@ -49,30 +72,3 @@ TEST(lockdep, recursive) b.unlock(); b.unlock(); } - -int main(int argc, char **argv) { -#ifdef NDEBUG - cout << "NDEBUG is defined" << std::endl; -#else - cout << "NDEBUG is NOT defined" << std::endl; -#endif -#ifndef CEPH_DEBUG_MUTEX - cerr << "WARNING: CEPH_DEBUG_MUTEX is not defined, lockdep will not work" - << std::endl; - exit(0); -#endif - std::vector args(argv, argv + argc); - args.push_back("--lockdep"); - auto cct = global_init(NULL, args, - CEPH_ENTITY_TYPE_CLIENT, - CODE_ENVIRONMENT_UTILITY, - CINIT_FLAG_NO_MON_CONFIG | - CINIT_FLAG_NO_DAEMON_ACTIONS); - common_init_finish(g_ceph_context); - - // stop logging thread - g_ceph_context->_log->stop(); - - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}