diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/watchdog.cc | 7 | ||||
-rw-r--r-- | base/watchdog.h | 4 | ||||
-rw-r--r-- | base/watchdog_unittest.cc | 16 |
3 files changed, 21 insertions, 6 deletions
diff --git a/base/watchdog.cc b/base/watchdog.cc index b254577..d78ec0c 100644 --- a/base/watchdog.cc +++ b/base/watchdog.cc @@ -127,6 +127,13 @@ void Watchdog::ThreadDelegate::SetThreadName() const { } // static +void Watchdog::ResetStaticData() { + AutoLock lock(static_lock_); + last_debugged_alarm_time_ = TimeTicks(); + last_debugged_alarm_delay_ = TimeDelta(); +} + +// static Lock Watchdog::static_lock_; // Lock for access of static data... // static TimeTicks Watchdog::last_debugged_alarm_time_ = TimeTicks(); diff --git a/base/watchdog.h b/base/watchdog.h index 59ee80c..fa60316 100644 --- a/base/watchdog.h +++ b/base/watchdog.h @@ -48,6 +48,10 @@ class Watchdog { DLOG(INFO) << "Watchdog alarmed for " << thread_watched_name_; } + // Reset static data to initial state. Useful for tests, to ensure + // they are independent. + static void ResetStaticData(); + private: class ThreadDelegate : public PlatformThread::Delegate { public: diff --git a/base/watchdog_unittest.cc b/base/watchdog_unittest.cc index 698bf9a..3ecfa7d 100644 --- a/base/watchdog_unittest.cc +++ b/base/watchdog_unittest.cc @@ -41,6 +41,10 @@ class WatchdogCounter : public Watchdog { }; class WatchdogTest : public testing::Test { + public: + void SetUp() { + Watchdog::ResetStaticData(); + } }; @@ -48,13 +52,13 @@ class WatchdogTest : public testing::Test { // Actual tests // Minimal constructor/destructor test. -TEST(WatchdogTest, StartupShutdownTest) { +TEST_F(WatchdogTest, StartupShutdownTest) { Watchdog watchdog1(TimeDelta::FromMilliseconds(300), "Disabled", false); Watchdog watchdog2(TimeDelta::FromMilliseconds(300), "Enabled", true); } // Test ability to call Arm and Disarm repeatedly. -TEST(WatchdogTest, ArmDisarmTest) { +TEST_F(WatchdogTest, ArmDisarmTest) { Watchdog watchdog1(TimeDelta::FromMilliseconds(300), "Disabled", false); watchdog1.Arm(); watchdog1.Disarm(); @@ -69,7 +73,7 @@ TEST(WatchdogTest, ArmDisarmTest) { } // Make sure a basic alarm fires when the time has expired. -TEST(WatchdogTest, AlarmTest) { +TEST_F(WatchdogTest, AlarmTest) { WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true); watchdog.Arm(); SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromMinutes(5), @@ -78,7 +82,7 @@ TEST(WatchdogTest, AlarmTest) { } // Make sure a basic alarm fires when the time has expired. -TEST(WatchdogTest, AlarmPriorTimeTest) { +TEST_F(WatchdogTest, AlarmPriorTimeTest) { WatchdogCounter watchdog(TimeDelta::TimeDelta(), "Enabled2", true); // Set a time in the past. watchdog.ArmSomeTimeDeltaAgo(TimeDelta::FromSeconds(2)); @@ -90,7 +94,7 @@ TEST(WatchdogTest, AlarmPriorTimeTest) { } // Make sure a disable alarm does nothing, even if we arm it. -TEST(WatchdogTest, ConstructorDisabledTest) { +TEST_F(WatchdogTest, ConstructorDisabledTest) { WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false); watchdog.Arm(); // Alarm should not fire, as it was disabled. @@ -99,7 +103,7 @@ TEST(WatchdogTest, ConstructorDisabledTest) { } // Make sure Disarming will prevent firing, even after Arming. -TEST(WatchdogTest, DisarmTest) { +TEST_F(WatchdogTest, DisarmTest) { WatchdogCounter watchdog(TimeDelta::FromSeconds(5), "Enabled3", true); watchdog.Arm(); PlatformThread::Sleep(100); // Don't sleep too long |