1 require_relative 'helper'
8 require 'sleepy_penguin'
10 class TestEpollOptimizations < Test::Unit::TestCase
20 [ @ep, @rd, @wr ].each { |io| io.close unless io.closed? }
24 io, err = Strace.me do
25 @ep.set(@wr, Epoll::OUT)
26 @ep.set(@wr, Epoll::OUT)
29 lines = io.readlines; io.close
30 assert_equal 1, lines.grep(/^epoll_ctl/).size, lines.inspect
31 assert_match(/EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0])
33 io, err = Strace.me { @ep.set(@wr, Epoll::OUT | Epoll::ONESHOT) }
35 lines = io.readlines; io.close
36 assert_equal 1, lines.grep(/^epoll_ctl/).size
37 assert_match(/EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0])
39 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
41 lines = io.readlines; io.close
42 assert_equal 1, lines.grep(/^epoll_ctl/).size
43 assert_match(/EPOLL_CTL_MOD/, lines.grep(/^epoll_ctl/)[0])
48 io, err = Strace.me { @ep.set(@wr, Epoll::OUT) }
50 lines = io.readlines; io.close
51 assert_equal 1, lines.grep(/^epoll_ctl/).size
52 assert_match(/EPOLL_CTL_ADD/, lines.grep(/^epoll_ctl/)[0])
56 @ep.set(@wr, Epoll::OUT)
58 io, err = Strace.me { rv = @ep.delete(@wr) }
61 lines = io.readlines; io.close
62 assert_equal 1, lines.grep(/^epoll_ctl/).size
63 assert_match(%r{=\s+0$}, lines.grep(/^epoll_ctl/)[0])
66 io, err = Strace.me { rv = @ep.delete(@wr) }
69 lines = io.readlines; io.close
70 assert_equal 0, lines.grep(/^epoll_ctl/).size
73 def test_delete_closed
75 @ep.set(@wr, Epoll::OUT)
79 assert_equal a, @wr.fileno
81 io, err = Strace.me { rv = @ep.delete(@wr) }
82 lines = io.readlines; io.close
85 assert_equal 0, lines.grep(/^epoll_ctl/).size
88 def test_delete_closed_proxy
89 obj = Struct.new(:to_io).new(@wr)
91 @ep.add(obj, Epoll::OUT)
93 io, err = Strace.me { rv = @ep.delete(obj) }
94 lines = io.readlines; io.close
95 assert_kind_of IOError, err
97 assert_equal 0, lines.grep(/^epoll_ctl/).size
100 def test_delete_aliased_a
101 tmp = IO.for_fd @wr.fileno
103 @ep.set(tmp, Epoll::OUT)
105 io, err = Strace.me { rv = @ep.delete(@wr) }
106 lines = io.readlines; io.close
109 assert_equal 1, lines.grep(/^epoll_ctl/).size
110 assert_match %r{=\s+0$}, lines.grep(/^epoll_ctl/)[0]
111 assert_equal 0, lines.grep(/ENOENT/).size
114 def test_delete_aliased_b
115 tmp = IO.for_fd @wr.fileno
117 @ep.set(@wr, Epoll::OUT)
119 io, err = Strace.me { rv = @ep.delete(tmp) }
120 lines = io.readlines; io.close
123 assert_equal 1, lines.grep(/^epoll_ctl/).size
124 assert_match(%r{=\s+0$}, lines.grep(/^epoll_ctl/)[0])
125 assert_equal 0, lines.grep(/ENOENT/).size
128 def test_delete_aliased_closed
129 tmp = IO.for_fd @wr.fileno
131 @ep.set(tmp, Epoll::OUT)
134 io, err = Strace.me { rv = @ep.delete(tmp) }
135 lines = io.readlines; io.close
138 assert_equal 1, lines.grep(/^epoll_ctl/).size
139 assert_equal 1, lines.grep(/EBADF/).size
141 end if defined?(Strace)