summaryrefslogtreecommitdiffstats
path: root/test/watchdog.hpp
blob: df628c35d163cf6b02039f99525a59fa64f3f7a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "../watchdog.hpp"

#include <chrono>
#include <memory>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>

#include <gtest/gtest.h>

using namespace std::chrono;
using namespace std::chrono_literals;

// Test Watchdog functionality
class WdogTest : public ::testing::Test
{
  public:
    // The unit time used to measure the timer
    // This should be large enough to accomodate drift
    using Quantum = duration<uint64_t, std::deci>;

    // Gets called as part of each TEST_F construction
    WdogTest() :
        event(sdeventplus::Event::get_default()),
        bus(sdbusplus::bus::new_default()),
        wdog(std::make_unique<phosphor::watchdog::Watchdog>(bus, TEST_PATH,
                                                            event)),
        defaultInterval(Quantum(3))
    {
        wdog->interval(milliseconds(defaultInterval).count());
        // Initially the watchdog would be disabled
        EXPECT_FALSE(wdog->enabled());
    }

    // sdevent Event handle
    sdeventplus::Event event;

    // sdbusplus handle
    sdbusplus::bus::bus bus;

    // Watchdog object
    std::unique_ptr<phosphor::watchdog::Watchdog> wdog;

    // This is the default interval as given in Interface definition
    Quantum defaultInterval;

  protected:
    // Dummy name for object path
    // This is just to satisfy the constructor. Does not have
    // a need to check if the objects paths have been created.
    static constexpr auto TEST_PATH = "/test/path";

    // Returns how long it took for the current watchdog timer to be
    // disabled or have its timeRemaining reset.
    Quantum waitForWatchdog(Quantum timeLimit);
};
OpenPOWER on IntegriCloud