add SignalFD interface
[sleepy_penguin.git] / test / test_signalfd.rb
blobdf6b3c9658d030af90e1648bcf442fc359cc25fc
1 require 'test/unit'
2 $-w = true
3 require 'sleepy_penguin'
5 class TestSignalFD < Test::Unit::TestCase
6   include SleepyPenguin
8   def setup
9     @sfd = nil
10   end
12   def teardown
13     @sfd.close if @sfd && ! @sfd.closed?
14   end
16   def test_gets
17     @sfd = SignalFD.new(%w(USR1), 0)
18     pid = fork { sleep 0.01; Process.kill(:USR1, Process.ppid) }
19     siginfo = @sfd.gets
20     assert_equal Signal.list["USR1"], siginfo.signo
21     assert_equal pid, siginfo.pid
22     assert Process.waitpid2(pid)[1].success?
23   end
24 end if RUBY_VERSION =~ %r{\A1\.9} && defined?(SleepyPenguin::SignalFD)