blob: 09aceed6acdc11f3185e4e9524cb0abcbd364316 [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:
17 // Gets called as part of each TEST_F construction
18 WdogTest() :
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070019 event(sdeventplus::Event::get_default()),
Patrick Venture8f6c5152018-09-11 17:45:33 -070020 bus(sdbusplus::bus::new_default()),
21 wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH,
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070022 event)),
Patrick Venture8f6c5152018-09-11 17:45:33 -070023 defaultInterval(milliseconds(wdog->interval())), defaultDrift(30)
24 {
Patrick Venture8f6c5152018-09-11 17:45:33 -070025 // Initially the watchdog would be disabled
26 EXPECT_FALSE(wdog->enabled());
27 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053028
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070029 // sdevent Event handle
30 sdeventplus::Event event;
31
Patrick Venture8f6c5152018-09-11 17:45:33 -070032 // sdbusplus handle
33 sdbusplus::bus::bus bus;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053034
Patrick Venture8f6c5152018-09-11 17:45:33 -070035 // Watchdog object
36 std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053037
Patrick Venture8f6c5152018-09-11 17:45:33 -070038 // This is the default interval as given in Interface definition
39 milliseconds defaultInterval;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053040
Patrick Venture8f6c5152018-09-11 17:45:33 -070041 // 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 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.
54 seconds waitForWatchdog(seconds timeLimit);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053055};