blob: 50fa8f18f345adb5b14efafbd2cbde5ef84a9459 [file] [log] [blame]
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05301#include <chrono>
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -08002#include <memory>
Patrick Venture8f6c5152018-09-11 17:45:33 -07003#include <timer_test.hpp>
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{
Patrick Venture8f6c5152018-09-11 17:45:33 -070012 public:
13 // Gets called as part of each TEST_F construction
14 WdogTest() :
15 bus(sdbusplus::bus::new_default()),
16 wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH,
17 eventP)),
18 defaultInterval(milliseconds(wdog->interval())), defaultDrift(30)
19 {
20 // Check for successful creation of
21 // event handler and bus handler
22 EXPECT_GE(rc, 0);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053023
Patrick Venture8f6c5152018-09-11 17:45:33 -070024 // Initially the watchdog would be disabled
25 EXPECT_FALSE(wdog->enabled());
26 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053027
Patrick Venture8f6c5152018-09-11 17:45:33 -070028 // sdbusplus handle
29 sdbusplus::bus::bus bus;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053030
Patrick Venture8f6c5152018-09-11 17:45:33 -070031 // Watchdog object
32 std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053033
Patrick Venture8f6c5152018-09-11 17:45:33 -070034 // This is the default interval as given in Interface definition
35 milliseconds defaultInterval;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053036
Patrick Venture8f6c5152018-09-11 17:45:33 -070037 // Acceptable drift when we compare the interval to timeRemaining.
38 // This is needed since it depends on when do we get scheduled and it
39 // has happened that remaining time was off by few msecs.
40 milliseconds defaultDrift;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053041
Patrick Venture8f6c5152018-09-11 17:45:33 -070042 protected:
43 // Dummy name for object path
44 // This is just to satisfy the constructor. Does not have
45 // a need to check if the objects paths have been created.
46 static constexpr auto TEST_PATH = "/test/path";
William A. Kennington III99c69de2018-03-01 10:59:22 -080047
Patrick Venture8f6c5152018-09-11 17:45:33 -070048 // Returns how long it took for the current watchdog timer to be
49 // disabled or have its timeRemaining reset.
50 seconds waitForWatchdog(seconds timeLimit);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053051};