blob: 1139251762ac40e946a85e0d3e885b11bf1af4a8 [file] [log] [blame]
William A. Kennington IIIaf60e632019-01-16 15:00:18 -08001#include "../watchdog.hpp"
2
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05303#include <chrono>
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -08004#include <memory>
William A. Kennington IIIf505fc02018-09-12 18:30:09 -07005#include <sdbusplus/bus.hpp>
6#include <sdeventplus/event.hpp>
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05307
William A. Kennington IIIf505fc02018-09-12 18:30:09 -07008#include <gtest/gtest.h>
9
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053010using namespace std::chrono;
11using namespace std::chrono_literals;
12
13// Test Watchdog functionality
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070014class WdogTest : public ::testing::Test
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053015{
Patrick Venture8f6c5152018-09-11 17:45:33 -070016 public:
William A. Kennington III3964f002019-01-16 15:43:43 -080017 // The unit time used to measure the timer
18 // This should be large enough to accomodate drift
19 using Quantum = seconds;
20
Patrick Venture8f6c5152018-09-11 17:45:33 -070021 // Gets called as part of each TEST_F construction
22 WdogTest() :
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070023 event(sdeventplus::Event::get_default()),
Patrick Venture8f6c5152018-09-11 17:45:33 -070024 bus(sdbusplus::bus::new_default()),
25 wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH,
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070026 event)),
William A. Kennington III3964f002019-01-16 15:43:43 -080027 defaultInterval(Quantum(3))
Patrick Venture8f6c5152018-09-11 17:45:33 -070028 {
William A. Kennington III3964f002019-01-16 15:43:43 -080029 wdog->interval(milliseconds(defaultInterval).count());
Patrick Venture8f6c5152018-09-11 17:45:33 -070030 // Initially the watchdog would be disabled
31 EXPECT_FALSE(wdog->enabled());
32 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053033
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070034 // sdevent Event handle
35 sdeventplus::Event event;
36
Patrick Venture8f6c5152018-09-11 17:45:33 -070037 // sdbusplus handle
38 sdbusplus::bus::bus bus;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053039
Patrick Venture8f6c5152018-09-11 17:45:33 -070040 // Watchdog object
41 std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053042
Patrick Venture8f6c5152018-09-11 17:45:33 -070043 // This is the default interval as given in Interface definition
William A. Kennington III3964f002019-01-16 15:43:43 -080044 Quantum defaultInterval;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053045
Patrick Venture8f6c5152018-09-11 17:45:33 -070046 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 III99c69de2018-03-01 10:59:22 -080051
Patrick Venture8f6c5152018-09-11 17:45:33 -070052 // Returns how long it took for the current watchdog timer to be
53 // disabled or have its timeRemaining reset.
William A. Kennington III3964f002019-01-16 15:43:43 -080054 Quantum waitForWatchdog(Quantum timeLimit);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053055};