From 1dce5edf993a15c66c61965fcab4c2f5a07f6312 Mon Sep 17 00:00:00 2001 From: mrkn Date: Tue, 27 Nov 2012 12:46:32 +0000 Subject: * bignum.c (bigdivrem): optimize the way to retry calculation of bigdivrem so that the calculation is started from the point where the last interruption was occurred. * bignum.c (bigdivrem1): ditto. * test/ruby/test_bignum.rb: add a test case for rb_bigdivrem in the case that an interruption is occurred during bigdivrem1 is running. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_bignum.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index b1497a9146..1ff23e2a00 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -581,6 +581,36 @@ class TestBignum < Test::Unit::TestCase assert_interrupt {(65536 ** 65536).to_s} end + def test_interrupt_during_bigdivrem + return unless Process.respond_to?(:kill) + begin + trace = [] + oldtrap = Signal.trap(:INT) {|sig| trace << :int } + a = 456 ** 100 + b = 123 ** 100 + c = nil + 100.times do |n| + a **= 3 + b **= 3 + trace.clear + th = Thread.new do + sleep 0.1; Process.kill :INT, $$ + sleep 0.1; Process.kill :INT, $$ + end + c = a / b + trace << :end + th.join + if trace == [:int, :int, :end] + assert_equal(a / b, c) + return + end + end + skip "cannot create suitable test case" + ensure + Signal.trap(:INT, oldtrap) if oldtrap + end + end + def test_too_big_to_s if (big = 2**31-1).is_a?(Fixnum) return -- cgit v1.2.3