summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-03-01 10:53:25 -0800
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-03-07 11:22:33 +0000
commit0650a3f09da8899a742988ff55d02eebd6e796aa (patch)
treeb110719075d9f46ef608d8ffedd05d9cf91cc001
parent5e3f877179a5b56d098173afb60753b1d1e6c9af (diff)
downloadphosphor-watchdog-0650a3f09da8899a742988ff55d02eebd6e796aa.tar.gz
phosphor-watchdog-0650a3f09da8899a742988ff55d02eebd6e796aa.zip
watchdog: Add a function to tell us if the timer is running
This helps us refactor some of our existing code and will be useful for future changes. Change-Id: Ifa1547f09997d6824f726fc5f46e15eed4c1e8c1 Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--test/watchdog_test.cpp10
-rw-r--r--watchdog.cpp4
-rw-r--r--watchdog.hpp6
3 files changed, 17 insertions, 3 deletions
diff --git a/test/watchdog_test.cpp b/test/watchdog_test.cpp
index f846532..cb22a83 100644
--- a/test/watchdog_test.cpp
+++ b/test/watchdog_test.cpp
@@ -8,6 +8,7 @@ TEST_F(WdogTest, createWdogAndDontEnable)
EXPECT_FALSE(wdog->enabled());
EXPECT_EQ(0, wdog->timeRemaining());
EXPECT_FALSE(wdog->timerExpired());
+ EXPECT_FALSE(wdog->timerEnabled());
}
/** @brief Make sure that watchdog is started and enabled */
@@ -16,6 +17,7 @@ TEST_F(WdogTest, createWdogAndEnable)
// Enable and then verify
EXPECT_TRUE(wdog->enabled(true));
EXPECT_FALSE(wdog->timerExpired());
+ EXPECT_TRUE(wdog->timerEnabled());
// Get the configured interval
auto remaining = milliseconds(wdog->timeRemaining());
@@ -26,6 +28,7 @@ TEST_F(WdogTest, createWdogAndEnable)
(remaining <= defaultInterval));
EXPECT_FALSE(wdog->timerExpired());
+ EXPECT_TRUE(wdog->timerEnabled());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -40,6 +43,8 @@ TEST_F(WdogTest, createWdogAndEnableThenDisable)
EXPECT_FALSE(wdog->enabled(false));
EXPECT_FALSE(wdog->enabled());
EXPECT_EQ(0, wdog->timeRemaining());
+ EXPECT_FALSE(wdog->timerExpired());
+ EXPECT_FALSE(wdog->timerEnabled());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -65,6 +70,7 @@ TEST_F(WdogTest, enableWdogAndWait5Seconds)
EXPECT_TRUE((remaining >= expected - defaultDrift) &&
(remaining <= expected));
EXPECT_FALSE(wdog->timerExpired());
+ EXPECT_TRUE(wdog->timerEnabled());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -96,7 +102,8 @@ TEST_F(WdogTest, enableWdogAndResetTo5Seconds)
}
}
EXPECT_TRUE(wdog->timerExpired());
- EXPECT_EQ(expireTime.count() - 1 , count);
+ EXPECT_FALSE(wdog->timerEnabled());
+ EXPECT_EQ(expireTime.count() - 1, count);
// Make sure secondary callback was not called.
EXPECT_FALSE(expired);
@@ -138,5 +145,6 @@ TEST_F(WdogTest, enableWdogAndWaitTillEnd)
EXPECT_TRUE(wdog->enabled());
EXPECT_EQ(0, wdog->timeRemaining());
EXPECT_TRUE(wdog->timerExpired());
+ EXPECT_FALSE(wdog->timerEnabled());
EXPECT_EQ(expireTime.count() - 1, count);
}
diff --git a/watchdog.cpp b/watchdog.cpp
index b5cae66..12631a6 100644
--- a/watchdog.cpp
+++ b/watchdog.cpp
@@ -50,7 +50,7 @@ uint64_t Watchdog::timeRemaining() const
uint64_t timeRemain = 0;
// timer may have already expired and disabled
- if (timer.getEnabled() != SD_EVENT_OFF)
+ if (timerEnabled())
{
// the one-shot timer does not expire yet
auto expiry = duration_cast<milliseconds>(
@@ -71,7 +71,7 @@ uint64_t Watchdog::timeRemaining() const
// Reset the timer to a new expiration value
uint64_t Watchdog::timeRemaining(uint64_t value)
{
- if (timer.getEnabled() == SD_EVENT_OFF)
+ if (!timerEnabled())
{
// We don't need to update the timer because it is off
return 0;
diff --git a/watchdog.hpp b/watchdog.hpp
index 757029c..e829699 100644
--- a/watchdog.hpp
+++ b/watchdog.hpp
@@ -93,6 +93,12 @@ class Watchdog : public WatchdogInherits
return timer.expired();
}
+ /** @brief Tells if the timer is running or not */
+ inline bool timerEnabled() const
+ {
+ return timer.getEnabled() != SD_EVENT_OFF;
+ }
+
private:
/** @brief sdbusplus handle */
sdbusplus::bus::bus& bus;
OpenPOWER on IntegriCloud