diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/common/test_lockdep.cc | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/common/test_lockdep.cc')
-rw-r--r-- | src/test/common/test_lockdep.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/common/test_lockdep.cc b/src/test/common/test_lockdep.cc new file mode 100644 index 000000000..0b47f780c --- /dev/null +++ b/src/test/common/test_lockdep.cc @@ -0,0 +1,74 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "gtest/gtest.h" + +#include "common/ceph_argparse.h" +#include "common/ceph_context.h" +#include "common/ceph_mutex.h" +#include "common/common_init.h" +#include "common/lockdep.h" +#include "include/util.h" +#include "include/coredumpctl.h" +#include "log/Log.h" + +class lockdep : public ::testing::Test +{ +protected: + void SetUp() override { +#ifndef 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)); + ASSERT_TRUE(ceph_mutex_is_locked_by_me(a)); + b.lock(); + ASSERT_TRUE(ceph_mutex_is_locked(b)); + ASSERT_TRUE(ceph_mutex_is_locked_by_me(b)); + a.unlock(); + b.unlock(); + + b.lock(); + PrCtl unset_dumpable; + EXPECT_DEATH(a.lock(), ""); + b.unlock(); +} + +TEST_F(lockdep, recursive) +{ + ceph::mutex a(ceph::make_mutex("a")); + a.lock(); + PrCtl unset_dumpable; + EXPECT_DEATH(a.lock(), ""); + a.unlock(); + + ceph::recursive_mutex b(ceph::make_recursive_mutex("b")); + b.lock(); + ASSERT_TRUE(ceph_mutex_is_locked(b)); + ASSERT_TRUE(ceph_mutex_is_locked_by_me(b)); + b.lock(); + b.unlock(); + b.unlock(); +} |