blob: a74f6009240d960d9161d6b551e1a46d9a5373fb [file] [log] [blame]
Alexander Hansen2cd25e62025-10-23 12:35:39 +02001#include "suite.hpp"
2
3#include <sdbusplus/timer.hpp>
4
5#include <chrono>
6
7#include <gtest/gtest.h>
8
9/** @brief Makes sure that timer is not expired
10 */
11TEST_F(TimerTestCallBack, timerNotExpiredAfter2SecondsNoOptionalCallBack)
12{
13 using namespace std::chrono;
14
15 auto time = duration_cast<microseconds>(seconds(2));
16 EXPECT_GE(timer->start(time), 0);
17
18 // Now turn off the timer post a 1 second sleep
19 sleep(1);
20 EXPECT_GE(timer->stop(), 0);
21
22 // Wait 2 seconds and see that timer is not expired
23 int count = 0;
24 while (count < 2)
25 {
26 // Returns -0- on timeout
27 auto sleepTime = duration_cast<microseconds>(seconds(1));
28 if (!sd_event_run(events, sleepTime.count()))
29 {
30 count++;
31 }
32 }
33 EXPECT_EQ(false, timer->isExpired());
34 EXPECT_EQ(false, callBackDone);
35
36 // 2 because of one more count that happens prior to exiting
37 EXPECT_EQ(2, count);
38}