diff options
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io_buffer.rb | 23 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 13 | ||||
-rw-r--r-- | test/ruby/test_zjit.rb | 89 |
3 files changed, 118 insertions, 7 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 55296c1f23..62c4667888 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -121,6 +121,16 @@ class TestIOBuffer < Test::Unit::TestCase end end + def test_string_mapped_buffer_frozen + string = "Hello World".freeze + IO::Buffer.for(string) do |buffer| + assert_raise IO::Buffer::AccessError, "Buffer is not writable!" do + buffer.set_string("abc") + end + assert_equal "H".ord, buffer.get_value(:U8, 0) + end + end + def test_non_string not_string = Object.new @@ -683,4 +693,17 @@ class TestIOBuffer < Test::Unit::TestCase buf.set_string('a', 0, 0) assert_predicate buf, :empty? end + + # https://bugs.ruby-lang.org/issues/21210 + def test_bug_21210 + omit "compaction is not supported on this platform" unless GC.respond_to?(:compact) + + str = +"hello" + buf = IO::Buffer.for(str) + assert_predicate buf, :valid? + + GC.verify_compaction_references(expand_heap: true, toward: :empty) + + assert_predicate buf, :valid? + end end diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 69f30c1ce3..54ad953ee9 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -870,13 +870,12 @@ class TestRubyOptions < Test::Unit::TestCase def test_segv_loaded_features bug7402 = '[ruby-core:49573]' - status = assert_segv(['-e', "END {#{SEGVTest::KILL_SELF}}", - '-e', 'class Bogus; def to_str; exit true; end; end', - '-e', '$".clear', - '-e', '$".unshift Bogus.new', - '-e', '(p $"; abort) unless $".size == 1', - ]) - assert_not_predicate(status, :success?, "segv but success #{bug7402}") + assert_segv(['-e', "END {#{SEGVTest::KILL_SELF}}", + '-e', 'class Bogus; def to_str; exit true; end; end', + '-e', '$".clear', + '-e', '$".unshift Bogus.new', + '-e', '(p $"; abort) unless $".size == 1', + ], success: false) end def test_segv_setproctitle diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb index 6095b0b734..2b171b02b1 100644 --- a/test/ruby/test_zjit.rb +++ b/test/ruby/test_zjit.rb @@ -31,6 +31,20 @@ class TestZJIT < Test::Unit::TestCase } end + def test_putstring + assert_compiles '""', %q{ + def test = "#{""}" + test + }, insns: [:putstring] + end + + def test_putchilldedstring + assert_compiles '""', %q{ + def test = "" + test + }, insns: [:putchilledstring] + end + def test_leave_param assert_compiles '5', %q{ def test(n) = n @@ -281,6 +295,34 @@ class TestZJIT < Test::Unit::TestCase }, insns: [:opt_ge], call_threshold: 2 end + def test_opt_hash_freeze + assert_compiles '{}', <<~RUBY, insns: [:opt_hash_freeze] + def test = {}.freeze + test + RUBY + end + + def test_opt_ary_freeze + assert_compiles '[]', <<~RUBY, insns: [:opt_ary_freeze] + def test = [].freeze + test + RUBY + end + + def test_opt_str_freeze + assert_compiles '""', <<~RUBY, insns: [:opt_str_freeze] + def test = "".freeze + test + RUBY + end + + def test_opt_str_uminus + assert_compiles '""', <<~RUBY, insns: [:opt_str_uminus] + def test = -"" + test + RUBY + end + def test_new_array_empty assert_compiles '[]', %q{ def test = [] @@ -636,6 +678,27 @@ class TestZJIT < Test::Unit::TestCase } end + def test_uncached_getconstant_path + assert_compiles RUBY_COPYRIGHT.dump, %q{ + def test = RUBY_COPYRIGHT + test + }, call_threshold: 1, insns: [:opt_getconstant_path] + end + + def test_getconstant_path_autoload + # A constant-referencing expression can run arbitrary code through Kernel#autoload. + Dir.mktmpdir('autoload') do |tmpdir| + autoload_path = File.join(tmpdir, 'test_getconstant_path_autoload.rb') + File.write(autoload_path, 'X = RUBY_COPYRIGHT') + + assert_compiles RUBY_COPYRIGHT.dump, %Q{ + Object.autoload(:X, #{File.realpath(autoload_path).inspect}) + def test = X + test + }, call_threshold: 1, insns: [:opt_getconstant_path] + end + end + def test_send_backtrace backtrace = [ "-e:2:in 'Object#jit_frame1'", @@ -652,6 +715,32 @@ class TestZJIT < Test::Unit::TestCase }, call_threshold: 2 end + def test_putspecialobject_vm_core_and_cbase + assert_compiles '10', %q{ + def test + alias bar test + 10 + end + + test + bar + }, insns: [:putspecialobject] + end + + def test_putspecialobject_const_base + assert_compiles '1', %q{ + Foo = 1 + + def test = Foo + + # First call: populates the constant cache + test + # Second call: triggers ZJIT compilation with warm cache + # RubyVM::ZJIT.assert_compiles will panic if this fails to compile + test + }, call_threshold: 2 + end + # tool/ruby_vm/views/*.erb relies on the zjit instructions a) being contiguous and # b) being reliably ordered after all the other instructions. def test_instruction_order |