blob: bafd7899ac946a7a5fb2ac414b355fc9a6aa7868 [file] [log] [blame]
Brian Carlstromcd74c4b2012-01-23 13:21:00 -08001// Copyright 2012 Google Inc. All Rights Reserved.
2
3#include "mutex.h"
4
5#include "gtest/gtest.h"
6
7namespace art {
8
9TEST(Mutex, LockUnlock) {
10 Mutex mu("test mutex");
11 mu.AssertDepth(0U);
12 mu.Lock();
13 mu.AssertDepth(1U);
14 mu.Unlock();
15 mu.AssertDepth(0U);
16}
17
18TEST(Mutex, TryLockUnlock) {
19 Mutex mu("test mutex");
20 mu.AssertDepth(0U);
21 mu.TryLock();
22 mu.AssertDepth(1U);
23 mu.Unlock();
24 mu.AssertDepth(0U);
25}
26
27TEST(Mutex, RecursiveLockUnlock) {
28 Mutex mu("test mutex");
29 mu.AssertDepth(0U);
30 mu.Lock();
31 mu.AssertDepth(1U);
32 mu.Lock();
33 mu.AssertDepth(2U);
34 mu.Unlock();
35 mu.AssertDepth(1U);
36 mu.Unlock();
37 mu.AssertDepth(0U);
38}
39
40TEST(Mutex, RecursiveTryLockUnlock) {
41 Mutex mu("test mutex");
42 mu.AssertDepth(0U);
43 mu.TryLock();
44 mu.AssertDepth(1U);
45 mu.TryLock();
46 mu.AssertDepth(2U);
47 mu.Unlock();
48 mu.AssertDepth(1U);
49 mu.Unlock();
50 mu.AssertDepth(0U);
51}
52
53} // namespace art