OLD | NEW |
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/lockers.h" | 7 #include "vm/lockers.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 #include "vm/profiler.h" | 9 #include "vm/profiler.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::Flags vm_flags; |
| 16 Dart_IsolateFlags api_flags; |
| 17 vm_flags.CopyTo(&api_flags); |
| 18 Isolate* isolate = Isolate::Init(NULL, api_flags); |
16 | 19 |
17 Mutex* mutex = new Mutex(); | 20 Mutex* mutex = new Mutex(); |
18 mutex->Lock(); | 21 mutex->Lock(); |
19 EXPECT_EQ(false, mutex->TryLock()); | 22 EXPECT_EQ(false, mutex->TryLock()); |
20 mutex->Unlock(); | 23 mutex->Unlock(); |
21 EXPECT_EQ(true, mutex->TryLock()); | 24 EXPECT_EQ(true, mutex->TryLock()); |
22 mutex->Unlock(); | 25 mutex->Unlock(); |
23 { | 26 { |
24 MutexLocker ml(mutex); | 27 MutexLocker ml(mutex); |
25 EXPECT_EQ(false, mutex->TryLock()); | 28 EXPECT_EQ(false, mutex->TryLock()); |
26 } | 29 } |
27 // The isolate shutdown and the destruction of the mutex are out-of-order on | 30 // The isolate shutdown and the destruction of the mutex are out-of-order on |
28 // purpose. | 31 // purpose. |
29 isolate->Shutdown(); | 32 isolate->Shutdown(); |
30 delete isolate; | 33 delete isolate; |
31 delete mutex; | 34 delete mutex; |
32 } | 35 } |
33 | 36 |
34 | 37 |
35 UNIT_TEST_CASE(Monitor) { | 38 UNIT_TEST_CASE(Monitor) { |
36 // This unit test case needs a running isolate. | 39 // This unit test case needs a running isolate. |
37 Isolate* isolate = Isolate::Init(NULL); | 40 Isolate::Flags vm_flags; |
| 41 Dart_IsolateFlags api_flags; |
| 42 vm_flags.CopyTo(&api_flags); |
| 43 Isolate* isolate = Isolate::Init(NULL, api_flags); |
38 // Thread interrupter interferes with this test, disable interrupts. | 44 // Thread interrupter interferes with this test, disable interrupts. |
39 isolate->set_thread_state(NULL); | 45 isolate->set_thread_state(NULL); |
40 Profiler::EndExecution(isolate); | 46 Profiler::EndExecution(isolate); |
41 Monitor* monitor = new Monitor(); | 47 Monitor* monitor = new Monitor(); |
42 monitor->Enter(); | 48 monitor->Enter(); |
43 monitor->Exit(); | 49 monitor->Exit(); |
44 | 50 |
45 const int kNumAttempts = 5; | 51 const int kNumAttempts = 5; |
46 int attempts = 0; | 52 int attempts = 0; |
47 while (attempts < kNumAttempts) { | 53 while (attempts < kNumAttempts) { |
(...skipping 22 matching lines...) Expand all Loading... |
70 EXPECT_LT(attempts, kNumAttempts); | 76 EXPECT_LT(attempts, kNumAttempts); |
71 | 77 |
72 // The isolate shutdown and the destruction of the mutex are out-of-order on | 78 // The isolate shutdown and the destruction of the mutex are out-of-order on |
73 // purpose. | 79 // purpose. |
74 isolate->Shutdown(); | 80 isolate->Shutdown(); |
75 delete isolate; | 81 delete isolate; |
76 delete monitor; | 82 delete monitor; |
77 } | 83 } |
78 | 84 |
79 } // namespace dart | 85 } // namespace dart |
OLD | NEW |