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

Side by Side Diff: chrome/browser/metrics/thread_watcher_unittest.cc

Issue 816403003: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years 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 unified diff | Download patch
OLDNEW
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/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB; 330 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB;
331 const std::string ThreadWatcherTest::db_thread_name = "DB"; 331 const std::string ThreadWatcherTest::db_thread_name = "DB";
332 const std::string ThreadWatcherTest::crash_on_hang_thread_names = "UI,IO"; 332 const std::string ThreadWatcherTest::crash_on_hang_thread_names = "UI,IO";
333 const std::string ThreadWatcherTest::thread_names_and_live_threshold = 333 const std::string ThreadWatcherTest::thread_names_and_live_threshold =
334 "UI:4,IO:4"; 334 "UI:4,IO:4";
335 const std::string ThreadWatcherTest::crash_on_hang_thread_data = 335 const std::string ThreadWatcherTest::crash_on_hang_thread_data =
336 "UI:5:12,IO:5:12,FILE:5:12"; 336 "UI:5:12,IO:5:12,FILE:5:12";
337 337
338 TEST_F(ThreadWatcherTest, ThreadNamesOnlyArgs) { 338 TEST_F(ThreadWatcherTest, ThreadNamesOnlyArgs) {
339 // Setup command_line arguments. 339 // Setup command_line arguments.
340 CommandLine command_line(CommandLine::NO_PROGRAM); 340 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
341 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, 341 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads,
342 crash_on_hang_thread_names); 342 crash_on_hang_thread_names);
343 343
344 // Parse command_line arguments. 344 // Parse command_line arguments.
345 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; 345 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads;
346 uint32 unresponsive_threshold; 346 uint32 unresponsive_threshold;
347 ThreadWatcherList::ParseCommandLine(command_line, 347 ThreadWatcherList::ParseCommandLine(command_line,
348 &unresponsive_threshold, 348 &unresponsive_threshold,
349 &crash_on_hang_threads); 349 &crash_on_hang_threads);
350 350
351 // Verify the data. 351 // Verify the data.
352 base::StringTokenizer tokens(crash_on_hang_thread_names, ","); 352 base::StringTokenizer tokens(crash_on_hang_thread_names, ",");
353 std::vector<std::string> values; 353 std::vector<std::string> values;
354 while (tokens.GetNext()) { 354 while (tokens.GetNext()) {
355 const std::string& token = tokens.token(); 355 const std::string& token = tokens.token();
356 base::SplitString(token, ':', &values); 356 base::SplitString(token, ':', &values);
357 std::string thread_name = values[0]; 357 std::string thread_name = values[0];
358 358
359 ThreadWatcherList::CrashOnHangThreadMap::iterator it = 359 ThreadWatcherList::CrashOnHangThreadMap::iterator it =
360 crash_on_hang_threads.find(thread_name); 360 crash_on_hang_threads.find(thread_name);
361 bool crash_on_hang = (it != crash_on_hang_threads.end()); 361 bool crash_on_hang = (it != crash_on_hang_threads.end());
362 EXPECT_TRUE(crash_on_hang); 362 EXPECT_TRUE(crash_on_hang);
363 EXPECT_LT(0u, it->second.live_threads_threshold); 363 EXPECT_LT(0u, it->second.live_threads_threshold);
364 EXPECT_LT(0u, it->second.unresponsive_threshold); 364 EXPECT_LT(0u, it->second.unresponsive_threshold);
365 } 365 }
366 } 366 }
367 367
368 TEST_F(ThreadWatcherTest, ThreadNamesAndLiveThresholdArgs) { 368 TEST_F(ThreadWatcherTest, ThreadNamesAndLiveThresholdArgs) {
369 // Setup command_line arguments. 369 // Setup command_line arguments.
370 CommandLine command_line(CommandLine::NO_PROGRAM); 370 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
371 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, 371 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads,
372 thread_names_and_live_threshold); 372 thread_names_and_live_threshold);
373 373
374 // Parse command_line arguments. 374 // Parse command_line arguments.
375 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; 375 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads;
376 uint32 unresponsive_threshold; 376 uint32 unresponsive_threshold;
377 ThreadWatcherList::ParseCommandLine(command_line, 377 ThreadWatcherList::ParseCommandLine(command_line,
378 &unresponsive_threshold, 378 &unresponsive_threshold,
379 &crash_on_hang_threads); 379 &crash_on_hang_threads);
380 380
381 // Verify the data. 381 // Verify the data.
382 base::StringTokenizer tokens(thread_names_and_live_threshold, ","); 382 base::StringTokenizer tokens(thread_names_and_live_threshold, ",");
383 std::vector<std::string> values; 383 std::vector<std::string> values;
384 while (tokens.GetNext()) { 384 while (tokens.GetNext()) {
385 const std::string& token = tokens.token(); 385 const std::string& token = tokens.token();
386 base::SplitString(token, ':', &values); 386 base::SplitString(token, ':', &values);
387 std::string thread_name = values[0]; 387 std::string thread_name = values[0];
388 388
389 ThreadWatcherList::CrashOnHangThreadMap::iterator it = 389 ThreadWatcherList::CrashOnHangThreadMap::iterator it =
390 crash_on_hang_threads.find(thread_name); 390 crash_on_hang_threads.find(thread_name);
391 bool crash_on_hang = (it != crash_on_hang_threads.end()); 391 bool crash_on_hang = (it != crash_on_hang_threads.end());
392 EXPECT_TRUE(crash_on_hang); 392 EXPECT_TRUE(crash_on_hang);
393 EXPECT_EQ(4u, it->second.live_threads_threshold); 393 EXPECT_EQ(4u, it->second.live_threads_threshold);
394 EXPECT_LT(0u, it->second.unresponsive_threshold); 394 EXPECT_LT(0u, it->second.unresponsive_threshold);
395 } 395 }
396 } 396 }
397 397
398 TEST_F(ThreadWatcherTest, CrashOnHangThreadsAllArgs) { 398 TEST_F(ThreadWatcherTest, CrashOnHangThreadsAllArgs) {
399 // Setup command_line arguments. 399 // Setup command_line arguments.
400 CommandLine command_line(CommandLine::NO_PROGRAM); 400 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
401 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, 401 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads,
402 crash_on_hang_thread_data); 402 crash_on_hang_thread_data);
403 403
404 // Parse command_line arguments. 404 // Parse command_line arguments.
405 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; 405 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads;
406 uint32 unresponsive_threshold; 406 uint32 unresponsive_threshold;
407 ThreadWatcherList::ParseCommandLine(command_line, 407 ThreadWatcherList::ParseCommandLine(command_line,
408 &unresponsive_threshold, 408 &unresponsive_threshold,
409 &crash_on_hang_threads); 409 &crash_on_hang_threads);
410 410
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); 690 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui);
691 691
692 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); 692 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread());
693 watchdog_thread_->Start(); 693 watchdog_thread_->Start();
694 694
695 // See http://crbug.com/347887. 695 // See http://crbug.com/347887.
696 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, 696 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_,
697 // whilst StopWatchingAll() will just PostTask to destroy it. 697 // whilst StopWatchingAll() will just PostTask to destroy it.
698 // Ensure that when Stop is called, Start will NOT create 698 // Ensure that when Stop is called, Start will NOT create
699 // g_thread_watcher_list_ later on. 699 // g_thread_watcher_list_ later on.
700 ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess()); 700 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess());
701 ThreadWatcherList::StopWatchingAll(); 701 ThreadWatcherList::StopWatchingAll();
702 message_loop_for_ui.PostDelayedTask( 702 message_loop_for_ui.PostDelayedTask(
703 FROM_HERE, 703 FROM_HERE,
704 message_loop_for_ui.QuitClosure(), 704 message_loop_for_ui.QuitClosure(),
705 base::TimeDelta::FromSeconds( 705 base::TimeDelta::FromSeconds(
706 ThreadWatcherList::g_initialize_delay_seconds)); 706 ThreadWatcherList::g_initialize_delay_seconds));
707 message_loop_for_ui.Run(); 707 message_loop_for_ui.Run();
708 708
709 CheckState(false /* has_thread_watcher_list */, 709 CheckState(false /* has_thread_watcher_list */,
710 true /* stopped */, 710 true /* stopped */,
711 "Start / Stopped"); 711 "Start / Stopped");
712 712
713 // Proceed with just |StartWatchingAll| and ensure it'll be started. 713 // Proceed with just |StartWatchingAll| and ensure it'll be started.
714 ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess()); 714 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess());
715 message_loop_for_ui.PostDelayedTask( 715 message_loop_for_ui.PostDelayedTask(
716 FROM_HERE, 716 FROM_HERE,
717 message_loop_for_ui.QuitClosure(), 717 message_loop_for_ui.QuitClosure(),
718 base::TimeDelta::FromSeconds( 718 base::TimeDelta::FromSeconds(
719 ThreadWatcherList::g_initialize_delay_seconds + 1)); 719 ThreadWatcherList::g_initialize_delay_seconds + 1));
720 message_loop_for_ui.Run(); 720 message_loop_for_ui.Run();
721 721
722 CheckState(true /* has_thread_watcher_list */, 722 CheckState(true /* has_thread_watcher_list */,
723 false /* stopped */, 723 false /* stopped */,
724 "Started"); 724 "Started");
725 725
726 // Finally, StopWatchingAll() must stop. 726 // Finally, StopWatchingAll() must stop.
727 ThreadWatcherList::StopWatchingAll(); 727 ThreadWatcherList::StopWatchingAll();
728 message_loop_for_ui.PostDelayedTask( 728 message_loop_for_ui.PostDelayedTask(
729 FROM_HERE, 729 FROM_HERE,
730 message_loop_for_ui.QuitClosure(), 730 message_loop_for_ui.QuitClosure(),
731 base::TimeDelta::FromSeconds( 731 base::TimeDelta::FromSeconds(
732 ThreadWatcherList::g_initialize_delay_seconds)); 732 ThreadWatcherList::g_initialize_delay_seconds));
733 message_loop_for_ui.Run(); 733 message_loop_for_ui.Run();
734 734
735 CheckState(false /* has_thread_watcher_list */, 735 CheckState(false /* has_thread_watcher_list */,
736 true /* stopped */, 736 true /* stopped */,
737 "Stopped"); 737 "Stopped");
738 } 738 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher_android_unittest.cc ('k') | chrome/browser/metrics/variations/variations_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698