mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add timerfd test for CLOCK_REALTIME and absolute input.
I was looking at a realtime timer implementation and noticed that gvisor does not have any tests with the combination of CLOCK_REALTIME and TFD_TIMER_ABSTIME. This adds a basic test with that combination. PiperOrigin-RevId: 495969923
This commit is contained in:
@@ -276,6 +276,25 @@ TEST(TimerfdClockRealtimeTest, ClockRealtime) {
|
||||
EXPECT_EQ(1, val);
|
||||
}
|
||||
|
||||
// Same as the above ClockRealtime test but expresses the input as an absolute
|
||||
// time value rather than an interval.
|
||||
TEST(TimerfdClockRealtimeTest, ClockAbsoluteRealtime) {
|
||||
constexpr int kDelaySecs = 1;
|
||||
|
||||
struct itimerspec its = {};
|
||||
ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &its.it_value));
|
||||
its.it_value.tv_sec += kDelaySecs;
|
||||
|
||||
auto const tfd = ASSERT_NO_ERRNO_AND_VALUE(TimerfdCreate(CLOCK_REALTIME, 0));
|
||||
ASSERT_THAT(timerfd_settime(tfd.get(), TFD_TIMER_ABSTIME, &its, nullptr),
|
||||
SyscallSucceeds());
|
||||
|
||||
uint64_t val = 0;
|
||||
ASSERT_THAT(ReadFd(tfd.get(), &val, sizeof(uint64_t)),
|
||||
SyscallSucceedsWithValue(sizeof(uint64_t)));
|
||||
EXPECT_EQ(1, val);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace testing
|
||||
|
||||
Reference in New Issue
Block a user