Skip to content

Commit

Permalink
test/unittest_lockdep: do not start extra threads
Browse files Browse the repository at this point in the history
also, stop linking against libglobal

Fixes: https://tracker.ceph.com/issues/43403
Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Jan 22, 2020
1 parent c4f555f commit 2dc50b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 39 deletions.
5 changes: 2 additions & 3 deletions src/test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 32 additions & 36 deletions src/test/common/test_lockdep.cc
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -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;
Expand All @@ -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<const char*> 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();
}

0 comments on commit 2dc50b5

Please sign in to comment.