blob: 2099951cb5331b0869f5262d0b61e0bed1e97d46 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian Carlstromcd74c4b2012-01-23 13:21:00 -080016
17#include "mutex.h"
18
19#include "gtest/gtest.h"
20
21namespace art {
22
23TEST(Mutex, LockUnlock) {
24 Mutex mu("test mutex");
25 mu.AssertDepth(0U);
26 mu.Lock();
27 mu.AssertDepth(1U);
28 mu.Unlock();
29 mu.AssertDepth(0U);
30}
31
32TEST(Mutex, TryLockUnlock) {
33 Mutex mu("test mutex");
34 mu.AssertDepth(0U);
35 mu.TryLock();
36 mu.AssertDepth(1U);
37 mu.Unlock();
38 mu.AssertDepth(0U);
39}
40
41TEST(Mutex, RecursiveLockUnlock) {
42 Mutex mu("test mutex");
43 mu.AssertDepth(0U);
44 mu.Lock();
45 mu.AssertDepth(1U);
46 mu.Lock();
47 mu.AssertDepth(2U);
48 mu.Unlock();
49 mu.AssertDepth(1U);
50 mu.Unlock();
51 mu.AssertDepth(0U);
52}
53
54TEST(Mutex, RecursiveTryLockUnlock) {
55 Mutex mu("test mutex");
56 mu.AssertDepth(0U);
57 mu.TryLock();
58 mu.AssertDepth(1U);
59 mu.TryLock();
60 mu.AssertDepth(2U);
61 mu.Unlock();
62 mu.AssertDepth(1U);
63 mu.Unlock();
64 mu.AssertDepth(0U);
65}
66
67} // namespace art