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 #include "vm/safepoint.h" | 10 #include "vm/safepoint.h" |
11 #include "vm/stack_frame.h" | 11 #include "vm/stack_frame.h" |
12 #include "vm/thread_pool.h" | 12 #include "vm/thread_pool.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 UNIT_TEST_CASE(Mutex) { | 16 UNIT_TEST_CASE(Mutex) { |
17 // This unit test case needs a running isolate. | 17 // This unit test case needs a running isolate. |
18 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 18 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
19 NULL); | 19 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
20 | 20 |
21 Mutex* mutex = new Mutex(); | 21 Mutex* mutex = new Mutex(); |
22 mutex->Lock(); | 22 mutex->Lock(); |
23 EXPECT_EQ(false, mutex->TryLock()); | 23 EXPECT_EQ(false, mutex->TryLock()); |
24 mutex->Unlock(); | 24 mutex->Unlock(); |
25 EXPECT_EQ(true, mutex->TryLock()); | 25 EXPECT_EQ(true, mutex->TryLock()); |
26 mutex->Unlock(); | 26 mutex->Unlock(); |
27 { | 27 { |
28 MutexLocker ml(mutex); | 28 MutexLocker ml(mutex); |
29 EXPECT_EQ(false, mutex->TryLock()); | 29 EXPECT_EQ(false, mutex->TryLock()); |
30 } | 30 } |
31 // The isolate shutdown and the destruction of the mutex are out-of-order on | 31 // The isolate shutdown and the destruction of the mutex are out-of-order on |
32 // purpose. | 32 // purpose. |
33 Dart_ShutdownIsolate(); | 33 Dart_ShutdownIsolate(); |
34 delete mutex; | 34 delete mutex; |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 UNIT_TEST_CASE(Monitor) { | 38 UNIT_TEST_CASE(Monitor) { |
39 // This unit test case needs a running isolate. | 39 // This unit test case needs a running isolate. |
40 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 40 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
41 NULL); | 41 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
42 OSThread* thread = OSThread::Current(); | 42 OSThread* thread = OSThread::Current(); |
43 // Thread interrupter interferes with this test, disable interrupts. | 43 // Thread interrupter interferes with this test, disable interrupts. |
44 thread->DisableThreadInterrupts(); | 44 thread->DisableThreadInterrupts(); |
45 Monitor* monitor = new Monitor(); | 45 Monitor* monitor = new Monitor(); |
46 monitor->Enter(); | 46 monitor->Enter(); |
47 monitor->Exit(); | 47 monitor->Exit(); |
48 EXPECT_EQ(true, monitor->TryEnter()); | 48 EXPECT_EQ(true, monitor->TryEnter()); |
49 monitor->Exit(); | 49 monitor->Exit(); |
50 | 50 |
51 const int kNumAttempts = 5; | 51 const int kNumAttempts = 5; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 #endif | 383 #endif |
384 | 384 |
385 | 385 |
386 TEST_CASE(ThreadRegistry) { | 386 TEST_CASE(ThreadRegistry) { |
387 Isolate* orig = Thread::Current()->isolate(); | 387 Isolate* orig = Thread::Current()->isolate(); |
388 Zone* orig_zone = Thread::Current()->zone(); | 388 Zone* orig_zone = Thread::Current()->zone(); |
389 char* orig_str = orig_zone->PrintToString("foo"); | 389 char* orig_str = orig_zone->PrintToString("foo"); |
390 Dart_ExitIsolate(); | 390 Dart_ExitIsolate(); |
391 // Create and enter a new isolate. | 391 // Create and enter a new isolate. |
392 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 392 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
393 NULL); | 393 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
394 Zone* zone0 = Thread::Current()->zone(); | 394 Zone* zone0 = Thread::Current()->zone(); |
395 EXPECT(zone0 != orig_zone); | 395 EXPECT(zone0 != orig_zone); |
396 Dart_ShutdownIsolate(); | 396 Dart_ShutdownIsolate(); |
397 // Create and enter yet another isolate. | 397 // Create and enter yet another isolate. |
398 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 398 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
399 NULL); | 399 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
400 { | 400 { |
401 // Create a stack resource this time, and exercise it. | 401 // Create a stack resource this time, and exercise it. |
402 StackZone stack_zone(Thread::Current()); | 402 StackZone stack_zone(Thread::Current()); |
403 Zone* zone1 = Thread::Current()->zone(); | 403 Zone* zone1 = Thread::Current()->zone(); |
404 EXPECT(zone1 != zone0); | 404 EXPECT(zone1 != zone0); |
405 EXPECT(zone1 != orig_zone); | 405 EXPECT(zone1 != orig_zone); |
406 } | 406 } |
407 Dart_ShutdownIsolate(); | 407 Dart_ShutdownIsolate(); |
408 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(orig)); | 408 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(orig)); |
409 // Original zone should be preserved. | 409 // Original zone should be preserved. |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 TransitionVMToBlocked transition(thread); | 803 TransitionVMToBlocked transition(thread); |
804 MonitorLocker ml(&done_monitor); | 804 MonitorLocker ml(&done_monitor); |
805 if (done) { | 805 if (done) { |
806 break; | 806 break; |
807 } | 807 } |
808 } | 808 } |
809 } | 809 } |
810 } | 810 } |
811 | 811 |
812 } // namespace dart | 812 } // namespace dart |
OLD | NEW |