8 require 'sleepy_penguin'
10 class TestEpollOptimizations < Test::Unit::TestCase
12 RBX = defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'rbx')
21 [ @ep, @rd, @wr ].each { |io| io.close unless io.closed? }
25 io, err = Strace.me do
26 @ep.set(@wr, Epoll::OUT)
27 @ep.set(@wr, Epoll::OUT)
30 lines = io.readlines; io.close
31 assert_equal 1, lines.grep(/^epoll_ctl/).size
32 assert_match(/EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0])
34 io, err = Strace.me { @ep.set(@wr, Epoll::OUT | Epoll::ONESHOT) }
36 lines = io.readlines; io.close
37 assert_equal 1, lines.grep(/^epoll_ctl/).size
38 assert_match(/EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0])
40 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
42 lines = io.readlines; io.close
43 assert_equal 1, lines.grep(/^epoll_ctl/).size
44 assert_match(/EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0])
49 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
51 lines = io.readlines; io.close
52 assert_equal 1, lines.grep(/^epoll_ctl/).size
53 assert_match(/EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0])
57 @ep.set(@wr, Epoll::OUT)
59 io, err = Strace.me { rv = @ep.delete(@wr) }
62 lines = io.readlines; io.close
63 assert_equal 1, lines.grep(/^epoll_ctl/).size
64 assert_match(%r{=\s+0$}, lines.grep(/^epoll_ctl/)[0])
67 io, err = Strace.me { rv = @ep.delete(@wr) }
70 lines = io.readlines; io.close
71 assert_equal 0, lines.grep(/^epoll_ctl/).size
74 def test_delete_closed
76 @ep.set(@wr, Epoll::OUT)
80 assert_equal a, @wr.fileno
82 io, err = Strace.me { rv = @ep.delete(@wr) }
83 lines = io.readlines; io.close
86 assert_equal 0, lines.grep(/^epoll_ctl/).size
89 def test_delete_closed_proxy
90 obj = Struct.new(:to_io).new(@wr)
92 @ep.add(obj, Epoll::OUT)
94 io, err = Strace.me { rv = @ep.delete(obj) }
95 lines = io.readlines; io.close
96 assert_kind_of IOError, err
98 assert_equal 0, lines.grep(/^epoll_ctl/).size
101 def test_delete_aliased_a
102 tmp = IO.for_fd @wr.fileno
104 @ep.set(tmp, Epoll::OUT)
106 io, err = Strace.me { rv = @ep.delete(@wr) }
107 lines = io.readlines; io.close
110 assert_equal 1, lines.grep(/^epoll_ctl/).size
111 assert_match %r{=\s+0$}, lines.grep(/^epoll_ctl/)[0]
112 assert_equal 0, lines.grep(/ENOENT/).size
115 def test_delete_aliased_b
116 tmp = IO.for_fd @wr.fileno
118 @ep.set(@wr, Epoll::OUT)
120 io, err = Strace.me { rv = @ep.delete(tmp) }
121 lines = io.readlines; io.close
124 assert_equal 1, lines.grep(/^epoll_ctl/).size
125 assert_match(%r{=\s+0$}, lines.grep(/^epoll_ctl/)[0])
126 assert_equal 0, lines.grep(/ENOENT/).size
129 def test_delete_aliased_closed
130 tmp = IO.for_fd @wr.fileno
132 @ep.set(tmp, Epoll::OUT)
135 io, err = Strace.me { rv = @ep.delete(tmp) }
136 lines = io.readlines; io.close
139 assert_equal 1, lines.grep(/^epoll_ctl/).size
140 assert_equal 1, lines.grep(/EBADF/).size
142 end if defined?(Strace)