Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 1 | #include <iostream> |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 2 | #include <timer.hpp> |
| 3 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 4 | #include <gtest/gtest.h> |
| 5 | |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 6 | // Base class for testing Timer |
| 7 | class TimerTest : public testing::Test |
| 8 | { |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 9 | public: |
| 10 | // systemd event handler |
| 11 | sd_event* events; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 12 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 13 | // Need this so that events can be initialized. |
| 14 | int rc; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 15 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 16 | // Tells if the watchdog timer expired. |
| 17 | bool expired = false; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 18 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 19 | // 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 Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 25 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 26 | // Its already wrapped in eventP |
| 27 | events = nullptr; |
| 28 | } |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 29 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 30 | // unique_ptr for sd_event |
| 31 | phosphor::watchdog::EventPtr eventP; |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 32 | |
Patrick Venture | 8f6c515 | 2018-09-11 17:45:33 -0700 | [diff] [blame] | 33 | // Handler called by timer expiration |
| 34 | inline void timeOutHandler() |
| 35 | { |
| 36 | std::cout << "Time out handler called" << std::endl; |
| 37 | expired = true; |
| 38 | } |
Vishwanatha Subbanna | 00bd377 | 2017-05-31 14:53:42 +0530 | [diff] [blame] | 39 | }; |