summaryrefslogtreecommitdiff
path: root/test/ruby/envutil.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-09 04:17:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-09 04:17:38 +0000
commite20cd8ee490537127fa07e22991bdc22402953e4 (patch)
tree7ec660abe3ce50097b9e3293827c2b58d1a45c1f /test/ruby/envutil.rb
parent68649699670a4c69fa198f98a4215b3eb5135284 (diff)
test/ruby/envutil.rb: compare RSS to check memory leak
* test/ruby/envutil.rb (Test::Test#assert_no_memory_leak): compare also RSS if available. * test/ruby/memory_status.rb (Memory::Status.parse): read string form of an instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/envutil.rb')
-rw-r--r--test/ruby/envutil.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index d49d423ca4..90a39e7140 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -391,6 +391,7 @@ eom
end
def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5, **opt)
+ require_relative 'memory_status'
token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m"
token_dump = token.dump
token_re = Regexp.quote(token)
@@ -403,16 +404,22 @@ eom
]
args.unshift(envs) if envs
cmd = [
- 'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}',
+ 'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new}"}',
prepare,
- 'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")',
+ 'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new}")',
code,
+ 'GC.start',
].join("\n")
_, err, status = EnvUtil.invoke_ruby(args, cmd, true, true, **opt)
- before = err.sub!(/^#{token_re}START=(\d+)\n/, '') && $1.to_i
- after = err.sub!(/^#{token_re}FINAL=(\d+)\n/, '') && $1.to_i
+ before = err.sub!(/^#{token_re}START=(\{.*\})\n/, '') && Memory::Status.parse($1)
+ after = err.sub!(/^#{token_re}FINAL=(\{.*\})\n/, '') && Memory::Status.parse($1)
assert_equal([true, ""], [status.success?, err], message)
- assert_operator(after.fdiv(before), :<, limit, message)
+ ([:size, :rss] & after.members).each do |n|
+ b = before[n]
+ a = after[n]
+ next unless a > 0 and b > 0
+ assert_operator(a.fdiv(b), :<, limit, message(message) {"#{n}: #{b} => #{a}"})
+ end
end
def assert_is_minus_zero(f)