about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-11 02:12:37 +0000
committerEric Wong <normalperson@yhbt.net>2011-03-11 02:12:37 +0000
commite516e45640206fa3e7864938da74a7cb5ca31715 (patch)
tree199b0eb8786ff310c81c5eb82424f8b0b893ddb3 /test
parent61962b27a51031965cef70451d369b115868fb11 (diff)
downloadraindrops-e516e45640206fa3e7864938da74a7cb5ca31715.tar.gz
This allows limited resizing of the Raindrops memory
area since we always over-allocate due to the required
page aligment for mmap.

It would be nice if mremap() worked with MAP_SHARED,
but it does not and triggers a bus error when attempting
to access the new area.

ref: https://bugzilla.kernel.org/show_bug.cgi?id=8691
Diffstat (limited to 'test')
-rw-r--r--test/test_raindrops.rb40
1 files changed, 39 insertions, 1 deletions
diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb
index 6686796..a26d0e1 100644
--- a/test/test_raindrops.rb
+++ b/test/test_raindrops.rb
@@ -16,9 +16,15 @@ class TestRaindrops < Test::Unit::TestCase
     puts "Raindrops::SIZE = #{Raindrops::SIZE}"
   end
 
-  def test_size
+  def test_page_size
+    assert_kind_of Integer, Raindrops::PAGE_SIZE
+    assert Raindrops::PAGE_SIZE > Raindrops::SIZE
+  end
+
+  def test_size_and_capa
     rd = Raindrops.new(4)
     assert_equal 4, rd.size
+    assert rd.capa >= rd.size
   end
 
   def test_ary
@@ -104,4 +110,36 @@ class TestRaindrops < Test::Unit::TestCase
     assert_equal expect, rd.to_ary
   end
 
+  def test_resize
+    rd = Raindrops.new(4)
+    assert_equal 4, rd.size
+    assert_equal rd.capa, rd.size = rd.capa
+    assert_equal rd.capa, rd.to_ary.size
+    assert_equal 0, rd[rd.capa - 1]
+    assert_equal 1, rd.incr(rd.capa - 1)
+    assert_raises(ArgumentError) { rd[rd.capa] }
+  end
+
+  def test_resize_mremap
+    rd = Raindrops.new(4)
+    assert_equal 4, rd.size
+    old_capa = rd.capa
+    rd.size = rd.capa + 1
+    assert_equal old_capa * 2, rd.capa
+
+    # mremap() is currently broken with MAP_SHARED
+    # https://bugzilla.kernel.org/show_bug.cgi?id=8691
+    assert_equal 0, rd[old_capa]
+    assert_equal rd.capa, rd.to_ary.size
+    assert_equal 0, rd[rd.capa - 1]
+    assert_equal 1, rd.incr(rd.capa - 1)
+    assert_raises(ArgumentError) { rd[rd.capa] }
+    rescue RangeError
+  end # if RUBY_PLATFORM =~ /linux/
+
+  def test_evaporate
+    rd = Raindrops.new 1
+    assert_nil rd.evaporate!
+    assert_raises(StandardError) { rd.evaporate! }
+  end
 end