summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-02-28 15:20:16 -0800
committerWilliam A. Kennington III <wak@google.com>2018-02-28 15:44:49 -0800
commitf0fe2d6ef7cef8de419277f6839dd229cddc1c1c (patch)
tree7d3e3fec648f0f63b3e203e1456d9df26ee7534f
parentd5d14833ca01ffefd2a81a4eacf6eff5fb2ba2ea (diff)
downloadphosphor-watchdog-f0fe2d6ef7cef8de419277f6839dd229cddc1c1c.tar.gz
phosphor-watchdog-f0fe2d6ef7cef8de419277f6839dd229cddc1c1c.zip
test/watchdog: Use a unique_ptr for the watchdog
This lets us change out the watchdog with a watchdog constructed using different parameters. Currently this functionality is not used, but it is needed for a future change. Change-Id: Ie1e7fbf2c7fc8bf2949237f2535177ecd46944a0 Signed-off-by: William A. Kennington III <wak@google.com>
-rw-r--r--test/watchdog_test.cpp50
-rw-r--r--test/watchdog_test.hpp10
2 files changed, 31 insertions, 29 deletions
diff --git a/test/watchdog_test.cpp b/test/watchdog_test.cpp
index a76a914..f846532 100644
--- a/test/watchdog_test.cpp
+++ b/test/watchdog_test.cpp
@@ -5,27 +5,27 @@ using namespace phosphor::watchdog;
/** @brief Make sure that watchdog is started and not enabled */
TEST_F(WdogTest, createWdogAndDontEnable)
{
- EXPECT_FALSE(wdog.enabled());
- EXPECT_EQ(0, wdog.timeRemaining());
- EXPECT_FALSE(wdog.timerExpired());
+ EXPECT_FALSE(wdog->enabled());
+ EXPECT_EQ(0, wdog->timeRemaining());
+ EXPECT_FALSE(wdog->timerExpired());
}
/** @brief Make sure that watchdog is started and enabled */
TEST_F(WdogTest, createWdogAndEnable)
{
// Enable and then verify
- EXPECT_TRUE(wdog.enabled(true));
- EXPECT_FALSE(wdog.timerExpired());
+ EXPECT_TRUE(wdog->enabled(true));
+ EXPECT_FALSE(wdog->timerExpired());
// Get the configured interval
- auto remaining = milliseconds(wdog.timeRemaining());
+ auto remaining = milliseconds(wdog->timeRemaining());
// Its possible that we are off by few msecs depending on
// how we get scheduled. So checking a range here.
EXPECT_TRUE((remaining >= defaultInterval - defaultDrift) &&
(remaining <= defaultInterval));
- EXPECT_FALSE(wdog.timerExpired());
+ EXPECT_FALSE(wdog->timerExpired());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -34,12 +34,12 @@ TEST_F(WdogTest, createWdogAndEnable)
TEST_F(WdogTest, createWdogAndEnableThenDisable)
{
// Enable and then verify
- EXPECT_TRUE(wdog.enabled(true));
+ EXPECT_TRUE(wdog->enabled(true));
// Disable and then verify
- EXPECT_FALSE(wdog.enabled(false));
- EXPECT_FALSE(wdog.enabled());
- EXPECT_EQ(0, wdog.timeRemaining());
+ EXPECT_FALSE(wdog->enabled(false));
+ EXPECT_FALSE(wdog->enabled());
+ EXPECT_EQ(0, wdog->timeRemaining());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -49,14 +49,14 @@ TEST_F(WdogTest, createWdogAndEnableThenDisable)
TEST_F(WdogTest, enableWdogAndWait5Seconds)
{
// Enable and then verify
- EXPECT_TRUE(wdog.enabled(true));
+ EXPECT_TRUE(wdog->enabled(true));
// Sleep for 5 seconds
auto sleepTime = seconds(5s);
std::this_thread::sleep_for(sleepTime);
// Get the remaining time again and expectation is that we get 25s
- auto remaining = milliseconds(wdog.timeRemaining());
+ auto remaining = milliseconds(wdog->timeRemaining());
auto expected = defaultInterval -
duration_cast<milliseconds>(sleepTime);
@@ -64,7 +64,7 @@ TEST_F(WdogTest, enableWdogAndWait5Seconds)
// how we get scheduled. So checking a range here.
EXPECT_TRUE((remaining >= expected - defaultDrift) &&
(remaining <= expected));
- EXPECT_FALSE(wdog.timerExpired());
+ EXPECT_FALSE(wdog->timerExpired());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -74,7 +74,7 @@ TEST_F(WdogTest, enableWdogAndWait5Seconds)
TEST_F(WdogTest, enableWdogAndResetTo5Seconds)
{
// Enable and then verify
- EXPECT_TRUE(wdog.enabled(true));
+ EXPECT_TRUE(wdog->enabled(true));
// Sleep for 1 second
std::this_thread::sleep_for(1s);
@@ -82,11 +82,11 @@ TEST_F(WdogTest, enableWdogAndResetTo5Seconds)
// Next timer will expire in 5 seconds from now.
auto expireTime = seconds(5s);
auto newTime = duration_cast<milliseconds>(expireTime);
- wdog.timeRemaining(newTime.count());
+ wdog->timeRemaining(newTime.count());
// Waiting for expiration
int count = 0;
- while(count < expireTime.count() && !wdog.timerExpired())
+ while(count < expireTime.count() && !wdog->timerExpired())
{
// Returns -0- on timeout and positive number on dispatch
auto sleepTime = duration_cast<microseconds>(seconds(1s));
@@ -95,7 +95,7 @@ TEST_F(WdogTest, enableWdogAndResetTo5Seconds)
count++;
}
}
- EXPECT_TRUE(wdog.timerExpired());
+ EXPECT_TRUE(wdog->timerExpired());
EXPECT_EQ(expireTime.count() - 1 , count);
// Make sure secondary callback was not called.
@@ -108,10 +108,10 @@ TEST_F(WdogTest, verifyIntervalUpdateReceived)
{
auto expireTime = seconds(5s);
auto newTime = duration_cast<milliseconds>(expireTime);
- wdog.interval(newTime.count());
+ wdog->interval(newTime.count());
// Expect an update in the Interval
- EXPECT_EQ(newTime.count(), wdog.interval());
+ EXPECT_EQ(newTime.count(), wdog->interval());
}
/** @brief Make sure that watchdog is started and enabled.
@@ -120,13 +120,13 @@ TEST_F(WdogTest, verifyIntervalUpdateReceived)
TEST_F(WdogTest, enableWdogAndWaitTillEnd)
{
// Enable and then verify
- EXPECT_TRUE(wdog.enabled(true));
+ EXPECT_TRUE(wdog->enabled(true));
auto expireTime = duration_cast<seconds>(
milliseconds(defaultInterval));
// Waiting default expiration
int count = 0;
- while(count < expireTime.count() && !wdog.timerExpired())
+ while(count < expireTime.count() && !wdog->timerExpired())
{
// Returns -0- on timeout and positive number on dispatch
auto sleepTime = duration_cast<microseconds>(seconds(1s));
@@ -135,8 +135,8 @@ TEST_F(WdogTest, enableWdogAndWaitTillEnd)
count++;
}
}
- EXPECT_TRUE(wdog.enabled());
- EXPECT_EQ(0, wdog.timeRemaining());
- EXPECT_TRUE(wdog.timerExpired());
+ EXPECT_TRUE(wdog->enabled());
+ EXPECT_EQ(0, wdog->timeRemaining());
+ EXPECT_TRUE(wdog->timerExpired());
EXPECT_EQ(expireTime.count() - 1, count);
}
diff --git a/test/watchdog_test.hpp b/test/watchdog_test.hpp
index e332260..beeda66 100644
--- a/test/watchdog_test.hpp
+++ b/test/watchdog_test.hpp
@@ -1,5 +1,6 @@
#include <timer_test.hpp>
#include <chrono>
+#include <memory>
#include <watchdog.hpp>
using namespace std::chrono;
@@ -12,8 +13,9 @@ class WdogTest : public TimerTest
// Gets called as part of each TEST_F construction
WdogTest()
: bus(sdbusplus::bus::new_default()),
- wdog(bus, TEST_PATH, eventP),
- defaultInterval(milliseconds(wdog.interval())),
+ wdog(std::make_unique<phosphor::watchdog::Watchdog>(
+ bus, TEST_PATH, eventP)),
+ defaultInterval(milliseconds(wdog->interval())),
defaultDrift(30)
{
// Check for successful creation of
@@ -21,14 +23,14 @@ class WdogTest : public TimerTest
EXPECT_GE(rc, 0);
// Initially the watchdog would be disabled
- EXPECT_FALSE(wdog.enabled());
+ EXPECT_FALSE(wdog->enabled());
}
//sdbusplus handle
sdbusplus::bus::bus bus;
// Watchdog object
- phosphor::watchdog::Watchdog wdog;
+ std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
// This is the default interval as given in Interface definition
milliseconds defaultInterval;
OpenPOWER on IntegriCloud