blob: 4c798a7ca62d99a85420b16c8c9b81662647c558 [file] [log] [blame]
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05301#include <chrono>
William A. Kennington IIIf0fe2d62018-02-28 15:20:16 -08002#include <memory>
William A. Kennington IIIf505fc02018-09-12 18:30:09 -07003#include <sdbusplus/bus.hpp>
4#include <sdeventplus/event.hpp>
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05305#include <watchdog.hpp>
6
William A. Kennington IIIf505fc02018-09-12 18:30:09 -07007#include <gtest/gtest.h>
8
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05309using namespace std::chrono;
10using namespace std::chrono_literals;
11
12// Test Watchdog functionality
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070013class WdogTest : public ::testing::Test
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053014{
Patrick Venture8f6c5152018-09-11 17:45:33 -070015 public:
16 // Gets called as part of each TEST_F construction
17 WdogTest() :
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070018 event(sdeventplus::Event::get_default()),
Patrick Venture8f6c5152018-09-11 17:45:33 -070019 bus(sdbusplus::bus::new_default()),
20 wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH,
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070021 event)),
Patrick Venture8f6c5152018-09-11 17:45:33 -070022 defaultInterval(milliseconds(wdog->interval())), defaultDrift(30)
23 {
Patrick Venture8f6c5152018-09-11 17:45:33 -070024 // Initially the watchdog would be disabled
25 EXPECT_FALSE(wdog->enabled());
26 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053027
William A. Kennington IIIf505fc02018-09-12 18:30:09 -070028 // sdevent Event handle
29 sdeventplus::Event event;
30
Patrick Venture8f6c5152018-09-11 17:45:33 -070031 // sdbusplus handle
32 sdbusplus::bus::bus bus;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053033
Patrick Venture8f6c5152018-09-11 17:45:33 -070034 // Watchdog object
35 std::unique_ptr<phosphor::watchdog::Watchdog> wdog;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053036
Patrick Venture8f6c5152018-09-11 17:45:33 -070037 // This is the default interval as given in Interface definition
38 milliseconds defaultInterval;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053039
Patrick Venture8f6c5152018-09-11 17:45:33 -070040 // Acceptable drift when we compare the interval to timeRemaining.
41 // This is needed since it depends on when do we get scheduled and it
42 // has happened that remaining time was off by few msecs.
43 milliseconds defaultDrift;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053044
Patrick Venture8f6c5152018-09-11 17:45:33 -070045 protected:
46 // Dummy name for object path
47 // This is just to satisfy the constructor. Does not have
48 // a need to check if the objects paths have been created.
49 static constexpr auto TEST_PATH = "/test/path";
William A. Kennington III99c69de2018-03-01 10:59:22 -080050
Patrick Venture8f6c5152018-09-11 17:45:33 -070051 // Returns how long it took for the current watchdog timer to be
52 // disabled or have its timeRemaining reset.
53 seconds waitForWatchdog(seconds timeLimit);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053054};