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

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

Issue 1425463004: Fix ThreadIterator_AddFindRemove test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « runtime/vm/thread.cc ('k') | no next file » | 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/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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 thread_count_1++; 428 thread_count_1++;
429 } 429 }
430 } 430 }
431 431
432 EXPECT(thread_count_0 > 0); 432 EXPECT(thread_count_0 > 0);
433 EXPECT(thread_count_1 > 0); 433 EXPECT(thread_count_1 > 0);
434 EXPECT(thread_count_0 >= thread_count_1); 434 EXPECT(thread_count_0 >= thread_count_1);
435 } 435 }
436 436
437 437
438 static bool ThreadInList(Thread* thread) {
439 ThreadIterator it;
440 while (it.HasNext()) {
441 Thread* t = it.Next();
442 if (t == thread) {
443 return true;
444 }
445 }
446 return false;
447 }
448
449
450 TEST_CASE(ThreadIterator_FindSelf) { 438 TEST_CASE(ThreadIterator_FindSelf) {
451 Thread* current = Thread::Current(); 439 Thread* current = Thread::Current();
452 EXPECT(ThreadInList(current)); 440 EXPECT(Thread::IsThreadInList(current->join_id()));
453 } 441 }
454 442
455 443
456 struct ThreadIteratorTestParams { 444 struct ThreadIteratorTestParams {
457 Isolate* isolate; 445 ThreadId spawned_thread_join_id;
458 Thread* spawned_thread;
459 ThreadJoinId spawned_thread_join_id;
460 Monitor* monitor; 446 Monitor* monitor;
461 }; 447 };
462 448
463 449
464 void ThreadIteratorTestMain(uword parameter) { 450 void ThreadIteratorTestMain(uword parameter) {
465 Thread::EnsureInit(); 451 Thread::EnsureInit();
466 ThreadIteratorTestParams* params = 452 ThreadIteratorTestParams* params =
467 reinterpret_cast<ThreadIteratorTestParams*>(parameter); 453 reinterpret_cast<ThreadIteratorTestParams*>(parameter);
468 Isolate* isolate = params->isolate;
469 EXPECT(isolate != NULL);
470 Thread* thread = Thread::Current(); 454 Thread* thread = Thread::Current();
471 EXPECT(thread != NULL); 455 EXPECT(thread != NULL);
472 456
473 MonitorLocker ml(params->monitor); 457 MonitorLocker ml(params->monitor);
474 params->spawned_thread = thread; 458 params->spawned_thread_join_id = thread->join_id();
475 params->spawned_thread_join_id = OSThread::GetCurrentThreadJoinId();
476 EXPECT(params->spawned_thread_join_id != OSThread::kInvalidThreadJoinId); 459 EXPECT(params->spawned_thread_join_id != OSThread::kInvalidThreadJoinId);
477 EXPECT(ThreadInList(thread)); 460 EXPECT(Thread::IsThreadInList(thread->join_id()));
478 ml.Notify(); 461 ml.Notify();
479 } 462 }
480 463
481 464
482 // NOTE: This test case also verifies that known TLS destructors are called 465 // NOTE: This test case also verifies that known TLS destructors are called
483 // on Windows. See |OnThreadExit| in os_thread_win.cc for more details. 466 // on Windows. See |OnDartThreadExit| in os_thread_win.cc for more details.
484 TEST_CASE(ThreadIterator_AddFindRemove) { 467 TEST_CASE(ThreadIterator_AddFindRemove) {
485 Isolate* isolate = thread->isolate();
486 ThreadIteratorTestParams params; 468 ThreadIteratorTestParams params;
487 params.isolate = isolate;
488 params.spawned_thread = NULL;
489 params.spawned_thread_join_id = OSThread::kInvalidThreadJoinId; 469 params.spawned_thread_join_id = OSThread::kInvalidThreadJoinId;
490 params.monitor = new Monitor(); 470 params.monitor = new Monitor();
491 471
492 { 472 {
493 MonitorLocker ml(params.monitor); 473 MonitorLocker ml(params.monitor);
494 EXPECT(params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId); 474 EXPECT(params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId);
495 EXPECT(params.spawned_thread == NULL);
496 // Spawn thread and wait to receive the thread join id. 475 // Spawn thread and wait to receive the thread join id.
497 OSThread::Start(ThreadIteratorTestMain, reinterpret_cast<uword>(&params)); 476 OSThread::Start(ThreadIteratorTestMain, reinterpret_cast<uword>(&params));
498 while (params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId) { 477 while (params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId) {
499 ml.Wait(); 478 ml.Wait();
500 } 479 }
501 EXPECT(params.spawned_thread_join_id != OSThread::kInvalidThreadJoinId); 480 EXPECT(params.spawned_thread_join_id != OSThread::kInvalidThreadJoinId);
502 EXPECT(params.spawned_thread != NULL);
503 // Join thread. 481 // Join thread.
504 OSThread::Join(params.spawned_thread_join_id); 482 OSThread::Join(params.spawned_thread_join_id);
505 } 483 }
506 484
507 for (intptr_t i = 0; i < 10; i++) { 485 EXPECT(!Thread::IsThreadInList(params.spawned_thread_join_id))
508 // Sleep for 10 milliseconds.
509 OS::Sleep(10);
510 if (!ThreadInList(params.spawned_thread)) {
511 break;
512 }
513 }
514
515 EXPECT(!ThreadInList(params.spawned_thread))
516 486
517 delete params.monitor; 487 delete params.monitor;
518 } 488 }
519 489
520 490
521 // Test rendezvous of: 491 // Test rendezvous of:
522 // - helpers in VM code, and 492 // - helpers in VM code, and
523 // - main thread in VM code, 493 // - main thread in VM code,
524 // organized by 494 // organized by
525 // - main thread, and 495 // - main thread, and
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 isolate->thread_registry()->CheckSafepoint(); 581 isolate->thread_registry()->CheckSafepoint();
612 MonitorLocker ml(&done_monitor); 582 MonitorLocker ml(&done_monitor);
613 if (done) { 583 if (done) {
614 break; 584 break;
615 } 585 }
616 } 586 }
617 } 587 }
618 } 588 }
619 589
620 } // namespace dart 590 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698