ruby-changes:68760
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:28 +0900 (JST)
Subject: [ruby-changes:68760] d192b149ba (master): Added more tests to `make btest`
https://git.ruby-lang.org/ruby.git/commit/?id=d192b149ba From d192b149ba5b6f0bb8222519793a59b60c637f78 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Fri, 12 Feb 2021 14:35:57 -0500 Subject: Added more tests to `make btest` --- bootstraptest/test_ujit.rb | 123 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 30 deletions(-) diff --git a/bootstraptest/test_ujit.rb b/bootstraptest/test_ujit.rb index 0894a1b4e2..65e20fa117 100644 --- a/bootstraptest/test_ujit.rb +++ b/bootstraptest/test_ujit.rb @@ -10,51 +10,36 @@ assert_equal '2', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ujit.rb#L10 check_index 2 } -# Method redefinition (code invalidation) test -assert_equal '1', %q{ - def ret1 - return 1 - end - - klass = Class.new do - def alias_then_hash(klass, method_to_redefine) - # Redefine the method to be ret1 - klass.alias_method(method_to_redefine, :ret1) - hash - end +# foo leaves a temp on the stack before the call +assert_equal '6', %q{ + def bar + return 5 end - instance = klass.new - - i = 0 - while i < 12 - if i < 11 - # Redefine the bar method - instance.alias_then_hash(klass, :bar) - else - # Redefine the hash method to be ret1 - retval = instance.alias_then_hash(klass, :hash) - end - i += 1 + def foo + return 1 + bar end - retval + foo() + retval = foo() } +# Method with one arguments # foo leaves a temp on the stack before the call -assert_equal '6', %q{ - def bar - return 5 +assert_equal '7', %q{ + def bar(a) + return a + 1 end def foo - return 1 + bar + return 1 + bar(5) end foo() retval = foo() } +# Method with two arguments # foo leaves a temp on the stack before the call assert_equal '0', %q{ def bar(a, b) @@ -71,7 +56,6 @@ assert_equal '0', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ujit.rb#L56 # Recursive Ruby-to-Ruby calls assert_equal '21', %q{ - def fib(n) if n < 2 return n @@ -97,6 +81,85 @@ assert_normal_exit %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ujit.rb#L81 foo() } +# Method redefinition (code invalidation) test +assert_equal '1', %q{ + def ret1 + return 1 + end + + klass = Class.new do + def alias_then_hash(klass, method_to_redefine) + # Redefine the method to be ret1 + klass.alias_method(method_to_redefine, :ret1) + hash + end + end + + instance = klass.new + + i = 0 + while i < 12 + if i < 11 + # Redefine the bar method + instance.alias_then_hash(klass, :bar) + else + # Redefine the hash method to be ret1 + retval = instance.alias_then_hash(klass, :hash) + end + i += 1 + end + + retval +} + +# Method redefinition (code invalidation) and GC +assert_equal '7', %q{ + def bar() + return 5 + end + + def foo() + bar() + end + + foo() + foo() + + def bar() + return 7 + end + + 4.times { GC.start } + + foo() + foo() +} + +# Method redefinition with two block versions +assert_equal '7', %q{ + def bar() + return 5 + end + + def foo(n) + return ((n < 5)? 5:false), bar() + end + + foo(4) + foo(4) + foo(10) + foo(10) + + def bar() + return 7 + end + + 4.times { GC.start } + + foo(4) + foo(4)[1] +} + # Test for GC safety. Don't invalidate dead iseqs. assert_normal_exit %q{ Class.new do -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/