diff options
Diffstat (limited to 'bootstraptest/runner.rb')
-rwxr-xr-x | bootstraptest/runner.rb | 127 |
1 files changed, 102 insertions, 25 deletions
diff --git a/bootstraptest/runner.rb b/bootstraptest/runner.rb index 3d42390254..20f121cdf4 100755 --- a/bootstraptest/runner.rb +++ b/bootstraptest/runner.rb @@ -6,7 +6,6 @@ # Never use optparse in this file. # Never use test/unit in this file. # Never use Ruby extensions in this file. -# Maintain Ruby 1.8 compatibility for now $start_time = Time.now @@ -61,7 +60,7 @@ if !Dir.respond_to?(:mktmpdir) end # Configuration -BT = Struct.new(:ruby, +bt = Struct.new(:ruby, :verbose, :color, :tty, @@ -73,9 +72,78 @@ BT = Struct.new(:ruby, :failed, :reset, :columns, + :window_width, :width, + :indent, :platform, - ).new + ) +BT = Class.new(bt) do + def indent=(n) + super + if (self.columns ||= 0) < n + $stderr.print(' ' * (n - self.columns)) + end + self.columns = indent + end + + def putc(c) + unless self.quiet + if self.window_width == nil + unless w = ENV["COLUMNS"] and (w = w.to_i) > 0 + w = 80 + end + w -= 1 + self.window_width = w + end + if self.window_width and self.columns >= self.window_width + $stderr.print "\n", " " * (self.indent ||= 0) + self.columns = indent + end + $stderr.print c + $stderr.flush + self.columns += 1 + end + end + + def wn=(wn) + unless wn == 1 + if /(?:\A|\s)--jobserver-(?:auth|fds)=(?:(\d+),(\d+)|fifo:((?:\\.|\S)+))/ =~ ENV.delete("MAKEFLAGS") + begin + if fifo = $3 + fifo.gsub!(/\\(?=.)/, '') + r = File.open(fifo, IO::RDONLY|IO::NONBLOCK|IO::BINARY) + w = File.open(fifo, IO::WRONLY|IO::NONBLOCK|IO::BINARY) + else + r = IO.for_fd($1.to_i(10), "rb", autoclose: false) + w = IO.for_fd($2.to_i(10), "wb", autoclose: false) + end + rescue + r.close if r + else + r.close_on_exec = true + w.close_on_exec = true + tokens = r.read_nonblock(wn > 0 ? wn : 1024, exception: false) + r.close + if String === tokens + tokens.freeze + auth = w + w = nil + at_exit {auth << tokens; auth.close} + wn = tokens.size + 1 + else + w.close + wn = 1 + end + end + end + if wn <= 0 + require 'etc' + wn = [Etc.nprocessors / 2, 1].max + end + end + super wn + end +end.new BT_STATE = Struct.new(:count, :error).new @@ -87,7 +155,7 @@ def main BT.color = nil BT.tty = nil BT.quiet = false - BT.wn = 1 + # BT.wn = 1 dir = nil quiet = false tests = nil @@ -122,12 +190,7 @@ def main BT.quiet = true true when /\A-j(\d+)?/ - wn = $1.to_i - if wn <= 0 - require 'etc' - wn = [Etc.nprocessors / 2, 1].max - end - BT.wn = wn + BT.wn = $1.to_i true when /\A(-v|--v(erbose))\z/ BT.verbose = true @@ -154,8 +217,7 @@ End end } if tests and not ARGV.empty? - $stderr.puts "--tests and arguments are exclusive" - exit false + abort "--sets and arguments are exclusive" end tests ||= ARGV tests = Dir.glob("#{File.dirname($0)}/test_*.rb").sort if tests.empty? @@ -164,6 +226,7 @@ End BT.progress = %w[- \\ | /] BT.progress_bs = "\b" * BT.progress[0].size BT.tty = $stderr.tty? if BT.tty.nil? + BT.wn ||= /-j(\d+)?/ =~ (ENV["MAKEFLAGS"] || ENV["MFLAGS"]) ? $1.to_i : 1 case BT.color when nil @@ -241,7 +304,7 @@ def concurrent_exec_test end end - $stderr.print ' ' unless BT.quiet + BT.indent = 1 aq.close i = 1 term_wn = 0 @@ -253,7 +316,7 @@ def concurrent_exec_test when BT.tty $stderr.print "#{BT.progress_bs}#{BT.progress[(i+=1) % BT.progress.size]}" else - $stderr.print '.' + BT.putc '.' end else term_wn += 1 @@ -275,7 +338,7 @@ def exec_test(pathes) # execute tests if BT.wn > 1 - concurrent_exec_test if BT.wn > 1 + concurrent_exec_test else prev_basename = nil Assertion.all.each do |basename, assertions| @@ -364,7 +427,7 @@ class Assertion < Struct.new(:src, :path, :lineno, :proc) def initialize(*args) super self.class.add self - @category = self.path.match(/test_(.+)\.rb/)[1] + @category = self.path[/\Atest_(.+)\.rb\z/, 1] end def call @@ -428,7 +491,7 @@ class Assertion < Struct.new(:src, :path, :lineno, :proc) elsif BT.verbose $stderr.printf(". %.3f\n", t) else - $stderr.print '.' + BT.putc '.' end else $stderr.print "#{BT.failed}F" @@ -487,9 +550,14 @@ class Assertion < Struct.new(:src, :path, :lineno, :proc) def make_srcfile(frozen_string_literal: nil) filename = "bootstraptest.#{self.path}_#{self.lineno}_#{self.id}.rb" File.open(filename, 'w') {|f| - f.puts "#frozen_string_literal:true" if frozen_string_literal - f.puts "GC.stress = true" if $stress - f.puts "print(begin; #{self.src}; end)" + f.puts "#frozen_string_literal:#{frozen_string_literal}" unless frozen_string_literal.nil? + if $stress + f.puts "GC.stress = true" if $stress + else + f.puts "" + end + f.puts "class BT_Skip < Exception; end; def skip(msg) = raise(BT_Skip, msg.to_s)" + f.puts "print(begin; #{self.src}; rescue BT_Skip; $!.message; end)" } filename end @@ -503,9 +571,9 @@ def add_assertion src, pr Assertion.new(src, path, lineno, pr) end -def assert_equal(expected, testsrc, message = '', opt = '', **argh) +def assert_equal(expected, testsrc, message = '', opt = '', **kwargs) add_assertion testsrc, -> as do - as.assert_check(message, opt, **argh) {|result| + as.assert_check(message, opt, **kwargs) {|result| if expected == result nil else @@ -516,9 +584,9 @@ def assert_equal(expected, testsrc, message = '', opt = '', **argh) end end -def assert_match(expected_pattern, testsrc, message = '') +def assert_match(expected_pattern, testsrc, message = '', **argh) add_assertion testsrc, -> as do - as.assert_check(message) {|result| + as.assert_check(message, **argh) {|result| if expected_pattern =~ result nil else @@ -605,7 +673,7 @@ end def assert_finish(timeout_seconds, testsrc, message = '') add_assertion testsrc, -> as do - if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # for --jit-wait + if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # for --jit-wait timeout_seconds *= 3 end @@ -720,4 +788,13 @@ def check_coredump end end +def yjit_enabled? + ENV.key?('RUBY_YJIT_ENABLE') || ENV.fetch('RUN_OPTS', '').include?('yjit') || BT.ruby.include?('yjit') +end + +def rjit_enabled? + # Don't check `RubyVM::RJIT.enabled?`. On btest-bruby, target Ruby != runner Ruby. + ENV.fetch('RUN_OPTS', '').include?('rjit') +end + exit main |