5 require 'sleepy_penguin'
7 class TestTimerFD < Test::Unit::TestCase
11 assert_kind_of Integer, TimerFD::REALTIME
12 assert_kind_of Integer, TimerFD::MONOTONIC
17 assert_kind_of(IO, tfd)
20 def test_create_nonblock
21 tfd = TimerFD.new(TimerFD::REALTIME, TimerFD::NONBLOCK)
22 flags = tfd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
23 assert_equal(Fcntl::O_NONBLOCK, flags)
24 end if defined?(TimerFD::NONBLOCK)
26 def test_create_nonblock_sym
27 tfd = TimerFD.new(:REALTIME, :NONBLOCK)
28 flags = tfd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
29 assert_equal(Fcntl::O_NONBLOCK, flags)
30 end if defined?(TimerFD::NONBLOCK)
32 def test_create_cloexec
33 tfd = TimerFD.new(TimerFD::REALTIME, TimerFD::CLOEXEC)
34 flags = tfd.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC
35 assert_equal(Fcntl::FD_CLOEXEC, flags)
36 end if defined?(TimerFD::CLOEXEC)
39 tfd = TimerFD.new(TimerFD::REALTIME)
40 assert_equal([0, 0], tfd.settime(TimerFD::ABSTIME, 0, 0.01))
42 assert_equal 1, tfd.expirations
45 def test_settime_symbol
46 tfd = TimerFD.new(:REALTIME)
47 assert_equal([0, 0], tfd.settime(:ABSTIME, 0, 0.01))
49 assert_equal 1, tfd.expirations
53 tfd = TimerFD.new :REALTIME
55 assert_equal([0, 0], tfd.settime(nil, 0, now + 5))
56 interval, value = tfd.gettime
57 assert_equal 0, interval
58 assert_in_delta now + 5, value, 0.01
61 def test_expirations_nonblock
62 tfd = TimerFD.new(:MONOTONIC)
63 assert_equal([0, 0], tfd.settime(0, 0, 0.01))
64 assert_nil tfd.expirations(true)
66 assert_equal 1, tfd.expirations
68 end if defined?(SleepyPenguin::TimerFD)