Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: test/cctest/test-mutex.cc

Issue 448603002: Refactor unit tests for the base library to use GTest. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reduce LoopIncrement test time. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include <cstdlib>
29
30 #include "src/v8.h"
31
32 #include "src/base/platform/mutex.h"
33 #include "test/cctest/cctest.h"
34
35 using namespace ::v8::internal;
36
37
38 TEST(LockGuardMutex) {
39 v8::base::Mutex mutex;
40 { v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
41 }
42 { v8::base::LockGuard<v8::base::Mutex> lock_guard(&mutex);
43 }
44 }
45
46
47 TEST(LockGuardRecursiveMutex) {
48 v8::base::RecursiveMutex recursive_mutex;
49 { v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard(&recursive_mutex);
50 }
51 { v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard1(&recursive_mutex);
52 v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard2(&recursive_mutex);
53 }
54 }
55
56
57 TEST(LockGuardLazyMutex) {
58 v8::base::LazyMutex lazy_mutex = LAZY_MUTEX_INITIALIZER;
59 { v8::base::LockGuard<v8::base::Mutex> lock_guard(lazy_mutex.Pointer());
60 }
61 { v8::base::LockGuard<v8::base::Mutex> lock_guard(lazy_mutex.Pointer());
62 }
63 }
64
65
66 TEST(LockGuardLazyRecursiveMutex) {
67 v8::base::LazyRecursiveMutex lazy_recursive_mutex =
68 LAZY_RECURSIVE_MUTEX_INITIALIZER;
69 {
70 v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard(
71 lazy_recursive_mutex.Pointer());
72 }
73 {
74 v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard1(
75 lazy_recursive_mutex.Pointer());
76 v8::base::LockGuard<v8::base::RecursiveMutex> lock_guard2(
77 lazy_recursive_mutex.Pointer());
78 }
79 }
80
81
82 TEST(MultipleMutexes) {
83 v8::base::Mutex mutex1;
84 v8::base::Mutex mutex2;
85 v8::base::Mutex mutex3;
86 // Order 1
87 mutex1.Lock();
88 mutex2.Lock();
89 mutex3.Lock();
90 mutex1.Unlock();
91 mutex2.Unlock();
92 mutex3.Unlock();
93 // Order 2
94 mutex1.Lock();
95 mutex2.Lock();
96 mutex3.Lock();
97 mutex3.Unlock();
98 mutex2.Unlock();
99 mutex1.Unlock();
100 }
101
102
103 TEST(MultipleRecursiveMutexes) {
104 v8::base::RecursiveMutex recursive_mutex1;
105 v8::base::RecursiveMutex recursive_mutex2;
106 // Order 1
107 recursive_mutex1.Lock();
108 recursive_mutex2.Lock();
109 CHECK(recursive_mutex1.TryLock());
110 CHECK(recursive_mutex2.TryLock());
111 recursive_mutex1.Unlock();
112 recursive_mutex1.Unlock();
113 recursive_mutex2.Unlock();
114 recursive_mutex2.Unlock();
115 // Order 2
116 recursive_mutex1.Lock();
117 CHECK(recursive_mutex1.TryLock());
118 recursive_mutex2.Lock();
119 CHECK(recursive_mutex2.TryLock());
120 recursive_mutex2.Unlock();
121 recursive_mutex1.Unlock();
122 recursive_mutex2.Unlock();
123 recursive_mutex1.Unlock();
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698