about summary refs log tree commit homepage
path: root/test/test_mwrap.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-20 21:35:22 +0000
committerEric Wong <mwrap-public@80x24.org>2022-08-22 17:11:39 +0000
commit7ec73b9ccdeaed30e813884f7765281be422bc21 (patch)
tree537eff656a6d8b0cc3bcb1dc6ec1582891270849 /test/test_mwrap.rb
parenta90e237d93256ded3088c83520683fc5835da72d (diff)
downloadmwrap-7ec73b9ccdeaed30e813884f7765281be422bc21.tar.gz
HEAP_PAGE_SIZE no longer estimates malloc overhead in Ruby 3.0.x,
but we can now rely on the GC::INTERNAL_CONSTANTS hash to access
the true value.

We also need to account for Ractors in 3.0+, and thus we need to
rely on thread-specific `ruby_current_ec' instead of process-wide
`ruby_current_execution_context_ptr' (which no longer exists in
3.0+).

Finally, the VM seems prone to making some small immortal
allocations in a few places we were not expecting in 2.7 and
earlier.  Account for that and loosen some exact checks to
account for it.

Tested on Ruby 3.0.3 and 3.0.4
Diffstat (limited to 'test/test_mwrap.rb')
-rw-r--r--test/test_mwrap.rb27
1 files changed, 16 insertions, 11 deletions
diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb
index 48fba23..fadaef6 100644
--- a/test/test_mwrap.rb
+++ b/test/test_mwrap.rb
@@ -29,7 +29,8 @@ class TestMwrap < Test::Unit::TestCase
       tmp.rewind
       lines = tmp.readlines
       line_1 = lines.grep(/\s-e:1\b/)[0].strip
-      assert_equal '10001', line_1.split(/\s+/)[0]
+      bytes = line_1.split(/\s+/)[0].to_i
+      assert_operator bytes, :>=, 10001
     end
   end
 
@@ -42,7 +43,7 @@ class TestMwrap < Test::Unit::TestCase
       res = system(env, *cmd, { 5 => tmp })
       assert res, $?.inspect
       tmp.rewind
-      assert_match(/\b10001\s+1\s+-e:1$/, tmp.read)
+      assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read)
 
       env['MWRAP'] = 'dump_fd:1,dump_min:10000'
       tmp.rewind
@@ -50,14 +51,14 @@ class TestMwrap < Test::Unit::TestCase
       res = system(env, *cmd, { 1 => tmp })
       assert res, $?.inspect
       tmp.rewind
-      assert_match(/\b10001\s+1\s+-e:1$/, tmp.read)
+      assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read)
 
       tmp.rewind
       tmp.truncate(0)
       env['MWRAP'] = "dump_path:#{tmp.path},dump_min:10000"
       res = system(env, *cmd)
       assert res, $?.inspect
-      assert_match(/\b10001\s+1\s+-e:1$/, tmp.read)
+      assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read)
 
       tmp.rewind
       tmp.truncate(0)
@@ -98,7 +99,7 @@ class TestMwrap < Test::Unit::TestCase
       tmp.rewind
       buf = tmp.read
       assert_not_match(/\s+-e:1$/, buf)
-      assert_match(/\b20001\s+1\s+-e:3$/, buf)
+      assert_match(/\b2\d{4}\s+[0-9]\d*\s+-e:3$/, buf)
     end
   end
 
@@ -176,8 +177,8 @@ class TestMwrap < Test::Unit::TestCase
       -e GC.disable
       -e keep=("0"*10000)
       -e loc=Mwrap["-e:3"]
-      -e loc.each{|size,gen|p([size,gen,count])}
-    )
+      -e
+    ) + [ 'loc.each{|size,gen|p([size,gen,count]) if size > 10000}' ]
     buf = IO.popen(@@env, cmd, &:read)
     assert_predicate $?, :success?
     assert_match(/\A\[\s*\d+,\s*\d+,\s*\d+\]\s*\z/s, buf)
@@ -230,7 +231,8 @@ class TestMwrap < Test::Unit::TestCase
       loc.name == k or abort 'SourceLocation#name broken'
       loc.total >= 10000 or abort 'SourceLocation#total broken'
       loc.frees == 0 or abort 'SourceLocation#frees broken'
-      loc.allocations == 1 or abort 'SourceLocation#allocations broken'
+      loc.allocations >= 1 or
+        abort "SourceLocation#allocations broken: #{loc.allocations}"
       seen = false
       loc.each do |*x| seen = x end
       seen[1] == loc.total or 'SourceLocation#each broken'
@@ -240,7 +242,9 @@ class TestMwrap < Test::Unit::TestCase
       freed = false
       until freed
         freed = true
-        loc.each do freed = false end
+        loc.each do |size, gen|
+          freed = false if size >= 10000
+        end
       end
       loc.frees == 1 or abort 'SourceLocation#frees broken (after free)'
       Float === loc.mean_lifespan or abort 'mean_lifespan broken'
@@ -264,8 +268,9 @@ class TestMwrap < Test::Unit::TestCase
     assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}")
     begin;
       require 'mwrap'
-      before = __LINE__
+      before = nil
       res = Mwrap.quiet do |depth|
+        before = __LINE__
         depth == 1 or abort 'depth is not 1'
         ('a' * 10000).clear
         Mwrap.quiet { |d| d == 2 or abort 'depth is not 2' }
@@ -304,7 +309,7 @@ class TestMwrap < Test::Unit::TestCase
         gen <= GC.count && gen >= 0 or abort "bad generation: #{gen}"
         (0 == (addr & 16383)) or abort "addr not aligned: #{'%x' % addr}"
       end
-      nr == ap or abort 'HeapPageBody.each missed page'
+      nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}"
       10.times { (1..20000).to_a.map(&:to_s) }
       3.times { GC.start }
       Mwrap::HeapPageBody.stat(h)