]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | /* | |
15 | * Override normal ceph assert. | |
16 | * It is needed to prevent hang when we assert() and THEN still wait on lock(). | |
17 | */ | |
18 | namespace ceph | |
19 | { | |
20 | void __ceph_assert_fail(const char *assertion, const char *file, int line, | |
21 | const char *func) | |
22 | { | |
23 | throw 0; | |
24 | } | |
25 | } | |
26 | ||
b32b8144 FG |
27 | static CephContext* cct; |
28 | ||
29 | static void do_init() { | |
7c673cae FG |
30 | if (cct == nullptr) { |
31 | cct = new CephContext(0); | |
32 | lockdep_register_ceph_context(cct); | |
33 | } | |
34 | } | |
35 | ||
b32b8144 FG |
36 | static void disable_lockdep() { |
37 | if (cct) { | |
38 | lockdep_unregister_ceph_context(cct); | |
39 | cct->put(); | |
40 | cct = nullptr; | |
41 | } | |
42 | } | |
43 | ||
7c673cae FG |
44 | TEST(Mutex, NormalAsserts) { |
45 | Mutex* m = new Mutex("Normal",false); | |
46 | m->Lock(); | |
47 | EXPECT_THROW(m->Lock(), int); | |
48 | } | |
49 | ||
50 | TEST(Mutex, RecursiveWithLockdep) { | |
51 | do_init(); | |
7c673cae FG |
52 | Mutex* m = new Mutex("Recursive1",true); |
53 | m->Lock(); | |
54 | m->Lock(); | |
55 | m->Unlock(); | |
56 | m->Unlock(); | |
57 | delete m; | |
58 | } | |
59 | ||
60 | TEST(Mutex, RecursiveWithoutLockdep) { | |
b32b8144 | 61 | disable_lockdep(); |
7c673cae FG |
62 | Mutex* m = new Mutex("Recursive2",true); |
63 | m->Lock(); | |
64 | m->Lock(); | |
65 | m->Unlock(); | |
66 | m->Unlock(); | |
67 | delete m; | |
68 | } | |
69 | ||
70 | TEST(Mutex, DeleteLocked) { | |
71 | Mutex* m = new Mutex("Recursive3",false); | |
72 | m->Lock(); | |
73 | PrCtl unset_dumpable; | |
74 | EXPECT_DEATH(delete m,".*"); | |
75 | } |