Skip to content

Commit d5120e7

Browse files
authored
Merge pull request #26 from ruby/update-test-lib-20230324
Update test libraries from ruby/ruby 2023-03-24
2 parents ccfef9f + b9a51e2 commit d5120e7

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

test/lib/core_assertions.rb

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def syntax_check(code, fname, line)
111111
end
112112

113113
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 2.0, rss: false, **opt)
114-
# TODO: consider choosing some appropriate limit for MJIT and stop skipping this once it does not randomly fail
114+
# TODO: consider choosing some appropriate limit for RJIT and stop skipping this once it does not randomly fail
115+
pend 'assert_no_memory_leak may consider RJIT memory usage as leak' if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
116+
# For previous versions which implemented MJIT
115117
pend 'assert_no_memory_leak may consider MJIT memory usage as leak' if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
116118

117119
require_relative 'memory_status'
@@ -248,7 +250,11 @@ def separated_runner(token, out = nil)
248250
at_exit {
249251
out.puts "#{token}<error>", [Marshal.dump($!)].pack('m'), "#{token}</error>", "#{token}assertions=#{self._assertions}"
250252
}
251-
Test::Unit::Runner.class_variable_set(:@@stop_auto_run, true) if defined?(Test::Unit::Runner)
253+
if defined?(Test::Unit::Runner)
254+
Test::Unit::Runner.class_variable_set(:@@stop_auto_run, true)
255+
elsif defined?(Test::Unit::AutoRunner)
256+
Test::Unit::AutoRunner.need_auto_run = false
257+
end
252258
end
253259

254260
def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **opt)
@@ -535,11 +541,11 @@ def assert_not_respond_to(obj, (meth, *priv), msg = nil)
535541
refute_respond_to(obj, meth, msg)
536542
end
537543

538-
# pattern_list is an array which contains regexp and :*.
544+
# pattern_list is an array which contains regexp, string and :*.
539545
# :* means any sequence.
540546
#
541547
# pattern_list is anchored.
542-
# Use [:*, regexp, :*] for non-anchored match.
548+
# Use [:*, regexp/string, :*] for non-anchored match.
543549
def assert_pattern_list(pattern_list, actual, message=nil)
544550
rest = actual
545551
anchored = true
@@ -697,7 +703,7 @@ def assert_join_threads(threads, message = nil)
697703
msg = "exceptions on #{errs.length} threads:\n" +
698704
errs.map {|t, err|
699705
"#{t.inspect}:\n" +
700-
err.full_message(highlight: false, order: :top)
706+
(err.respond_to?(:full_message) ? err.full_message(highlight: false, order: :top) : err.message)
701707
}.join("\n---\n")
702708
if message
703709
msg = "#{message}\n#{msg}"
@@ -732,6 +738,39 @@ def assert_all_assertions_foreach(msg = nil, *keys, &block)
732738
end
733739
alias all_assertions_foreach assert_all_assertions_foreach
734740

741+
# Expect +seq+ to respond to +first+ and +each+ methods, e.g.,
742+
# Array, Range, Enumerator::ArithmeticSequence and other
743+
# Enumerable-s, and each elements should be size factors.
744+
#
745+
# :yield: each elements of +seq+.
746+
def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
747+
first = seq.first
748+
*arg = pre.call(first)
749+
times = (0..(rehearsal || (2 * first))).map do
750+
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
751+
yield(*arg)
752+
t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
753+
assert_operator 0, :<=, t
754+
t.nonzero?
755+
end
756+
times.compact!
757+
tmin, tmax = times.minmax
758+
tmax *= tmax / tmin
759+
tmax = 10**Math.log10(tmax).ceil
760+
761+
seq.each do |i|
762+
next if i == first
763+
t = tmax * i.fdiv(first)
764+
*arg = pre.call(i)
765+
message = "[#{i}]: in #{t}s"
766+
Timeout.timeout(t, Timeout::Error, message) do
767+
st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
768+
yield(*arg)
769+
assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message
770+
end
771+
end
772+
end
773+
735774
def diff(exp, act)
736775
require 'pp'
737776
q = PP.new(+"")

test/lib/envutil.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,24 @@ def self.diagnostic_reports(signame, pid, now)
297297
cmd = @ruby_install_name if "ruby-runner#{RbConfig::CONFIG["EXEEXT"]}" == cmd
298298
path = DIAGNOSTIC_REPORTS_PATH
299299
timeformat = DIAGNOSTIC_REPORTS_TIMEFORMAT
300-
pat = "#{path}/#{cmd}_#{now.strftime(timeformat)}[-_]*.crash"
300+
pat = "#{path}/#{cmd}_#{now.strftime(timeformat)}[-_]*.{crash,ips}"
301301
first = true
302302
30.times do
303303
first ? (first = false) : sleep(0.1)
304304
Dir.glob(pat) do |name|
305305
log = File.read(name) rescue next
306-
if /\AProcess:\s+#{cmd} \[#{pid}\]$/ =~ log
307-
File.unlink(name)
308-
File.unlink("#{path}/.#{File.basename(name)}.plist") rescue nil
309-
return log
306+
case name
307+
when /\.crash\z/
308+
if /\AProcess:\s+#{cmd} \[#{pid}\]$/ =~ log
309+
File.unlink(name)
310+
File.unlink("#{path}/.#{File.basename(name)}.plist") rescue nil
311+
return log
312+
end
313+
when /\.ips\z/
314+
if /^ *"pid" *: *#{pid},/ =~ log
315+
File.unlink(name)
316+
return log
317+
end
310318
end
311319
end
312320
end

0 commit comments

Comments
 (0)