[前][次][番号順一覧][スレッド一覧]

ruby-changes:40847

From: ko1 <ko1@a...>
Date: Tue, 8 Dec 2015 04:01:39 +0900 (JST)
Subject: [ruby-changes:40847] ko1:r52926 (trunk): * test/lib/iseq_loader_checker.rb: add iseq dumper/loader checker.

ko1	2015-12-08 04:01:29 +0900 (Tue, 08 Dec 2015)

  New Revision: 52926

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52926

  Log:
    * test/lib/iseq_loader_checker.rb: add iseq dumper/loader checker.
      If you enable this checker (remove `#' in test/runner.rb),
      you can see comparison results between an original iseq disassembed
      result and dumped and loaded iseq disassembed result.
    
      There are several bugs around there, because of inexact stack depth
      calculation. Now, I leave these bugs because they are not critical
      and difficult to solve completely.
    
    * test/runner.rb: require test/lib/iseq_loader_checker.rb but
      disabled at default (commented out).

  Added files:
    trunk/test/lib/iseq_loader_checker.rb
  Modified files:
    trunk/ChangeLog
    trunk/test/runner.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52925)
+++ ChangeLog	(revision 52926)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  8 03:56:05 2015  Koichi Sasada  <ko1@a...>
+
+	* test/lib/iseq_loader_checker.rb: add iseq dumper/loader checker.
+	  If you enable this checker (remove `#' in test/runner.rb),
+	  you can see comparison results between an original iseq disassembed
+	  result and dumped and loaded iseq disassembed result.
+
+	  There are several bugs around there, because of inexact stack depth
+	  calculation. Now, I leave these bugs because they are not critical
+	  and difficult to solve completely.
+
+	* test/runner.rb: require test/lib/iseq_loader_checker.rb but
+	  disabled at default (commented out).
+
 Tue Dec  8 03:45:47 2015  Eric Wong  <e@8...>
 
 	* doc/extension.rdoc: warn about kwargs performance in C
Index: test/runner.rb
===================================================================
--- test/runner.rb	(revision 52925)
+++ test/runner.rb	(revision 52926)
@@ -22,6 +22,7 @@ ENV["GEM_SKIP"] = ENV["GEM_HOME"] = ENV[ https://github.com/ruby/ruby/blob/trunk/test/runner.rb#L22
 require_relative 'lib/profile_test_all' if ENV.has_key?('RUBY_TEST_ALL_PROFILE')
 require_relative 'lib/tracepointchecker'
 require_relative 'lib/zombie_hunter'
+# require_relative 'lib/iseq_loader_checker'
 
 if ENV['COVERAGE']
   %w[doclie simplecov-html simplecov].each do |f|
Index: test/lib/iseq_loader_checker.rb
===================================================================
--- test/lib/iseq_loader_checker.rb	(revision 0)
+++ test/lib/iseq_loader_checker.rb	(revision 52926)
@@ -0,0 +1,55 @@ https://github.com/ruby/ruby/blob/trunk/test/lib/iseq_loader_checker.rb#L1
+
+require '-test-/iseq_load/iseq_load'
+require 'tempfile'
+
+class RubyVM::InstructionSequence
+  def disasm_if_possible
+    begin
+      self.disasm
+    rescue Encoding::CompatibilityError, EncodingError, SecurityError
+      nil
+    end
+  end
+
+  def self.compare_dump_and_load i1, dumper, loader
+    dump = dumper.call(i1)
+    return i1 unless dump
+    i2 = loader.call(dump)
+
+    # compare disassembled result
+    d1 = i1.disasm_if_possible
+    d2 = i2.disasm_if_possible
+
+    if d1 != d2
+      p i1
+      return
+
+      STDERR.puts "expected:"
+      STDERR.puts d1
+      STDERR.puts "actual:"
+      STDERR.puts d2
+
+      t1 = Tempfile.new("expected"); t1.puts d1; t1.close
+      t2 = Tempfile.new("actual"); t2.puts d2; t2.close
+      system("diff -u #{t1.path} #{t2.path}") # use diff if available
+      exit(1)
+    end
+    i2
+  end
+
+  def self.translate i1
+    # check to_a/load_iseq
+    i2 = compare_dump_and_load(i1,
+                               proc{|iseq|
+                                 ary = iseq.to_a
+                                 ary[9] == :top ? ary : nil
+                               },
+                               proc{|ary|
+                                 RubyVM::InstructionSequence.iseq_load(ary)
+                               })
+    # return value
+    i1
+  end
+end
+
+#require_relative 'x'; exit(1)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]