2018-08-09 05:58:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'test/unit'
|
2019-07-09 08:04:07 -04:00
|
|
|
require_relative '../lib/jit_support'
|
2018-08-09 05:58:07 -04:00
|
|
|
|
2018-10-20 04:06:50 -04:00
|
|
|
return if RbConfig::CONFIG["MJIT_SUPPORT"] == 'no'
|
|
|
|
|
2018-08-09 05:58:07 -04:00
|
|
|
class TestRubyVMMJIT < Test::Unit::TestCase
|
|
|
|
include JITSupport
|
|
|
|
|
2018-10-19 10:26:29 -04:00
|
|
|
def setup
|
|
|
|
unless JITSupport.supported?
|
|
|
|
skip 'JIT seems not supported on this platform'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-09 05:58:07 -04:00
|
|
|
def test_pause
|
|
|
|
out, err = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, wait: false)
|
|
|
|
i = 0
|
|
|
|
while i < 5
|
|
|
|
eval("def mjit#{i}; end; mjit#{i}")
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
print RubyVM::MJIT.pause
|
|
|
|
print RubyVM::MJIT.pause
|
|
|
|
while i < 10
|
|
|
|
eval("def mjit#{i}; end; mjit#{i}")
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
print RubyVM::MJIT.pause # no JIT here
|
|
|
|
EOS
|
|
|
|
assert_equal('truefalsefalse', out)
|
2018-08-11 10:09:26 -04:00
|
|
|
assert_equal(
|
|
|
|
5, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size,
|
|
|
|
"unexpected stdout:\n```\n#{out}```\n\nstderr:\n```\n#{err}```",
|
|
|
|
)
|
2018-08-09 05:58:07 -04:00
|
|
|
end
|
|
|
|
|
2018-10-19 11:08:55 -04:00
|
|
|
def test_pause_does_not_hang_on_full_units
|
|
|
|
out, _ = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, max_cache: 10, wait: false)
|
|
|
|
i = 0
|
|
|
|
while i < 11
|
|
|
|
eval("def mjit#{i}; end; mjit#{i}")
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
print RubyVM::MJIT.pause
|
|
|
|
EOS
|
|
|
|
assert_equal('true', out)
|
|
|
|
end
|
|
|
|
|
2018-08-09 05:58:07 -04:00
|
|
|
def test_pause_wait_false
|
|
|
|
out, err = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, wait: false)
|
|
|
|
i = 0
|
|
|
|
while i < 10
|
|
|
|
eval("def mjit#{i}; end; mjit#{i}")
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
print RubyVM::MJIT.pause(wait: false)
|
|
|
|
print RubyVM::MJIT.pause(wait: false)
|
|
|
|
EOS
|
|
|
|
assert_equal('truefalse', out)
|
|
|
|
assert_equal(true, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size < 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_resume
|
|
|
|
out, err = eval_with_jit(<<~'EOS', verbose: 1, min_calls: 1, wait: false)
|
|
|
|
print RubyVM::MJIT.resume
|
|
|
|
print RubyVM::MJIT.pause
|
|
|
|
print RubyVM::MJIT.resume
|
|
|
|
print RubyVM::MJIT.resume
|
|
|
|
print RubyVM::MJIT.pause
|
|
|
|
EOS
|
|
|
|
assert_equal('falsetruetruefalsetrue', out)
|
|
|
|
assert_equal(0, err.scan(/#{JITSupport::JIT_SUCCESS_PREFIX}/).size)
|
|
|
|
end
|
|
|
|
end
|