about summary refs log tree commit homepage
path: root/test/test_mwrap.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-08-10 06:49:43 +0000
committerEric Wong <e@80x24.org>2018-08-10 07:02:19 +0000
commit423f89a545ee90cdc428cae5aae7bc6bd18a484c (patch)
tree62cb1521c3f504c4ed931c10bac2b6f8e5c1c94a /test/test_mwrap.rb
parentd1eaf0347a3acd7328c1c1b99a346f153a42406d (diff)
downloadmwrap-423f89a545ee90cdc428cae5aae7bc6bd18a484c.tar.gz
free-ing and calling posix_memalign again can cause
fragmentation in glibc malloc (at least):

  https://sourceware.org/bugzilla/show_bug.cgi?id=14581

Add statistics to track lifetimes and deathtimes (time between
free and resurrection via posix_memalign).
Diffstat (limited to 'test/test_mwrap.rb')
-rw-r--r--test/test_mwrap.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb
index d112b4e..9c6141d 100644
--- a/test/test_mwrap.rb
+++ b/test/test_mwrap.rb
@@ -283,4 +283,33 @@ class TestMwrap < Test::Unit::TestCase
         abort 'freed more than allocated'
     end;
   end
+
+  def test_heap_page_body
+    assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}")
+    begin;
+      require 'mwrap'
+      require 'rubygems' # use up some memory
+      ap = GC.stat(:heap_allocated_pages)
+      h = {}
+      nr = 0
+      Mwrap::HeapPageBody.each do |addr, gen|
+        nr += 1
+        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'
+      10.times { (1..20000).to_a.map(&:to_s) }
+      3.times { GC.start }
+      Mwrap::HeapPageBody.stat(h)
+      Integer === h[:lifespan_max] or abort 'lifespan_max not recorded'
+      Integer === h[:lifespan_min] or abort 'lifespan_min not recorded'
+      Float === h[:lifespan_mean] or abort 'lifespan_mean not recorded'
+      3.times { GC.start }
+      10.times { (1..20000).to_a.map(&:to_s) }
+      Mwrap::HeapPageBody.stat(h)
+      h[:deathspan_min] <= h[:deathspan_max] or
+        abort 'wrong min/max deathtime'
+      Float === h[:deathspan_mean] or abort 'deathspan_mean not recorded'
+    end;
+  end
 end