| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 // Parse command_line arguments. | 346 // Parse command_line arguments. |
| 347 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; | 347 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; |
| 348 uint32 unresponsive_threshold; | 348 uint32 unresponsive_threshold; |
| 349 ThreadWatcherList::ParseCommandLine(command_line, | 349 ThreadWatcherList::ParseCommandLine(command_line, |
| 350 &unresponsive_threshold, | 350 &unresponsive_threshold, |
| 351 &crash_on_hang_threads); | 351 &crash_on_hang_threads); |
| 352 | 352 |
| 353 // Verify the data. | 353 // Verify the data. |
| 354 base::StringTokenizer tokens(crash_on_hang_thread_names, ","); | 354 base::StringTokenizer tokens(crash_on_hang_thread_names, ","); |
| 355 std::vector<std::string> values; | |
| 356 while (tokens.GetNext()) { | 355 while (tokens.GetNext()) { |
| 357 const std::string& token = tokens.token(); | 356 std::vector<base::StringPiece> values = base::SplitStringPiece( |
| 358 base::SplitString(token, ':', &values); | 357 tokens.token_piece(), ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 359 std::string thread_name = values[0]; | 358 std::string thread_name = values[0].as_string(); |
| 360 | 359 |
| 361 ThreadWatcherList::CrashOnHangThreadMap::iterator it = | 360 ThreadWatcherList::CrashOnHangThreadMap::iterator it = |
| 362 crash_on_hang_threads.find(thread_name); | 361 crash_on_hang_threads.find(thread_name); |
| 363 bool crash_on_hang = (it != crash_on_hang_threads.end()); | 362 bool crash_on_hang = (it != crash_on_hang_threads.end()); |
| 364 EXPECT_TRUE(crash_on_hang); | 363 EXPECT_TRUE(crash_on_hang); |
| 365 EXPECT_LT(0u, it->second.live_threads_threshold); | 364 EXPECT_LT(0u, it->second.live_threads_threshold); |
| 366 EXPECT_LT(0u, it->second.unresponsive_threshold); | 365 EXPECT_LT(0u, it->second.unresponsive_threshold); |
| 367 } | 366 } |
| 368 } | 367 } |
| 369 | 368 |
| 370 TEST_F(ThreadWatcherTest, ThreadNamesAndLiveThresholdArgs) { | 369 TEST_F(ThreadWatcherTest, ThreadNamesAndLiveThresholdArgs) { |
| 371 // Setup command_line arguments. | 370 // Setup command_line arguments. |
| 372 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 371 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 373 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, | 372 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, |
| 374 thread_names_and_live_threshold); | 373 thread_names_and_live_threshold); |
| 375 | 374 |
| 376 // Parse command_line arguments. | 375 // Parse command_line arguments. |
| 377 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; | 376 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; |
| 378 uint32 unresponsive_threshold; | 377 uint32 unresponsive_threshold; |
| 379 ThreadWatcherList::ParseCommandLine(command_line, | 378 ThreadWatcherList::ParseCommandLine(command_line, |
| 380 &unresponsive_threshold, | 379 &unresponsive_threshold, |
| 381 &crash_on_hang_threads); | 380 &crash_on_hang_threads); |
| 382 | 381 |
| 383 // Verify the data. | 382 // Verify the data. |
| 384 base::StringTokenizer tokens(thread_names_and_live_threshold, ","); | 383 base::StringTokenizer tokens(thread_names_and_live_threshold, ","); |
| 385 std::vector<std::string> values; | |
| 386 while (tokens.GetNext()) { | 384 while (tokens.GetNext()) { |
| 387 const std::string& token = tokens.token(); | 385 std::vector<base::StringPiece> values = base::SplitStringPiece( |
| 388 base::SplitString(token, ':', &values); | 386 tokens.token_piece(), ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 389 std::string thread_name = values[0]; | 387 std::string thread_name = values[0].as_string(); |
| 390 | 388 |
| 391 ThreadWatcherList::CrashOnHangThreadMap::iterator it = | 389 ThreadWatcherList::CrashOnHangThreadMap::iterator it = |
| 392 crash_on_hang_threads.find(thread_name); | 390 crash_on_hang_threads.find(thread_name); |
| 393 bool crash_on_hang = (it != crash_on_hang_threads.end()); | 391 bool crash_on_hang = (it != crash_on_hang_threads.end()); |
| 394 EXPECT_TRUE(crash_on_hang); | 392 EXPECT_TRUE(crash_on_hang); |
| 395 EXPECT_EQ(4u, it->second.live_threads_threshold); | 393 EXPECT_EQ(4u, it->second.live_threads_threshold); |
| 396 EXPECT_LT(0u, it->second.unresponsive_threshold); | 394 EXPECT_LT(0u, it->second.unresponsive_threshold); |
| 397 } | 395 } |
| 398 } | 396 } |
| 399 | 397 |
| 400 TEST_F(ThreadWatcherTest, CrashOnHangThreadsAllArgs) { | 398 TEST_F(ThreadWatcherTest, CrashOnHangThreadsAllArgs) { |
| 401 // Setup command_line arguments. | 399 // Setup command_line arguments. |
| 402 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 400 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 403 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, | 401 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, |
| 404 crash_on_hang_thread_data); | 402 crash_on_hang_thread_data); |
| 405 | 403 |
| 406 // Parse command_line arguments. | 404 // Parse command_line arguments. |
| 407 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; | 405 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; |
| 408 uint32 unresponsive_threshold; | 406 uint32 unresponsive_threshold; |
| 409 ThreadWatcherList::ParseCommandLine(command_line, | 407 ThreadWatcherList::ParseCommandLine(command_line, |
| 410 &unresponsive_threshold, | 408 &unresponsive_threshold, |
| 411 &crash_on_hang_threads); | 409 &crash_on_hang_threads); |
| 412 | 410 |
| 413 // Verify the data. | 411 // Verify the data. |
| 414 base::StringTokenizer tokens(crash_on_hang_thread_data, ","); | 412 base::StringTokenizer tokens(crash_on_hang_thread_data, ","); |
| 415 std::vector<std::string> values; | |
| 416 while (tokens.GetNext()) { | 413 while (tokens.GetNext()) { |
| 417 const std::string& token = tokens.token(); | 414 std::vector<base::StringPiece> values = base::SplitStringPiece( |
| 418 base::SplitString(token, ':', &values); | 415 tokens.token_piece(), ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 419 std::string thread_name = values[0]; | 416 std::string thread_name = values[0].as_string(); |
| 420 | 417 |
| 421 ThreadWatcherList::CrashOnHangThreadMap::iterator it = | 418 ThreadWatcherList::CrashOnHangThreadMap::iterator it = |
| 422 crash_on_hang_threads.find(thread_name); | 419 crash_on_hang_threads.find(thread_name); |
| 423 | 420 |
| 424 bool crash_on_hang = (it != crash_on_hang_threads.end()); | 421 bool crash_on_hang = (it != crash_on_hang_threads.end()); |
| 425 EXPECT_TRUE(crash_on_hang); | 422 EXPECT_TRUE(crash_on_hang); |
| 426 | 423 |
| 427 uint32 crash_live_threads_threshold = it->second.live_threads_threshold; | 424 uint32 crash_live_threads_threshold = it->second.live_threads_threshold; |
| 428 EXPECT_EQ(5u, crash_live_threads_threshold); | 425 EXPECT_EQ(5u, crash_live_threads_threshold); |
| 429 | 426 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 message_loop_for_ui.task_runner()->PostDelayedTask( | 725 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 729 FROM_HERE, message_loop_for_ui.QuitClosure(), | 726 FROM_HERE, message_loop_for_ui.QuitClosure(), |
| 730 base::TimeDelta::FromSeconds( | 727 base::TimeDelta::FromSeconds( |
| 731 ThreadWatcherList::g_initialize_delay_seconds)); | 728 ThreadWatcherList::g_initialize_delay_seconds)); |
| 732 message_loop_for_ui.Run(); | 729 message_loop_for_ui.Run(); |
| 733 | 730 |
| 734 CheckState(false /* has_thread_watcher_list */, | 731 CheckState(false /* has_thread_watcher_list */, |
| 735 true /* stopped */, | 732 true /* stopped */, |
| 736 "Stopped"); | 733 "Stopped"); |
| 737 } | 734 } |
| OLD | NEW |