Guard all accesses to RubyVM::MJIT with defined?(RubyVM::MJIT) &&

* Otherwise those tests, etc cannot run on alternative Ruby implementations.
This commit is contained in:
Benoit Daloze 2020-12-04 16:40:02 +01:00
Родитель 83e983ab61
Коммит b4ec4a41c2
18 изменённых файлов: 42 добавлений и 42 удалений

Просмотреть файл

@ -135,7 +135,7 @@ class BenchmarkDriver::Runner::MjitExec
nil
end
% end
RubyVM::MJIT.pause if RubyVM::MJIT.enabled?
RubyVM::MJIT.pause if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
def vm
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@ -172,7 +172,7 @@ class BenchmarkDriver::Runner::MjitExec
a<%= i %>
a<%= i %> # --jit-min-calls=2
% end
RubyVM::MJIT.pause if RubyVM::MJIT.enabled?
RubyVM::MJIT.pause if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
def vm
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@ -228,7 +228,7 @@ class BenchmarkDriver::Runner::MjitExec
jit
jit
RubyVM::MJIT.pause if RubyVM::MJIT.enabled?
RubyVM::MJIT.pause if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
File.write(<%= result.dump %>, jit)
EOS
end

Просмотреть файл

@ -383,8 +383,8 @@ def assert_normal_exit(testsrc, *rest, timeout: nil, **opt)
end
def assert_finish(timeout_seconds, testsrc, message = '')
if RubyVM.const_defined? :MJIT
timeout_seconds *= 3 if RubyVM::MJIT.enabled? # for --jit-wait
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
timeout_seconds *= 3
end
newtest
show_progress(message) {

Просмотреть файл

@ -7,7 +7,7 @@ class TestBugReporter < Test::Unit::TestCase
skip if ENV['RUBY_ON_BUG']
description = RUBY_DESCRIPTION
description = description.sub(/\+JIT /, '') if RubyVM::MJIT.enabled?
description = description.sub(/\+JIT /, '') if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
expected_stderr = [
:*,
/\[BUG\]\sSegmentation\sfault.*\n/,

Просмотреть файл

@ -216,7 +216,7 @@ module DRbCore
def test_06_timeout
skip if RUBY_PLATFORM.include?("armv7l-linux")
skip if RUBY_PLATFORM.include?("sparc-solaris2.10")
skip if RubyVM::MJIT.enabled? # expecting a certain delay is difficult for --jit-wait CI
skip if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # expecting a certain delay is difficult for --jit-wait CI
Timeout.timeout(60) do
ten = Onecky.new(10)
assert_raise(Timeout::Error) do

Просмотреть файл

@ -74,7 +74,7 @@ module JITSupport
end
def remove_mjit_logs(stderr)
if RubyVM::MJIT.enabled? # utility for -DFORCE_MJIT_ENABLE
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # utility for -DFORCE_MJIT_ENABLE
stderr.gsub(/^MJIT warning: Skipped to compile unsupported instruction: \w+\n/m, '')
else
stderr

Просмотреть файл

@ -762,7 +762,7 @@ class FTPTest < Test::Unit::TestCase
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
@ -807,7 +807,7 @@ class FTPTest < Test::Unit::TestCase
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
@ -1545,7 +1545,7 @@ EOF
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
assert_equal(['LANG EN*', 'UTF8'], ftp.features)
assert_equal("FEAT\r\n", commands.shift)
@ -1568,7 +1568,7 @@ EOF
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
assert_raise(Net::FTPPermError) do
ftp.features
@ -1594,7 +1594,7 @@ EOF
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.option("UTF8", "ON")
assert_equal("OPTS UTF8 ON\r\n", commands.shift)
@ -1653,7 +1653,7 @@ EOF
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
entry = ftp.mlst("foo")
assert_equal("/foo", entry.pathname)
@ -1740,7 +1740,7 @@ EOF
begin
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
@ -1779,7 +1779,7 @@ EOF
def test_parse257
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
assert_equal('/foo/bar',
ftp.send(:parse257, '257 "/foo/bar" directory created'))
assert_equal('/foo/bar"baz',
@ -1918,7 +1918,7 @@ EOF
port: port,
ssl: { ca_file: CA_FILE },
passive: false)
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
begin
assert_equal("AUTH TLS\r\n", commands.shift)
assert_equal("PBSZ 0\r\n", commands.shift)
@ -2003,7 +2003,7 @@ EOF
port: port,
ssl: { ca_file: CA_FILE },
passive: true)
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
begin
assert_equal("AUTH TLS\r\n", commands.shift)
assert_equal("PBSZ 0\r\n", commands.shift)
@ -2079,7 +2079,7 @@ EOF
ssl: { ca_file: CA_FILE },
private_data_connection: false,
passive: false)
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
begin
assert_equal("AUTH TLS\r\n", commands.shift)
ftp.login
@ -2149,7 +2149,7 @@ EOF
ssl: { ca_file: CA_FILE },
private_data_connection: false,
passive: true)
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
begin
assert_equal("AUTH TLS\r\n", commands.shift)
ftp.login
@ -2230,7 +2230,7 @@ EOF
ftp = Net::FTP.new(SERVER_NAME,
port: server.port,
ssl: { ca_file: CA_FILE })
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
assert_equal("AUTH TLS\r\n", commands.shift)
assert_equal("PBSZ 0\r\n", commands.shift)
assert_equal("PROT P\r\n", commands.shift)
@ -2342,7 +2342,7 @@ EOF
chdir_to_tmpdir do
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
@ -2448,7 +2448,7 @@ EOF
end
begin
ftp = Net::FTP.new
ftp.read_timeout *= 5 if RubyVM::MJIT.enabled? # for --jit-wait
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait
ftp.connect(SERVER_ADDR, server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)

Просмотреть файл

@ -78,7 +78,7 @@ EOS
def test_read_body_block_mod
# http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/3019353
skip 'too unstable with --jit-wait, and extending read_timeout did not help it' if RubyVM::MJIT.enabled?
skip 'too unstable with --jit-wait, and extending read_timeout did not help it' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
IO.pipe do |r, w|
buf = 'x' * 1024
buf.freeze

Просмотреть файл

@ -402,7 +402,7 @@ module TupleSpaceTestModule
end
def test_cancel_02
skip 'this test is unstable with --jit-wait' if RubyVM::MJIT.enabled?
skip 'this test is unstable with --jit-wait' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
entry = @ts.write([:removeme, 1])
assert_equal([[:removeme, 1]], @ts.read_all([nil, nil]))
entry.cancel
@ -662,7 +662,7 @@ class TestRingServer < Test::Unit::TestCase
end
def test_do_reply_local
skip 'timeout-based test becomes unstable with --jit-wait' if RubyVM::MJIT.enabled?
skip 'timeout-based test becomes unstable with --jit-wait' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
with_timeout(30) {_test_do_reply_local}
end

Просмотреть файл

@ -34,7 +34,7 @@ class TestFiber < Test::Unit::TestCase
end
def test_many_fibers
skip 'This is unstable on GitHub Actions --jit-wait. TODO: debug it' if RubyVM::MJIT.enabled?
skip 'This is unstable on GitHub Actions --jit-wait. TODO: debug it' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
max = 10_000
assert_equal(max, max.times{
Fiber.new{}

Просмотреть файл

@ -607,7 +607,7 @@ class TestIO < Test::Unit::TestCase
if have_nonblock?
def test_copy_stream_no_busy_wait
skip "MJIT has busy wait on GC. This sometimes fails with --jit." if RubyVM::MJIT.enabled?
skip "MJIT has busy wait on GC. This sometimes fails with --jit." if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
skip "multiple threads already active" if Thread.list.size > 1
msg = 'r58534 [ruby-core:80969] [Backport #13533]'
@ -1562,7 +1562,7 @@ class TestIO < Test::Unit::TestCase
end if have_nonblock?
def test_read_nonblock_no_exceptions
skip '[ruby-core:90895] MJIT worker may leave fd open in a forked child' if RubyVM::MJIT.enabled? # TODO: consider acquiring GVL from MJIT worker.
skip '[ruby-core:90895] MJIT worker may leave fd open in a forked child' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # TODO: consider acquiring GVL from MJIT worker.
with_pipe {|r, w|
assert_equal :wait_readable, r.read_nonblock(4096, exception: false)
w.puts "HI!"
@ -2210,7 +2210,7 @@ class TestIO < Test::Unit::TestCase
def test_autoclose_true_closed_by_finalizer
# http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1465760
# http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1469765
skip 'this randomly fails with MJIT' if RubyVM::MJIT.enabled?
skip 'this randomly fails with MJIT' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
feature2250 = '[ruby-core:26222]'
pre = 'ft2250'

Просмотреть файл

@ -452,7 +452,7 @@ class TestRubyOptimization < Test::Unit::TestCase
end
def test_tailcall_not_to_grow_stack
skip 'currently JIT-ed code always creates a new stack frame' if RubyVM::MJIT.enabled?
skip 'currently JIT-ed code always creates a new stack frame' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
bug16161 = '[ruby-core:94881]'
tailcall("#{<<-"begin;"}\n#{<<~"end;"}")

Просмотреть файл

@ -1681,7 +1681,7 @@ class TestProcess < Test::Unit::TestCase
Process.wait pid
assert_send [sig_r, :wait_readable, 5], 'self-pipe not readable'
end
if RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE. It may trigger extra SIGCHLD.
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE. It may trigger extra SIGCHLD.
assert_equal [true], signal_received.uniq, "[ruby-core:19744]"
else
assert_equal [true], signal_received, "[ruby-core:19744]"

Просмотреть файл

@ -8,7 +8,7 @@ require_relative '../lib/jit_support'
class TestRubyOptions < Test::Unit::TestCase
NO_JIT_DESCRIPTION =
if RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
RUBY_DESCRIPTION.sub(/\+JIT /, '')
else
RUBY_DESCRIPTION
@ -117,7 +117,7 @@ class TestRubyOptions < Test::Unit::TestCase
def test_verbose
assert_in_out_err(["-vve", ""]) do |r, e|
assert_match(VERSION_PATTERN, r[0])
if RubyVM::MJIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE
assert_equal(NO_JIT_DESCRIPTION, r[0])
else
assert_equal(RUBY_DESCRIPTION, r[0])
@ -180,7 +180,7 @@ class TestRubyOptions < Test::Unit::TestCase
def test_version
assert_in_out_err(%w(--version)) do |r, e|
assert_match(VERSION_PATTERN, r[0])
if RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
else
assert_equal(RUBY_DESCRIPTION, r[0])
@ -210,7 +210,7 @@ class TestRubyOptions < Test::Unit::TestCase
].each do |args|
assert_in_out_err(args) do |r, e|
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
if RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # checking -DMJIT_FORCE_ENABLE
assert_equal(RUBY_DESCRIPTION, r[0])
else
assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])

Просмотреть файл

@ -1963,7 +1963,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
Thread.pass until t.status == 'sleep'
# When MJIT thread exists, t.status becomes 'sleep' even if it does not reach m2t_q.pop.
# This sleep forces it to reach m2t_q.pop for --jit-wait.
sleep 1 if RubyVM::MJIT.enabled?
sleep 1 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
t.add_trace_func proc{|ev, file, line, *args|
if file == __FILE__

Просмотреть файл

@ -309,7 +309,7 @@ class TestThread < Test::Unit::TestCase
s += 1
end
Thread.pass until t.stop?
sleep 1 if RubyVM::MJIT.enabled? # t.stop? behaves unexpectedly with --jit-wait
sleep 1 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # t.stop? behaves unexpectedly with --jit-wait
assert_equal(1, s)
t.wakeup
Thread.pass while t.alive?
@ -1338,7 +1338,7 @@ q.pop
opts = { timeout: 5, timeout_error: nil }
# prevent SIGABRT from slow shutdown with MJIT
opts[:reprieve] = 3 if RubyVM::MJIT.enabled?
opts[:reprieve] = 3 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
assert_normal_exit(<<-_end, '[Bug #8996]', **opts)
Thread.report_on_exception = false

Просмотреть файл

@ -485,7 +485,7 @@ class TestSocket < Test::Unit::TestCase
end while IO.select([r], nil, nil, 0.1).nil?
n
end
timeout = (RubyVM::MJIT.enabled? ? 120 : 30) # for --jit-wait
timeout = (defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? ? 120 : 30) # for --jit-wait
assert_equal([[s1],[],[]], IO.select([s1], nil, nil, timeout))
msg, _, _, stamp = s1.recvmsg
assert_equal("a", msg)

Просмотреть файл

@ -6,7 +6,7 @@ class TestHideSkip < Test::Unit::TestCase
assert_not_match(/^ *1\) Skipped/, hideskip)
assert_match(/^ *1\) Skipped/, hideskip("--show-skip"))
output = hideskip("--hide-skip")
output.gsub!(/Successful MJIT finish\n/, '') if RubyVM::MJIT.enabled?
output.gsub!(/Successful MJIT finish\n/, '') if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
assert_match(/assertions\/s.\n+1 tests, 0 assertions, 0 failures, 0 errors, 1 skips/, output)
end

Просмотреть файл

@ -6,7 +6,7 @@ module TestParallel
PARALLEL_RB = "#{File.dirname(__FILE__)}/../../lib/test/unit/parallel.rb"
TESTS = "#{File.dirname(__FILE__)}/tests_for_parallel"
# use large timeout for --jit-wait
TIMEOUT = EnvUtil.apply_timeout_scale(RubyVM::MJIT.enabled? ? 100 : 30)
TIMEOUT = EnvUtil.apply_timeout_scale(defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? ? 100 : 30)
class TestParallelWorker < Test::Unit::TestCase
def setup