]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_mutex.cc
update sources to 12.2.10
[ceph.git] / ceph / src / test / common / test_mutex.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 */
7
8 #include <common/Mutex.h>
9 #include "gtest/gtest.h"
10 #include "common/ceph_context.h"
11 #include "common/config.h"
12 #include "include/coredumpctl.h"
13
14 static CephContext* cct;
15
16 static void do_init() {
17 if (cct == nullptr) {
18 cct = new CephContext(0);
19 lockdep_register_ceph_context(cct);
20 }
21 }
22
23 static void disable_lockdep() {
24 if (cct) {
25 lockdep_unregister_ceph_context(cct);
26 cct->put();
27 cct = nullptr;
28 }
29 }
30
31 TEST(Mutex, NormalAsserts) {
32 Mutex* m = new Mutex("Normal",false);
33 m->Lock();
34 testing::GTEST_FLAG(death_test_style) = "threadsafe";
35 EXPECT_DEATH(m->Lock(), ".*");
36 }
37
38 TEST(Mutex, RecursiveWithLockdep) {
39 do_init();
40 Mutex* m = new Mutex("Recursive1",true);
41 m->Lock();
42 m->Lock();
43 m->Unlock();
44 m->Unlock();
45 delete m;
46 }
47
48 TEST(Mutex, RecursiveWithoutLockdep) {
49 disable_lockdep();
50 Mutex* m = new Mutex("Recursive2",true);
51 m->Lock();
52 m->Lock();
53 m->Unlock();
54 m->Unlock();
55 delete m;
56 }
57
58 TEST(Mutex, DeleteLocked) {
59 Mutex* m = new Mutex("Recursive3",false);
60 m->Lock();
61 PrCtl unset_dumpable;
62 EXPECT_DEATH(delete m,".*");
63 }