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

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

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « runtime/vm/thread_interrupter_win.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/signal_handler.h" 8 #include "vm/profiler.h"
9 #include "vm/thread.h" 9 #include "vm/thread.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 UNIT_TEST_CASE(Mutex) { 13 UNIT_TEST_CASE(Mutex) {
14 // This unit test case needs a running isolate. 14 // This unit test case needs a running isolate.
15 Isolate* isolate = Isolate::Init(NULL); 15 Isolate* isolate = Isolate::Init(NULL);
16 16
17 Mutex* mutex = new Mutex(); 17 Mutex* mutex = new Mutex();
18 mutex->Lock(); 18 mutex->Lock();
19 EXPECT_EQ(false, mutex->TryLock()); 19 EXPECT_EQ(false, mutex->TryLock());
20 mutex->Unlock(); 20 mutex->Unlock();
21 EXPECT_EQ(true, mutex->TryLock()); 21 EXPECT_EQ(true, mutex->TryLock());
22 mutex->Unlock(); 22 mutex->Unlock();
23 { 23 {
24 MutexLocker ml(mutex); 24 MutexLocker ml(mutex);
25 EXPECT_EQ(false, mutex->TryLock()); 25 EXPECT_EQ(false, mutex->TryLock());
26 } 26 }
27 // The isolate shutdown and the destruction of the mutex are out-of-order on 27 // The isolate shutdown and the destruction of the mutex are out-of-order on
28 // purpose. 28 // purpose.
29 isolate->Shutdown(); 29 isolate->Shutdown();
30 delete isolate; 30 delete isolate;
31 delete mutex; 31 delete mutex;
32 } 32 }
33 33
34 34
35 UNIT_TEST_CASE(Monitor) { 35 UNIT_TEST_CASE(Monitor) {
36 // This unit test case needs a running isolate. 36 // This unit test case needs a running isolate.
37 Isolate* isolate = Isolate::Init(NULL); 37 Isolate* isolate = Isolate::Init(NULL);
38 38 // Profiler interrupts interfere with this test.
39 Profiler::EndExecution(isolate);
39 Monitor* monitor = new Monitor(); 40 Monitor* monitor = new Monitor();
40 monitor->Enter(); 41 monitor->Enter();
41 monitor->Exit(); 42 monitor->Exit();
42 43
43 const int kNumAttempts = 5; 44 const int kNumAttempts = 5;
44 int attempts = 0; 45 int attempts = 0;
45 while (attempts < kNumAttempts) { 46 while (attempts < kNumAttempts) {
46 // This test verifies that a monitor returns after the specified timeout. If
47 // a signal is delivered to this thread, the monitor may return early.
48 // Block signal delivery in this scope.
49 ScopedSignalBlocker ssb;
50 MonitorLocker ml(monitor); 47 MonitorLocker ml(monitor);
51 int64_t start = OS::GetCurrentTimeMillis(); 48 int64_t start = OS::GetCurrentTimeMillis();
52 int64_t wait_time = 2017; 49 int64_t wait_time = 2017;
53 Monitor::WaitResult wait_result = ml.Wait(wait_time); 50 Monitor::WaitResult wait_result = ml.Wait(wait_time);
54 int64_t stop = OS::GetCurrentTimeMillis(); 51 int64_t stop = OS::GetCurrentTimeMillis();
55 52
56 // We expect to be timing out here. 53 // We expect to be timing out here.
57 EXPECT_EQ(Monitor::kTimedOut, wait_result); 54 EXPECT_EQ(Monitor::kTimedOut, wait_result);
58 55
59 // Check whether this attempt falls within the exptected time limits. 56 // Check whether this attempt falls within the exptected time limits.
(...skipping 12 matching lines...) Expand all
72 EXPECT_LT(attempts, kNumAttempts); 69 EXPECT_LT(attempts, kNumAttempts);
73 70
74 // The isolate shutdown and the destruction of the mutex are out-of-order on 71 // The isolate shutdown and the destruction of the mutex are out-of-order on
75 // purpose. 72 // purpose.
76 isolate->Shutdown(); 73 isolate->Shutdown();
77 delete isolate; 74 delete isolate;
78 delete monitor; 75 delete monitor;
79 } 76 }
80 77
81 } // namespace dart 78 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread_interrupter_win.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698