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

Unified Diff: runtime/vm/thread_test.cc

Issue 1393423005: Add ThreadIterator for iterating over all Threads (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 side-by-side diff with in-line comments
Download patch
« runtime/vm/thread.cc ('K') | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_test.cc
diff --git a/runtime/vm/thread_test.cc b/runtime/vm/thread_test.cc
index a412dcebc7009b197bb47f36c0bdf92040af2255..2f9baef364c7187ad9202b345c809b0c8f73e24d 100644
--- a/runtime/vm/thread_test.cc
+++ b/runtime/vm/thread_test.cc
@@ -407,6 +407,126 @@ TEST_CASE(SafepointTestVM) {
}
+TEST_CASE(ThreadIterator_Count) {
+ intptr_t thread_count_0 = 0;
+ intptr_t thread_count_1 = 0;
+
+ {
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ thread_count_0++;
+ }
+ }
+
+ {
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ thread_count_1++;
+ }
+ }
+
+ EXPECT(thread_count_0 > 0);
+ EXPECT(thread_count_1 > 0);
+ EXPECT(thread_count_0 >= thread_count_1);
+}
+
+
+TEST_CASE(ThreadIterator_FindSelf) {
+ Thread* current = Thread::Current();
+
+ bool found_self = false;
+
+ {
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ if (thread == current) {
+ found_self = true;
+ break;
+ }
+ }
+ }
+
+ EXPECT(found_self);
+}
+
+
+class ThreadIteratorTestHelper : public AllStatic {
+ public:
+ static void AddThreadToList(Thread* thread) {
+ Thread::AddThreadToList(thread);
+ }
+
+ static void RemoveThreadFromList(Thread* thread) {
+ Thread::RemoveThreadFromList(thread);
+ }
+};
+
+
+TEST_CASE(ThreadIterator_RemoveSelf) {
+ Thread* current = Thread::Current();
+
+ // Remove self.
+ 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
+
+ // Not in thread list.
+ {
+ bool found_self = false;
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ if (thread == current) {
+ found_self = true;
+ break;
+ }
+ }
+ EXPECT(!found_self);
+ }
+
+ ThreadIteratorTestHelper::AddThreadToList(current);
+
+ // Now in thread list.
+ {
+ bool found_self = false;
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ if (thread == current) {
+ found_self = true;
+ break;
+ }
+ }
+ EXPECT(found_self);
+ }
+
+ // Remove self.
+ ThreadIteratorTestHelper::RemoveThreadFromList(current);
+
+ // Not in thread list.
+ {
+ bool found_self = false;
+ ThreadIterator ti;
+ while (ti.HasNext()) {
+ Thread* thread = ti.Next();
+ EXPECT(thread != NULL);
+ if (thread == current) {
+ found_self = true;
+ break;
+ }
+ }
+ EXPECT(!found_self);
+ }
+
+ ThreadIteratorTestHelper::AddThreadToList(current);
+}
+
// Test rendezvous of:
// - helpers in VM code, and
// - main thread in VM code,
« runtime/vm/thread.cc ('K') | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698