From 2342c658c7c2ccdc1e23d642a5873c80297669de Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 16 Dec 2022 15:06:05 -0800 Subject: [PATCH] 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 --- test/syscalls/linux/timerfd.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/syscalls/linux/timerfd.cc b/test/syscalls/linux/timerfd.cc index da03a3332..279e5b596 100644 --- a/test/syscalls/linux/timerfd.cc +++ b/test/syscalls/linux/timerfd.cc @@ -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