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: |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 17 | // The unit time used to measure the timer |
| 18 | // This should be large enough to accomodate drift |
William A. Kennington III | 5e35079 | 2019-01-16 15:46:01 -0800 | [diff] [blame] | 19 | using Quantum = duration<uint64_t, std::deci>; |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 20 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 21 | // Gets called as part of each TEST_F construction |
| 22 | WdogTest() : |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 23 | event(sdeventplus::Event::get_default()), |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 24 | bus(sdbusplus::bus::new_default()), |
| 25 | wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH, |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 26 | event)), |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 27 | defaultInterval(Quantum(3)) |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 28 | { |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 29 | wdog->interval(milliseconds(defaultInterval).count()); |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 30 | // Initially the watchdog would be disabled |
| 31 | EXPECT_FALSE(wdog->enabled()); |
| 32 | } |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 33 | |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 34 | // sdevent Event handle |
| 35 | sdeventplus::Event event; |
| 36 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 37 | // sdbusplus handle |
| 38 | sdbusplus::bus::bus bus; |
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 | // Watchdog object |
| 41 | std::unique_ptr<phosphor::watchdog::Watchdog> wdog; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 42 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 43 | // This is the default interval as given in Interface definition |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 44 | Quantum defaultInterval; |
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. |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 54 | Quantum waitForWatchdog(Quantum timeLimit); |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 55 | }; |