diff options
author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2021-02-12 14:35:57 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:29 -0400 |
commit | d192b149ba5b6f0bb8222519793a59b60c637f78 (patch) | |
tree | f1249d9a493f301e6f8e5f02e107de50532068a5 /bootstraptest | |
parent | 8ed77f96fc7df4ff0a1a91507cd7bf11e1f6788e (diff) |
Added more tests to `make btest`
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ujit.rb | 123 |
1 files 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{ 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{ # 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{ 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 |