Chromium Code Reviews| 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, |