| 275 | using ThreadNameMap = std::map<pid_t, std::string>; |
| 276 | |
| 277 | void ExpectThreads(const ThreadMap& thread_map, |
| 278 | const ThreadNameMap& thread_name_map, |
| 279 | const std::vector<ProcessReaderLinux::Thread>& threads, |
| 280 | PtraceConnection* connection) { |
| 281 | ASSERT_EQ(threads.size(), thread_map.size()); |
| 282 | ASSERT_EQ(threads.size(), thread_name_map.size()); |
| 283 | |
| 284 | MemoryMap memory_map; |
| 285 | ASSERT_TRUE(memory_map.Initialize(connection)); |
| 286 | |
| 287 | for (const auto& thread : threads) { |
| 288 | SCOPED_TRACE( |
| 289 | base::StringPrintf("Thread id %d, name %s, tls 0x%" PRIx64 |
| 290 | ", stack addr 0x%" PRIx64 ", stack size 0x%" PRIx64, |
| 291 | thread.tid, |
| 292 | thread.name.c_str(), |
| 293 | thread.thread_info.thread_specific_data_address, |
| 294 | thread.stack_region_address, |
| 295 | thread.stack_region_size)); |
| 296 | |
| 297 | const auto& iterator = thread_map.find(thread.tid); |
| 298 | ASSERT_NE(iterator, thread_map.end()); |
| 299 | |
| 300 | EXPECT_EQ(thread.thread_info.thread_specific_data_address, |
| 301 | iterator->second.tls); |
| 302 | |
| 303 | ASSERT_TRUE(memory_map.FindMapping(thread.stack_region_address)); |
| 304 | ASSERT_TRUE(memory_map.FindMapping(thread.stack_region_address + |
| 305 | thread.stack_region_size - 1)); |
| 306 | |
| 307 | #if !defined(ADDRESS_SANITIZER) |
| 308 | // AddressSanitizer causes stack variables to be stored separately from the |
| 309 | // call stack. |
| 310 | EXPECT_LE( |
| 311 | thread.stack_region_address, |
| 312 | connection->Memory()->PointerToAddress(iterator->second.stack_address)); |
| 313 | EXPECT_GE( |
| 314 | thread.stack_region_address + thread.stack_region_size, |
| 315 | connection->Memory()->PointerToAddress(iterator->second.stack_address)); |
| 316 | #endif // !defined(ADDRESS_SANITIZER) |
| 317 | |
| 318 | if (iterator->second.max_stack_size) { |
| 319 | EXPECT_LT(thread.stack_region_size, iterator->second.max_stack_size); |
| 320 | } |
| 321 | |
| 322 | EXPECT_EQ(thread.sched_policy, iterator->second.sched_policy); |
| 323 | EXPECT_EQ(thread.static_priority, iterator->second.static_priority); |
| 324 | EXPECT_EQ(thread.nice_value, iterator->second.nice_value); |
| 325 | |
| 326 | const auto& thread_name_iterator = thread_name_map.find(thread.tid); |
| 327 | ASSERT_NE(thread_name_iterator, thread_name_map.end()); |
| 328 | EXPECT_EQ(thread.name, thread_name_iterator->second); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | class ChildThreadTest : public Multiprocess { |
| 333 | public: |
no test coverage detected