test/watchdog: Remove separate header
The header contents are not being shared anywhere and the name collides
with the source header.
Change-Id: I2ddfd4488e2318b9fdd34cc1663044dbe413f4f1
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/watchdog.cpp b/test/watchdog.cpp
index 4f444ed..7f0a2aa 100644
--- a/test/watchdog.cpp
+++ b/test/watchdog.cpp
@@ -1,32 +1,88 @@
#include "watchdog.hpp"
+#include <chrono>
#include <memory>
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
#include <thread>
#include <utility>
+#include <gtest/gtest.h>
+
namespace phosphor
{
namespace watchdog
{
-WdogTest::Quantum WdogTest::waitForWatchdog(Quantum timeLimit)
-{
- auto previousTimeRemaining = wdog->timeRemaining();
- auto ret = Quantum(0);
- while (ret < timeLimit && previousTimeRemaining >= wdog->timeRemaining() &&
- wdog->timerEnabled())
- {
- previousTimeRemaining = wdog->timeRemaining();
+using namespace std::chrono;
+using namespace std::chrono_literals;
- constexpr auto sleepTime = Quantum(1);
- if (event.run(sleepTime) == 0)
- {
- ret += sleepTime;
- }
+constexpr auto TEST_MIN_INTERVAL = duration<uint64_t, std::deci>(2);
+
+// Test Watchdog functionality
+class WdogTest : public ::testing::Test
+{
+ public:
+ // The unit time used to measure the timer
+ // This should be large enough to accomodate drift
+ using Quantum = duration<uint64_t, std::deci>;
+
+ // Gets called as part of each TEST_F construction
+ WdogTest() :
+ event(sdeventplus::Event::get_default()),
+ bus(sdbusplus::bus::new_default()),
+ wdog(std::make_unique<Watchdog>(
+ bus, TEST_PATH, event, Watchdog::ActionTargetMap(), std::nullopt,
+ milliseconds(TEST_MIN_INTERVAL).count())),
+
+ defaultInterval(Quantum(3))
+
+ {
+ wdog->interval(milliseconds(defaultInterval).count());
+ // Initially the watchdog would be disabled
+ EXPECT_FALSE(wdog->enabled());
}
- return ret;
-}
+ // sdevent Event handle
+ sdeventplus::Event event;
+
+ // sdbusplus handle
+ sdbusplus::bus::bus bus;
+
+ // Watchdog object
+ std::unique_ptr<Watchdog> wdog;
+
+ // This is the default interval as given in Interface definition
+ Quantum defaultInterval;
+
+ protected:
+ // Dummy name for object path
+ // This is just to satisfy the constructor. Does not have
+ // a need to check if the objects paths have been created.
+ static constexpr auto TEST_PATH = "/test/path";
+
+ // Returns how long it took for the current watchdog timer to be
+ // disabled or have its timeRemaining reset.
+ Quantum waitForWatchdog(Quantum timeLimit)
+ {
+ auto previousTimeRemaining = wdog->timeRemaining();
+ auto ret = Quantum(0);
+ while (ret < timeLimit &&
+ previousTimeRemaining >= wdog->timeRemaining() &&
+ wdog->timerEnabled())
+ {
+ previousTimeRemaining = wdog->timeRemaining();
+
+ constexpr auto sleepTime = Quantum(1);
+ if (event.run(sleepTime) == 0)
+ {
+ ret += sleepTime;
+ }
+ }
+
+ return ret;
+ }
+};
/** @brief Make sure that watchdog is started and not enabled */
TEST_F(WdogTest, createWdogAndDontEnable)