ruby-changes:31612
From: nobu <ko1@a...>
Date: Sat, 16 Nov 2013 07:14:14 +0900 (JST)
Subject: [ruby-changes:31612] nobu:r43691 (trunk): envutil.rb: crash report on Mac OS X
nobu 2013-11-16 07:14:09 +0900 (Sat, 16 Nov 2013) New Revision: 43691 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43691 Log: envutil.rb: crash report on Mac OS X * test/ruby/envutil.rb (EnvUtil.diagnostic_reports): find crash report on Mac OS X. * test/ruby/envutil.rb (Test::Unit::Assertions::FailDesc): include crash report on Mac OS X. * test/ruby/envutil.rb (Test::Unit::Assertions#assert_in_out_err): remove crash reports if exist. * test/ruby/test_process.rb (TestProcess#test_status_kill): ditto. Modified files: trunk/test/ruby/envutil.rb trunk/test/ruby/test_process.rb Index: test/ruby/test_process.rb =================================================================== --- test/ruby/test_process.rb (revision 43690) +++ test/ruby/test_process.rb (revision 43691) @@ -1190,6 +1190,7 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1190 pid = spawn(RUBY, "foo") Thread.new { sleep 1; Process.kill(:SIGQUIT, pid) } Process.wait(pid) + t = Time.now s = $? assert_equal([false, true, false], [s.exited?, s.signaled?, s.stopped?], @@ -1201,6 +1202,7 @@ class TestProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1202 s.inspect]) assert_equal(false, s.exited?) assert_equal(nil, s.success?) + EnvUtil.diagnostic_reports("QUIT", RUBY, pid, t) end end Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 43690) +++ test/ruby/envutil.rb (revision 43691) @@ -155,6 +155,34 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L155 $VERBOSE = verbose end module_function :with_default_internal + + if /darwin/ =~ RUBY_PLATFORM + DIAGNOSTIC_REPORTS_PATH = File.expand_path("~/Library/Logs/DiagnosticReports") + DIAGNOSTIC_REPORTS_TIMEFORMAT = '%Y-%m-%d-%H%M%S' + def self.diagnostic_reports(signame, cmd, pid, now) + return unless %w[ABRT QUIT SEGV ILL].include?(signame) + cmd = File.basename(cmd) + path = DIAGNOSTIC_REPORTS_PATH + timeformat = DIAGNOSTIC_REPORTS_TIMEFORMAT + pat = "#{path}/#{cmd}_#{now.strftime(timeformat)}[-_]*.crash" + first = true + 3.times do + first ? (first = false) : sleep(1) + Dir.glob(pat) do |name| + log = File.read(name) rescue next + if /\AProcess:\s+#{cmd} \[#{pid}\]$/ =~ log + File.unlink(name) + File.unlink("#{path}/.#{File.basename(name)}.plist") + return log + end + end + end + nil + end + else + def self.diagnostic_reports(signame, cmd, pid, now) + end + end end module Test @@ -221,10 +249,12 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L249 FailDesc = proc do |status, message = "", out = ""| pid = status.pid + now = Time.now faildesc = proc do signo = status.termsig signame = Signal.signame(signo) sigdesc = "signal #{signo}" + log = EnvUtil.diagnostic_reports(signame, EnvUtil.rubybin, pid, now) if signame sigdesc = "SIG#{signame} (#{sigdesc})" end @@ -240,6 +270,9 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L270 full_message << "\n#{out.gsub(/^/, '| ')}" full_message << "\n" if /\n\z/ !~ full_message end + if log + full_message << "\n#{log.gsub(/^/, '| ')}" + end full_message end faildesc @@ -247,6 +280,9 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L280 def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, **opt) stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, **opt) + if signo = status.termsig + EnvUtil.diagnostic_reports(Signal.signame(signo), EnvUtil.rubybin, status.pid, Time.now) + end if block_given? raise "test_stdout ignored, use block only or without block" if test_stdout != [] raise "test_stderr ignored, use block only or without block" if test_stderr != [] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/