OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads(); | 148 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads(); |
149 | 149 |
150 // If other tests ran in this process previously, threads may have been | 150 // If other tests ran in this process previously, threads may have been |
151 // created and may still be running. This check must look for at least one | 151 // created and may still be running. This check must look for at least one |
152 // thread, not exactly one thread. | 152 // thread, not exactly one thread. |
153 ASSERT_GE(threads.size(), 1u); | 153 ASSERT_GE(threads.size(), 1u); |
154 | 154 |
155 EXPECT_EQ(PthreadToThreadID(pthread_self()), threads[0].id); | 155 EXPECT_EQ(PthreadToThreadID(pthread_self()), threads[0].id); |
156 | 156 |
157 mach_port_t thread_self = MachThreadSelf(); | 157 thread_t thread_self = MachThreadSelf(); |
158 EXPECT_EQ(thread_self, threads[0].port); | 158 EXPECT_EQ(thread_self, threads[0].port); |
159 | 159 |
160 EXPECT_EQ(0, threads[0].suspend_count); | 160 EXPECT_EQ(0, threads[0].suspend_count); |
161 } | 161 } |
162 | 162 |
163 class TestThreadPool { | 163 class TestThreadPool { |
164 public: | 164 public: |
165 struct ThreadExpectation { | 165 struct ThreadExpectation { |
166 mach_vm_address_t stack_address; | 166 mach_vm_address_t stack_address; |
167 int suspend_count; | 167 int suspend_count; |
168 }; | 168 }; |
169 | 169 |
170 TestThreadPool() : thread_infos_() { | 170 TestThreadPool() : thread_infos_() { |
171 } | 171 } |
172 | 172 |
173 // Resumes suspended threads, signals each thread’s exit semaphore asking it | 173 // Resumes suspended threads, signals each thread’s exit semaphore asking it |
174 // to exit, and joins each thread, blocking until they have all exited. | 174 // to exit, and joins each thread, blocking until they have all exited. |
175 ~TestThreadPool() { | 175 ~TestThreadPool() { |
176 for (ThreadInfo* thread_info : thread_infos_) { | 176 for (ThreadInfo* thread_info : thread_infos_) { |
177 mach_port_t thread_port = pthread_mach_thread_np(thread_info->pthread); | 177 thread_t thread_port = pthread_mach_thread_np(thread_info->pthread); |
178 while (thread_info->suspend_count > 0) { | 178 while (thread_info->suspend_count > 0) { |
179 kern_return_t kr = thread_resume(thread_port); | 179 kern_return_t kr = thread_resume(thread_port); |
180 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); | 180 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); |
181 --thread_info->suspend_count; | 181 --thread_info->suspend_count; |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 for (const ThreadInfo* thread_info : thread_infos_) { | 185 for (const ThreadInfo* thread_info : thread_infos_) { |
186 dispatch_semaphore_signal(thread_info->exit_semaphore); | 186 dispatch_semaphore_signal(thread_info->exit_semaphore); |
187 } | 187 } |
(...skipping 25 matching lines...) Expand all Loading... |
213 long rv = dispatch_semaphore_wait(thread_info->ready_semaphore, | 213 long rv = dispatch_semaphore_wait(thread_info->ready_semaphore, |
214 DISPATCH_TIME_FOREVER); | 214 DISPATCH_TIME_FOREVER); |
215 ASSERT_EQ(0, rv); | 215 ASSERT_EQ(0, rv); |
216 } | 216 } |
217 | 217 |
218 // If present, suspend the thread at indices 1 through 3 the same number of | 218 // If present, suspend the thread at indices 1 through 3 the same number of |
219 // times as their index. This tests reporting of suspend counts. | 219 // times as their index. This tests reporting of suspend counts. |
220 for (size_t thread_index = 1; | 220 for (size_t thread_index = 1; |
221 thread_index < thread_infos_.size() && thread_index < 4; | 221 thread_index < thread_infos_.size() && thread_index < 4; |
222 ++thread_index) { | 222 ++thread_index) { |
223 mach_port_t thread_port = | 223 thread_t thread_port = |
224 pthread_mach_thread_np(thread_infos_[thread_index]->pthread); | 224 pthread_mach_thread_np(thread_infos_[thread_index]->pthread); |
225 for (size_t suspend_count = 0; | 225 for (size_t suspend_count = 0; |
226 suspend_count < thread_index; | 226 suspend_count < thread_index; |
227 ++suspend_count) { | 227 ++suspend_count) { |
228 kern_return_t kr = thread_suspend(thread_port); | 228 kern_return_t kr = thread_suspend(thread_port); |
229 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_suspend"); | 229 EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_suspend"); |
230 if (kr == KERN_SUCCESS) { | 230 if (kr == KERN_SUCCESS) { |
231 ++thread_infos_[thread_index]->suspend_count; | 231 ++thread_infos_[thread_index]->suspend_count; |
232 } | 232 } |
233 } | 233 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 412 |
413 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads(); | 413 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads(); |
414 | 414 |
415 // Other tests that have run previously may have resulted in the creation of | 415 // Other tests that have run previously may have resulted in the creation of |
416 // threads that still exist, so pass true for |tolerate_extra_threads|. | 416 // threads that still exist, so pass true for |tolerate_extra_threads|. |
417 ExpectSeveralThreads(&thread_map, threads, true); | 417 ExpectSeveralThreads(&thread_map, threads, true); |
418 | 418 |
419 // When testing in-process, verify that when this thread shows up in the | 419 // When testing in-process, verify that when this thread shows up in the |
420 // vector, it has the expected thread port, and that this thread port only | 420 // vector, it has the expected thread port, and that this thread port only |
421 // shows up once. | 421 // shows up once. |
422 mach_port_t thread_self = MachThreadSelf(); | 422 thread_t thread_self = MachThreadSelf(); |
423 bool found_thread_self = false; | 423 bool found_thread_self = false; |
424 for (const ProcessReader::Thread& thread : threads) { | 424 for (const ProcessReader::Thread& thread : threads) { |
425 if (thread.port == thread_self) { | 425 if (thread.port == thread_self) { |
426 EXPECT_FALSE(found_thread_self); | 426 EXPECT_FALSE(found_thread_self); |
427 found_thread_self = true; | 427 found_thread_self = true; |
428 EXPECT_EQ(self_thread_id, thread.id); | 428 EXPECT_EQ(self_thread_id, thread.id); |
429 } | 429 } |
430 } | 430 } |
431 EXPECT_TRUE(found_thread_self); | 431 EXPECT_TRUE(found_thread_self); |
432 } | 432 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 | 762 |
763 DISALLOW_COPY_AND_ASSIGN(ProcessReaderModulesChild); | 763 DISALLOW_COPY_AND_ASSIGN(ProcessReaderModulesChild); |
764 }; | 764 }; |
765 | 765 |
766 TEST(ProcessReader, ChildModules) { | 766 TEST(ProcessReader, ChildModules) { |
767 ProcessReaderModulesChild process_reader_modules_child; | 767 ProcessReaderModulesChild process_reader_modules_child; |
768 process_reader_modules_child.Run(); | 768 process_reader_modules_child.Run(); |
769 } | 769 } |
770 | 770 |
771 } // namespace | 771 } // namespace |
OLD | NEW |