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

Side by Side Diff: runtime/vm/thread_test.cc

Issue 9242035: Give isolates names to be used during debugging. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/isolate.h" 6 #include "vm/isolate.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 UNIT_TEST_CASE(Mutex) { 12 UNIT_TEST_CASE(Mutex) {
13 // This unit test case needs a running isolate. 13 // This unit test case needs a running isolate.
14 Isolate* isolate = Isolate::Init(); 14 Isolate* isolate = Isolate::Init(NULL);
15 15
16 Mutex* mutex = new Mutex(); 16 Mutex* mutex = new Mutex();
17 mutex->Lock(); 17 mutex->Lock();
18 EXPECT_EQ(false, mutex->TryLock()); 18 EXPECT_EQ(false, mutex->TryLock());
19 mutex->Unlock(); 19 mutex->Unlock();
20 EXPECT_EQ(true, mutex->TryLock()); 20 EXPECT_EQ(true, mutex->TryLock());
21 mutex->Unlock(); 21 mutex->Unlock();
22 { 22 {
23 MutexLocker ml(mutex); 23 MutexLocker ml(mutex);
24 EXPECT_EQ(false, mutex->TryLock()); 24 EXPECT_EQ(false, mutex->TryLock());
25 } 25 }
26 // The isolate shutdown and the destruction of the mutex are out-of-order on 26 // The isolate shutdown and the destruction of the mutex are out-of-order on
27 // purpose. 27 // purpose.
28 isolate->Shutdown(); 28 isolate->Shutdown();
29 delete isolate; 29 delete isolate;
30 delete mutex; 30 delete mutex;
31 } 31 }
32 32
33 33
34 UNIT_TEST_CASE(Monitor) { 34 UNIT_TEST_CASE(Monitor) {
35 // This unit test case needs a running isolate. 35 // This unit test case needs a running isolate.
36 Isolate* isolate = Isolate::Init(); 36 Isolate* isolate = Isolate::Init(NULL);
37 37
38 Monitor* monitor = new Monitor(); 38 Monitor* monitor = new Monitor();
39 monitor->Enter(); 39 monitor->Enter();
40 monitor->Exit(); 40 monitor->Exit();
41 41
42 { 42 {
43 MonitorLocker ml(monitor); 43 MonitorLocker ml(monitor);
44 int64_t start = OS::GetCurrentTimeMillis(); 44 int64_t start = OS::GetCurrentTimeMillis();
45 int64_t wait_time = 2017; 45 int64_t wait_time = 2017;
46 Monitor::WaitResult wait_result = ml.Wait(wait_time); 46 Monitor::WaitResult wait_result = ml.Wait(wait_time);
47 int64_t stop = OS::GetCurrentTimeMillis(); 47 int64_t stop = OS::GetCurrentTimeMillis();
48 EXPECT_EQ(Monitor::kTimedOut, wait_result); 48 EXPECT_EQ(Monitor::kTimedOut, wait_result);
49 const int kAcceptableTimeJitter = 20; // Measured in milliseconds. 49 const int kAcceptableTimeJitter = 20; // Measured in milliseconds.
50 EXPECT_LE(wait_time - kAcceptableTimeJitter, stop - start); 50 EXPECT_LE(wait_time - kAcceptableTimeJitter, stop - start);
51 const int kAcceptableWakeupDelay = 120; // Measured in milliseconds. 51 const int kAcceptableWakeupDelay = 120; // Measured in milliseconds.
52 EXPECT_GE(wait_time + kAcceptableWakeupDelay, stop - start); 52 EXPECT_GE(wait_time + kAcceptableWakeupDelay, stop - start);
53 } 53 }
54 // The isolate shutdown and the destruction of the mutex are out-of-order on 54 // The isolate shutdown and the destruction of the mutex are out-of-order on
55 // purpose. 55 // purpose.
56 isolate->Shutdown(); 56 isolate->Shutdown();
57 delete isolate; 57 delete isolate;
58 delete monitor; 58 delete monitor;
59 } 59 }
60 60
61 } // namespace dart 61 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698