blob: cab9086cc429d1b14ea6166d369b5092546bf2ee [file] [log] [blame]
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05301#include <iostream>
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05302#include <timer.hpp>
3
Patrick Venture8f6c5152018-09-11 17:45:33 -07004#include <gtest/gtest.h>
5
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +05306// Base class for testing Timer
7class TimerTest : public testing::Test
8{
Patrick Venture8f6c5152018-09-11 17:45:33 -07009 public:
10 // systemd event handler
11 sd_event* events;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053012
Patrick Venture8f6c5152018-09-11 17:45:33 -070013 // Need this so that events can be initialized.
14 int rc;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053015
Patrick Venture8f6c5152018-09-11 17:45:33 -070016 // Tells if the watchdog timer expired.
17 bool expired = false;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053018
Patrick Venture8f6c5152018-09-11 17:45:33 -070019 // Gets called as part of each TEST_F construction
20 TimerTest() : rc(sd_event_default(&events)), eventP(events)
21 {
22 // Check for successful creation of
23 // event handler and bus handler
24 EXPECT_GE(rc, 0);
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053025
Patrick Venture8f6c5152018-09-11 17:45:33 -070026 // Its already wrapped in eventP
27 events = nullptr;
28 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053029
Patrick Venture8f6c5152018-09-11 17:45:33 -070030 // unique_ptr for sd_event
31 phosphor::watchdog::EventPtr eventP;
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053032
Patrick Venture8f6c5152018-09-11 17:45:33 -070033 // Handler called by timer expiration
34 inline void timeOutHandler()
35 {
36 std::cout << "Time out handler called" << std::endl;
37 expired = true;
38 }
Vishwanatha Subbanna00bd3772017-05-31 14:53:42 +053039};