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 | |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace watchdog |
| 13 | { |
| 14 | |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 15 | using namespace std::chrono; |
| 16 | using namespace std::chrono_literals; |
| 17 | |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 18 | constexpr auto TEST_MIN_INTERVAL = duration<uint64_t, std::deci>(2); |
| 19 | |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 20 | // Test Watchdog functionality |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 21 | class WdogTest : public ::testing::Test |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 22 | { |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 23 | public: |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 24 | // The unit time used to measure the timer |
| 25 | // This should be large enough to accomodate drift |
William A. Kennington III | 5e35079 | 2019-01-16 15:46:01 -0800 | [diff] [blame] | 26 | using Quantum = duration<uint64_t, std::deci>; |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 27 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 28 | // Gets called as part of each TEST_F construction |
| 29 | WdogTest() : |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 30 | event(sdeventplus::Event::get_default()), |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 31 | bus(sdbusplus::bus::new_default()), |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 32 | wdog(std::make_unique<Watchdog>( |
| 33 | bus, TEST_PATH, event, Watchdog::ActionTargetMap(), std::nullopt, |
| 34 | milliseconds(TEST_MIN_INTERVAL).count())), |
| 35 | |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 36 | defaultInterval(Quantum(3)) |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 37 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 38 | { |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 39 | wdog->interval(milliseconds(defaultInterval).count()); |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 40 | // Initially the watchdog would be disabled |
| 41 | EXPECT_FALSE(wdog->enabled()); |
| 42 | } |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 43 | |
William A. Kennington III | f505fc0 | 2018-09-12 18:30:09 -0700 | [diff] [blame] | 44 | // sdevent Event handle |
| 45 | sdeventplus::Event event; |
| 46 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 47 | // sdbusplus handle |
| 48 | sdbusplus::bus::bus bus; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 49 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 50 | // Watchdog object |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 51 | std::unique_ptr<Watchdog> wdog; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 52 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 53 | // This is the default interval as given in Interface definition |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 54 | Quantum defaultInterval; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 55 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 56 | protected: |
| 57 | // Dummy name for object path |
| 58 | // This is just to satisfy the constructor. Does not have |
| 59 | // a need to check if the objects paths have been created. |
| 60 | static constexpr auto TEST_PATH = "/test/path"; |
William A. Kennington III | 99c69de | 2018-03-01 10:59:22 -0800 | [diff] [blame] | 61 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 62 | // Returns how long it took for the current watchdog timer to be |
| 63 | // disabled or have its timeRemaining reset. |
William A. Kennington III | 3964f00 | 2019-01-16 15:43:43 -0800 | [diff] [blame] | 64 | Quantum waitForWatchdog(Quantum timeLimit); |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 65 | }; |
Ofer Yehielli | c35135d | 2019-06-14 11:30:25 -0700 | [diff] [blame] | 66 | |
| 67 | } // namespace watchdog |
| 68 | } // namespace phosphor |