summaryrefslogtreecommitdiffstats
path: root/test/timer_test.hpp
blob: 3f6ffea6fa81bcd52a3a2e3f47213445dc280f30 (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
#include <iostream>
#include <gtest/gtest.h>
#include <timer.hpp>

// Base class for testing Timer
class TimerTest : public testing::Test
{
    public:
        // systemd event handler
        sd_event* events;

        // Need this so that events can be initialized.
        int rc;

        // Tells if the watchdog timer expired.
        bool expired = false;

        // Gets called as part of each TEST_F construction
        TimerTest()
            : rc(sd_event_default(&events)),
              eventP(events)
        {
            // Check for successful creation of
            // event handler and bus handler
            EXPECT_GE(rc, 0);

            // Its already wrapped in eventP
            events = nullptr;
        }

        // unique_ptr for sd_event
        phosphor::watchdog::EventPtr eventP;

        // Handler called by timer expiration
        inline void timeOutHandler()
        {
            std::cout << "Time out handler called" << std::endl;
            expired = true;
        }
};
OpenPOWER on IntegriCloud