blob: 87c64e9e83046e7e6f905ce0add32b6a696e565b [file] [log] [blame]
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05301#include <timer_test.hpp>
2#include <chrono>
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -08003#include <memory>
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05304#include <watchdog.hpp>
5
6using namespace std::chrono;
7using namespace std::chrono_literals;
8
9// Test Watchdog functionality
10class WdogTest : public TimerTest
11{
12 public:
13 // Gets called as part of each TEST_F construction
14 WdogTest()
15 : bus(sdbusplus::bus::new_default()),
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -080016 wdog(std::make_unique<phosphor::watchdog::Watchdog>(
17 bus, TEST_PATH, eventP)),
18 defaultInterval(milliseconds(wdog->interval())),
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053019 defaultDrift(30)
20 {
21 // Check for successful creation of
22 // event handler and bus handler
23 EXPECT_GE(rc, 0);
24
25 // Initially the watchdog would be disabled
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -080026 EXPECT_FALSE(wdog->enabled());
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053027 }
28
29 //sdbusplus handle
30 sdbusplus::bus::bus bus;
31
32 // Watchdog object
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -080033 std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053034
35 // This is the default interval as given in Interface definition
36 milliseconds defaultInterval;
37
38 // Acceptable drift when we compare the interval to timeRemaining.
39 // This is needed since it depends on when do we get scheduled and it
40 // has happened that remaining time was off by few msecs.
41 milliseconds defaultDrift;
42
William A. Kennington IIIab175202018-02-28 15:26:06 -080043 protected:
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053044 // Dummy name for object path
45 // This is just to satisfy the constructor. Does not have
46 // a need to check if the objects paths have been created.
47 static constexpr auto TEST_PATH = "/test/path";
William A. Kennington III99c69de2018-03-01 10:59:22 -080048
49 // Returns how long it took for the current watchdog timer to be
50 // disabled or have its timeRemaining reset.
51 seconds waitForWatchdog(seconds timeLimit);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053052};