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> |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdeventplus/event.hpp> |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 5 | #include <watchdog.hpp> |
| 6 | |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 7 | #include <gtest/gtest.h> |
| 8 | |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 9 | using namespace std::chrono; |
| 10 | using namespace std::chrono_literals; |
| 11 | |
| 12 | // Test Watchdog functionality |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 13 | class WdogTest : public ::testing::Test |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 14 | { |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 15 | public: |
| 16 | // Gets called as part of each TEST_F construction |
| 17 | WdogTest() : |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 18 | event(sdeventplus::Event::get_default()), |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 19 | bus(sdbusplus::bus::new_default()), |
| 20 | wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH, |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 21 | event)), |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 22 | defaultInterval(milliseconds(wdog->interval())), defaultDrift(30) |
| 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 | |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame^] | 28 | // sdevent Event handle |
| 29 | sdeventplus::Event event; |
| 30 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 31 | // sdbusplus handle |
| 32 | sdbusplus::bus::bus bus; |
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 | // Watchdog object |
| 35 | std::unique_ptr<phosphor::watchdog::Watchdog> wdog; |
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 | // This is the default interval as given in Interface definition |
| 38 | milliseconds defaultInterval; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 39 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 40 | // Acceptable drift when we compare the interval to timeRemaining. |
| 41 | // This is needed since it depends on when do we get scheduled and it |
| 42 | // has happened that remaining time was off by few msecs. |
| 43 | milliseconds defaultDrift; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 44 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 45 | protected: |
| 46 | // Dummy name for object path |
| 47 | // This is just to satisfy the constructor. Does not have |
| 48 | // a need to check if the objects paths have been created. |
| 49 | static constexpr auto TEST_PATH = "/test/path"; |
William A. Kennington III | 99c69de | 2018-03-01 10:59:22 -0800 | [diff] [blame] | 50 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 51 | // Returns how long it took for the current watchdog timer to be |
| 52 | // disabled or have its timeRemaining reset. |
| 53 | seconds waitForWatchdog(seconds timeLimit); |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 54 | }; |