5 require 'sleepy_penguin'
7 class TestEventFD < Test::Unit::TestCase
11 defined?(EventFD::NONBLOCK) and
12 assert_kind_of Integer, EventFD::NONBLOCK
13 defined?(EventFD::CLOEXEC) and
14 assert_kind_of Integer, EventFD::CLOEXEC
15 defined?(EventFD::SEMAPHORE) and
16 assert_kind_of Integer, EventFD::SEMAPHORE
17 assert_equal 0xfffffffffffffffe, EventFD::MAX
22 assert_kind_of(IO, efd)
23 if RUBY_VERSION.to_f >= 2.0
24 assert_equal 1, efd.fcntl(Fcntl::F_GETFD)
26 assert_equal 0, efd.fcntl(Fcntl::F_GETFD)
31 efd = EventFD.new(0, EventFD::NONBLOCK)
32 flags = efd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
33 assert_equal(Fcntl::O_NONBLOCK, flags)
34 end if defined?(EventFD::NONBLOCK)
36 def test_new_nonblock_cloexec_sym
37 efd = EventFD.new(0, [:NONBLOCK,:CLOEXEC])
38 flags = efd.fcntl(Fcntl::F_GETFL) & Fcntl::O_NONBLOCK
39 assert_equal(Fcntl::O_NONBLOCK, flags)
41 flags = efd.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC
42 assert_equal(Fcntl::FD_CLOEXEC, flags)
43 end if defined?(EventFD::NONBLOCK) && defined?(EventFD::CLOEXEC)
46 efd = EventFD.new(0, EventFD::CLOEXEC)
47 flags = efd.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC
48 assert_equal(Fcntl::FD_CLOEXEC, flags)
49 end if defined?(EventFD::CLOEXEC)
53 assert_equal true, efd.incr(1)
54 assert_equal 1, efd.value
56 assert_nil efd.value(true)
57 assert_equal true, efd.incr(9)
58 assert_equal 9, efd.value(true)
60 assert_equal true, efd.incr(0xfffffffffffffffe)
61 assert_equal false, efd.incr(1, true)
64 def test_incr_value_semaphore
65 efd = EventFD.new(6, :SEMAPHORE)
66 6.times { assert_equal 1, efd.value }
67 assert_nil efd.value(true)
68 assert_equal true, efd.incr(1)
69 assert_equal 1, efd.value
71 end if defined?(SleepyPenguin::EventFD)