Chromium Code Reviews| 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/thread_pool.h" | 10 #include "vm/thread_pool.h" |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 while (true) { | 400 while (true) { |
| 401 isolate->thread_registry()->CheckSafepoint(); | 401 isolate->thread_registry()->CheckSafepoint(); |
| 402 MutexLocker ml(&mutex); | 402 MutexLocker ml(&mutex); |
| 403 if (exited == SafepointTestTask::kTaskCount) { | 403 if (exited == SafepointTestTask::kTaskCount) { |
| 404 break; | 404 break; |
| 405 } | 405 } |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 | 409 |
| 410 TEST_CASE(ThreadIterator_Count) { | |
| 411 intptr_t thread_count_0 = 0; | |
| 412 intptr_t thread_count_1 = 0; | |
| 413 | |
| 414 { | |
| 415 ThreadIterator ti; | |
| 416 while (ti.HasNext()) { | |
| 417 Thread* thread = ti.Next(); | |
| 418 EXPECT(thread != NULL); | |
| 419 thread_count_0++; | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 { | |
| 424 ThreadIterator ti; | |
| 425 while (ti.HasNext()) { | |
| 426 Thread* thread = ti.Next(); | |
| 427 EXPECT(thread != NULL); | |
| 428 thread_count_1++; | |
| 429 } | |
| 430 } | |
| 431 | |
| 432 EXPECT(thread_count_0 > 0); | |
| 433 EXPECT(thread_count_1 > 0); | |
| 434 EXPECT(thread_count_0 >= thread_count_1); | |
| 435 } | |
| 436 | |
| 437 | |
| 438 TEST_CASE(ThreadIterator_FindSelf) { | |
| 439 Thread* current = Thread::Current(); | |
| 440 | |
| 441 bool found_self = false; | |
| 442 | |
| 443 { | |
| 444 ThreadIterator ti; | |
| 445 while (ti.HasNext()) { | |
| 446 Thread* thread = ti.Next(); | |
| 447 EXPECT(thread != NULL); | |
| 448 if (thread == current) { | |
| 449 found_self = true; | |
| 450 break; | |
| 451 } | |
| 452 } | |
| 453 } | |
| 454 | |
| 455 EXPECT(found_self); | |
| 456 } | |
| 457 | |
| 458 | |
| 459 class ThreadIteratorTestHelper : public AllStatic { | |
| 460 public: | |
| 461 static void AddThreadToList(Thread* thread) { | |
| 462 Thread::AddThreadToList(thread); | |
| 463 } | |
| 464 | |
| 465 static void RemoveThreadFromList(Thread* thread) { | |
| 466 Thread::RemoveThreadFromList(thread); | |
| 467 } | |
| 468 }; | |
| 469 | |
| 470 | |
| 471 TEST_CASE(ThreadIterator_RemoveSelf) { | |
| 472 Thread* current = Thread::Current(); | |
| 473 | |
| 474 // Remove self. | |
| 475 ThreadIteratorTestHelper::RemoveThreadFromList(current); | |
|
siva
2015/10/12 23:03:14
This test does not seem right, we should not allow
Cutch
2015/10/13 16:41:24
I've rewritten the test and added assertions that
| |
| 476 | |
| 477 // Not in thread list. | |
| 478 { | |
| 479 bool found_self = false; | |
| 480 ThreadIterator ti; | |
| 481 while (ti.HasNext()) { | |
| 482 Thread* thread = ti.Next(); | |
| 483 EXPECT(thread != NULL); | |
| 484 if (thread == current) { | |
| 485 found_self = true; | |
| 486 break; | |
| 487 } | |
| 488 } | |
| 489 EXPECT(!found_self); | |
| 490 } | |
| 491 | |
| 492 ThreadIteratorTestHelper::AddThreadToList(current); | |
| 493 | |
| 494 // Now in thread list. | |
| 495 { | |
| 496 bool found_self = false; | |
| 497 ThreadIterator ti; | |
| 498 while (ti.HasNext()) { | |
| 499 Thread* thread = ti.Next(); | |
| 500 EXPECT(thread != NULL); | |
| 501 if (thread == current) { | |
| 502 found_self = true; | |
| 503 break; | |
| 504 } | |
| 505 } | |
| 506 EXPECT(found_self); | |
| 507 } | |
| 508 | |
| 509 // Remove self. | |
| 510 ThreadIteratorTestHelper::RemoveThreadFromList(current); | |
| 511 | |
| 512 // Not in thread list. | |
| 513 { | |
| 514 bool found_self = false; | |
| 515 ThreadIterator ti; | |
| 516 while (ti.HasNext()) { | |
| 517 Thread* thread = ti.Next(); | |
| 518 EXPECT(thread != NULL); | |
| 519 if (thread == current) { | |
| 520 found_self = true; | |
| 521 break; | |
| 522 } | |
| 523 } | |
| 524 EXPECT(!found_self); | |
| 525 } | |
| 526 | |
| 527 ThreadIteratorTestHelper::AddThreadToList(current); | |
| 528 } | |
| 529 | |
| 410 // Test rendezvous of: | 530 // Test rendezvous of: |
| 411 // - helpers in VM code, and | 531 // - helpers in VM code, and |
| 412 // - main thread in VM code, | 532 // - main thread in VM code, |
| 413 // organized by | 533 // organized by |
| 414 // - main thread, and | 534 // - main thread, and |
| 415 // - helpers. | 535 // - helpers. |
| 416 TEST_CASE(SafepointTestVM2) { | 536 TEST_CASE(SafepointTestVM2) { |
| 417 Isolate* isolate = thread->isolate(); | 537 Isolate* isolate = thread->isolate(); |
| 418 Mutex mutex; | 538 Mutex mutex; |
| 419 intptr_t expected_count = 0; | 539 intptr_t expected_count = 0; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 isolate->thread_registry()->CheckSafepoint(); | 620 isolate->thread_registry()->CheckSafepoint(); |
| 501 MonitorLocker ml(&done_monitor); | 621 MonitorLocker ml(&done_monitor); |
| 502 if (done) { | 622 if (done) { |
| 503 break; | 623 break; |
| 504 } | 624 } |
| 505 } | 625 } |
| 506 } | 626 } |
| 507 } | 627 } |
| 508 | 628 |
| 509 } // namespace dart | 629 } // namespace dart |
| OLD | NEW |