From 8d10e4aa66f32abd16d9b6ac0049f777be495d6b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 9 Jan 2015 07:28:21 +0000 Subject: test_posix_mq: rewrite test to not depend on DL or alarm DL is removed and deprecated, and we don't actually need it or alarm to test for EINTR-safety. --- test/test_posix_mq.rb | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb index 54c7223..3583022 100644 --- a/test/test_posix_mq.rb +++ b/test/test_posix_mq.rb @@ -3,11 +3,6 @@ require 'test/unit' require 'thread' require 'fcntl' $stderr.sync = $stdout.sync = true -require "dl" -begin - require "dl/func" -rescue LoadError -end $-w = true require 'posix_mq' @@ -104,23 +99,15 @@ class Test_POSIX_MQ < Test::Unit::TestCase assert elapsed < 1.10, elapsed.inspect end - def test_alarm_signal_safe - libc = alarm = nil - libcs = %w(libc.so.6 libc.so.0.1 libc.so.7 /usr/lib/libc.sl) - libcs.each do |name| - libc = DL::Handle.new(name) rescue next - if defined?(DL::Function) - alarm = libc["alarm"] - alarm = DL::CFunc.new(alarm, DL::TYPE_INT, "alarm") - alarm = DL::Function.new(alarm, [DL::TYPE_INT]) - else - alarm = libc["alarm", "II"] + def test_signal_safe + alarm = lambda do |x| + Thread.new(x) do |time| + sleep(time) + Process.kill(:USR1, $$) end - break end - alarm or return warn "alarm() not found in #{libcs.inspect}" alarms = 0 - trap("ALRM") do + sig = trap(:USR1) do alarms += 1 Thread.new { @mq.send("HI") } end @@ -135,6 +122,8 @@ class Test_POSIX_MQ < Test::Unit::TestCase assert elapsed >= interval, elapsed.inspect assert elapsed < 1.10, elapsed.inspect assert_equal 1, alarms + ensure + trap(:USR1, sig) if sig end def test_timed_send -- cgit v1.2.3-24-ge0c7