| 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 "chrome/browser/metrics/thread_watcher.h" | 5 #include "chrome/browser/metrics/thread_watcher.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 UpdateWaitState(STOPPED_WAITING); | 239 UpdateWaitState(STOPPED_WAITING); |
| 240 return exit_state; | 240 return exit_state; |
| 241 } | 241 } |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 class ThreadWatcherTest : public ::testing::Test { | 244 class ThreadWatcherTest : public ::testing::Test { |
| 245 public: | 245 public: |
| 246 static const TimeDelta kSleepTime; | 246 static const TimeDelta kSleepTime; |
| 247 static const TimeDelta kUnresponsiveTime; | 247 static const TimeDelta kUnresponsiveTime; |
| 248 static const BrowserThread::ID io_thread_id; | 248 static const BrowserThread::ID io_thread_id; |
| 249 static const std::string io_thread_name; | 249 static const char io_thread_name[]; |
| 250 static const BrowserThread::ID db_thread_id; | 250 static const BrowserThread::ID db_thread_id; |
| 251 static const std::string db_thread_name; | 251 static const char db_thread_name[]; |
| 252 static const std::string crash_on_hang_seconds; | 252 static const char crash_on_hang_thread_names[]; |
| 253 static const std::string crash_on_hang_thread_names; | 253 static const char thread_names_and_live_threshold[]; |
| 254 static const std::string thread_names_and_live_threshold; | 254 static const char crash_on_hang_thread_data[]; |
| 255 static const std::string crash_on_hang_thread_data; | |
| 256 CustomThreadWatcher* io_watcher_; | 255 CustomThreadWatcher* io_watcher_; |
| 257 CustomThreadWatcher* db_watcher_; | 256 CustomThreadWatcher* db_watcher_; |
| 258 ThreadWatcherList* thread_watcher_list_; | 257 ThreadWatcherList* thread_watcher_list_; |
| 259 | 258 |
| 260 ThreadWatcherTest() | 259 ThreadWatcherTest() |
| 261 : setup_complete_(&lock_), | 260 : setup_complete_(&lock_), |
| 262 initialized_(false) { | 261 initialized_(false) { |
| 263 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); | 262 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); |
| 264 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | 263 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); |
| 265 watchdog_thread_.reset(new WatchDogThread()); | 264 watchdog_thread_.reset(new WatchDogThread()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 std::unique_ptr<content::TestBrowserThread> io_thread_; | 325 std::unique_ptr<content::TestBrowserThread> io_thread_; |
| 327 std::unique_ptr<WatchDogThread> watchdog_thread_; | 326 std::unique_ptr<WatchDogThread> watchdog_thread_; |
| 328 }; | 327 }; |
| 329 | 328 |
| 330 // Define static constants. | 329 // Define static constants. |
| 331 const TimeDelta ThreadWatcherTest::kSleepTime = | 330 const TimeDelta ThreadWatcherTest::kSleepTime = |
| 332 TimeDelta::FromMilliseconds(50); | 331 TimeDelta::FromMilliseconds(50); |
| 333 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = | 332 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = |
| 334 TimeDelta::FromMilliseconds(500); | 333 TimeDelta::FromMilliseconds(500); |
| 335 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; | 334 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; |
| 336 const std::string ThreadWatcherTest::io_thread_name = "IO"; | 335 const char ThreadWatcherTest::io_thread_name[] = "IO"; |
| 337 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB; | 336 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB; |
| 338 const std::string ThreadWatcherTest::db_thread_name = "DB"; | 337 const char ThreadWatcherTest::db_thread_name[] = "DB"; |
| 339 const std::string ThreadWatcherTest::crash_on_hang_thread_names = "UI,IO"; | 338 const char ThreadWatcherTest::crash_on_hang_thread_names[] = "UI,IO"; |
| 340 const std::string ThreadWatcherTest::thread_names_and_live_threshold = | 339 const char ThreadWatcherTest::thread_names_and_live_threshold[] = |
| 341 "UI:4,IO:4"; | 340 "UI:4,IO:4"; |
| 342 const std::string ThreadWatcherTest::crash_on_hang_thread_data = | 341 const char ThreadWatcherTest::crash_on_hang_thread_data[] = |
| 343 "UI:5:12,IO:5:12,FILE:5:12"; | 342 "UI:5:12,IO:5:12,FILE:5:12"; |
| 344 | 343 |
| 345 TEST_F(ThreadWatcherTest, ThreadNamesOnlyArgs) { | 344 TEST_F(ThreadWatcherTest, ThreadNamesOnlyArgs) { |
| 346 // Setup command_line arguments. | 345 // Setup command_line arguments. |
| 347 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 346 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 348 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, | 347 command_line.AppendSwitchASCII(switches::kCrashOnHangThreads, |
| 349 crash_on_hang_thread_names); | 348 crash_on_hang_thread_names); |
| 350 | 349 |
| 351 // Parse command_line arguments. | 350 // Parse command_line arguments. |
| 352 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; | 351 ThreadWatcherList::CrashOnHangThreadMap crash_on_hang_threads; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(1), | 770 SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(1), |
| 772 watchdog_thread_->Started()); | 771 watchdog_thread_->Started()); |
| 773 WaitForWatchDogThreadPostTask(); | 772 WaitForWatchDogThreadPostTask(); |
| 774 } | 773 } |
| 775 | 774 |
| 776 ~JankTimeBombTest() override { | 775 ~JankTimeBombTest() override { |
| 777 watchdog_thread_.reset(); | 776 watchdog_thread_.reset(); |
| 778 } | 777 } |
| 779 | 778 |
| 780 static void WaitForWatchDogThreadPostTask() { | 779 static void WaitForWatchDogThreadPostTask() { |
| 781 base::WaitableEvent watchdog_thread_event(false, false); | 780 base::WaitableEvent watchdog_thread_event( |
| 781 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 782 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 782 PostAndWaitForWatchdogThread(&watchdog_thread_event); | 783 PostAndWaitForWatchdogThread(&watchdog_thread_event); |
| 783 } | 784 } |
| 784 | 785 |
| 785 private: | 786 private: |
| 786 static void OnJankTimeBombTask(base::WaitableEvent* event) { | 787 static void OnJankTimeBombTask(base::WaitableEvent* event) { |
| 787 event->Signal(); | 788 event->Signal(); |
| 788 } | 789 } |
| 789 | 790 |
| 790 static void PostAndWaitForWatchdogThread(base::WaitableEvent* event) { | 791 static void PostAndWaitForWatchdogThread(base::WaitableEvent* event) { |
| 791 WatchDogThread::PostDelayedTask( | 792 WatchDogThread::PostDelayedTask( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 812 } | 813 } |
| 813 | 814 |
| 814 TEST_F(JankTimeBombTest, ArmTest) { | 815 TEST_F(JankTimeBombTest, ArmTest) { |
| 815 // Test firing of Alarm by passing empty delay. | 816 // Test firing of Alarm by passing empty delay. |
| 816 TestingJankTimeBomb timebomb((base::TimeDelta())); | 817 TestingJankTimeBomb timebomb((base::TimeDelta())); |
| 817 if (!timebomb.IsEnabled()) | 818 if (!timebomb.IsEnabled()) |
| 818 return; | 819 return; |
| 819 WaitForWatchDogThreadPostTask(); | 820 WaitForWatchDogThreadPostTask(); |
| 820 EXPECT_TRUE(timebomb.alarm_invoked()); | 821 EXPECT_TRUE(timebomb.alarm_invoked()); |
| 821 } | 822 } |
| OLD | NEW |