aboutsummaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 19:01:29 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-07 19:01:29 +0000
commit7476be4defe09d951bdb28b2925be5b461baed5d (patch)
tree01eb15a2aec416b3bb067fbb0b5eaf7748c8d118 /test/lib
parentb401937c627f2aa15c5eb7d6810fd0c049968ecc (diff)
downloadruby-7476be4defe09d951bdb28b2925be5b461baed5d.tar.gz
* 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). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/iseq_loader_checker.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/lib/iseq_loader_checker.rb b/test/lib/iseq_loader_checker.rb
new file mode 100644
index 0000000000..0c372ca638
--- /dev/null
+++ b/test/lib/iseq_loader_checker.rb
@@ -0,0 +1,55 @@
+
+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)