From: Patrick Donnelly Date: Wed, 2 Oct 2024 14:48:34 +0000 (-0400) Subject: test/common: add death test for double !recursive lock X-Git-Tag: testing/wip-pdonnell-testing-20241004.144202-debug~4^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a48080af3956ae84fb2b3e5da2db1ca16c308c2f;p=ceph-ci.git test/common: add death test for double !recursive lock Signed-off-by: Patrick Donnelly --- diff --git a/src/test/common/test_mutex_debug.cc b/src/test/common/test_mutex_debug.cc index 29eb8076859..cee4b427770 100644 --- a/src/test/common/test_mutex_debug.cc +++ b/src/test/common/test_mutex_debug.cc @@ -57,20 +57,13 @@ TEST(MutexDebug, Lock) { test_lock(); } -TEST(MutexDebug, NotRecursive) { +TEST(MutexDebugDeathTest, NotRecursive) { ceph::mutex_debug m("foo"); - auto ttl = &test_try_lock; - - ASSERT_NO_THROW(m.lock()); - ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - + // avoid assert during test cleanup where the mutex is locked and cannot be + // pthread_mutex_destroy'd + std::unique_lock locker{m}; ASSERT_TRUE(m.is_locked()); - ASSERT_FALSE(std::async(std::launch::async, ttl, &m).get()); - - ASSERT_NO_THROW(m.unlock()); - ASSERT_FALSE(m.is_locked()); - ASSERT_TRUE(std::async(std::launch::async, ttl, &m).get()); + ASSERT_DEATH(m.lock(), "FAILED ceph_assert(recursive || !is_locked_by_me())"); } TEST(MutexRecursiveDebug, Lock) {