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)
18 if RUBY_VERSION.to_f >= 2.0
19 assert_equal 1, tfd.fcntl(Fcntl::F_GETFD)
21 assert_equal 0, tfd.fcntl(Fcntl::F_GETFD)
25 def test_create_nonblock
26 tfd = TimerFD.new(TimerFD::REALTIME, TimerFD::NONBLOCK)
27 flags = tfd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
28 assert_equal(Fcntl::O_NONBLOCK, flags)
29 end if defined?(TimerFD::NONBLOCK)
31 def test_create_nonblock_sym
32 tfd = TimerFD.new(:REALTIME, :NONBLOCK)
33 flags = tfd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
34 assert_equal(Fcntl::O_NONBLOCK, flags)
35 end if defined?(TimerFD::NONBLOCK)
37 def test_create_cloexec
38 tfd = TimerFD.new(TimerFD::REALTIME, TimerFD::CLOEXEC)
39 flags = tfd.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC
40 assert_equal(Fcntl::FD_CLOEXEC, flags)
41 end if defined?(TimerFD::CLOEXEC)
44 tfd = TimerFD.new(TimerFD::REALTIME)
45 assert_equal([0, 0], tfd.settime(TimerFD::ABSTIME, 0, 0.01))
47 assert_equal 1, tfd.expirations
50 def test_settime_symbol
51 tfd = TimerFD.new(:REALTIME)
52 assert_equal([0, 0], tfd.settime(:ABSTIME, 0, 0.01))
54 assert_equal 1, tfd.expirations
58 tfd = TimerFD.new :REALTIME
60 assert_equal([0, 0], tfd.settime(nil, 0, now + 5))
61 interval, value = tfd.gettime
62 assert_equal 0, interval
63 assert_in_delta now + 5, value, 0.01
66 def test_expirations_nonblock
67 tfd = TimerFD.new(:MONOTONIC)
68 assert_equal([0, 0], tfd.settime(0, 0, 0.01))
69 assert_nil tfd.expirations(true)
71 assert_equal 1, tfd.expirations
73 end if defined?(SleepyPenguin::TimerFD)