From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.posix-mq.general Subject: [PATCH] test_posix_mq: rewrite test to not depend on DL or alarm Date: Fri, 9 Jan 2015 07:35:23 +0000 Message-ID: <1420788923-23815-1-git-send-email-normalperson@yhbt.net> References: <1420788923-23815-1-git-send-email-normalperson@yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1420788986 27159 80.91.229.3 (9 Jan 2015 07:36:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 9 Jan 2015 07:36:26 +0000 (UTC) To: ruby.posix.mq@librelist.com Original-X-From: ruby.posix.mq@librelist.com Fri Jan 09 08:36:22 2015 Return-path: Envelope-to: gclrpg-ruby.posix.mq@m.gmane.org In-Reply-To: <1420788923-23815-1-git-send-email-normalperson@yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: ruby.posix.mq@librelist.com Xref: news.gmane.org gmane.comp.lang.ruby.posix-mq.general:125 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y9U6i-0001sM-KA for gclrpg-ruby.posix.mq@m.gmane.org; Fri, 09 Jan 2015 08:35:44 +0100 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 35DAB74FE7 for ; Fri, 9 Jan 2015 07:37:12 +0000 (UTC) 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 -- EW