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