From e516e45640206fa3e7864938da74a7cb5ca31715 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 11 Mar 2011 02:12:37 +0000 Subject: support for Raindrops#size= and Raindrops#evaporate! 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 --- test/test_raindrops.rb | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'test') 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 -- cgit v1.2.3-24-ge0c7