Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 1 | #include <chrono> |
William A. Kennington III | f0fe2d6 | 2018-02-28 15:20:16 -0800 | [diff] [blame] | 2 | #include <memory> |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 3 | #include <timer_test.hpp> |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 4 | #include <watchdog.hpp> |
| 5 | |
| 6 | using namespace std::chrono; |
| 7 | using namespace std::chrono_literals; |
| 8 | |
| 9 | // Test Watchdog functionality |
| 10 | class WdogTest : public TimerTest |
| 11 | { |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 12 | 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 Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 23 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 24 | // Initially the watchdog would be disabled |
| 25 | EXPECT_FALSE(wdog->enabled()); |
| 26 | } |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 27 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 28 | // sdbusplus handle |
| 29 | sdbusplus::bus::bus bus; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 30 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 31 | // Watchdog object |
| 32 | std::unique_ptr<phosphor::watchdog::Watchdog> wdog; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 33 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 34 | // This is the default interval as given in Interface definition |
| 35 | milliseconds defaultInterval; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 36 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 37 | // 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 Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 41 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 42 | 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 III | 99c69de | 2018-03-01 10:59:22 -0800 | [diff] [blame] | 47 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 48 | // 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 Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 51 | }; |