]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/common: add death test for double !recursive lock 60037/head
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 2 Oct 2024 14:48:34 +0000 (10:48 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 3 Oct 2024 20:19:18 +0000 (16:19 -0400)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/test/common/test_mutex_debug.cc

index 29eb8076859c90bd32fd90a2cc8d1ece822e81f1..cee4b427770aeeb997b1421bd7d203f81c7e79af 100644 (file)
@@ -57,20 +57,13 @@ TEST(MutexDebug, Lock) {
   test_lock<ceph::mutex_debug>();
 }
 
-TEST(MutexDebug, NotRecursive) {
+TEST(MutexDebugDeathTest, NotRecursive) {
   ceph::mutex_debug m("foo");
-  auto ttl = &test_try_lock<mutex_debug>;
-
-  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) {