summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 10:30:38 +0000
committertmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-05 10:30:38 +0000
commit4876dd3fb1715b4ea11051532ed3a3c2e6b0a628 (patch)
tree6efa76e4c572558ac38c237181e25e0fa2d766b8 /test
parent6692436b9fe206c130fbfa3fa7b41e18c1048f4a (diff)
gc.c: add GC.latest_gc_info()
* gc.c (struct rb_objspace): rename internal last_collection_flags to latest_gc_info * gc.c (gc_latest_collection_info): add GC.latest_gc_info() with similar behavior to GC.stat() * gc.c (rb_gc_latest_gc_info): new c-api for above * gc.c (gc_stat_internal): remove :last_collection_flags from GC.stat * gc.c (gc_profile_decode_flags): remove GC::Profiler.decode_flags * include/ruby/intern.h (rb_gc_latest_gc_info): export new c-api * test/ruby/test_gc.rb (class TestGc): test for new behavior * NEWS: note about new api * gc.c (gc_stat_internal): raise TypeError on wrong type * gc.c (gc_stat): fix error message git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_gc.rb26
1 files changed, 15 insertions, 11 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index d43f8b8693..8c1f1b63bb 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -85,27 +85,31 @@ class TestGc < Test::Unit::TestCase
assert_raise(ArgumentError){ GC.stat(:invalid) }
end
- def test_gc_reason
+ def test_latest_gc_info
GC.start
GC.stat[:heap_free_slot].times{ "a" + "b" }
- assert_equal({:gc_by => :newobj},
- GC::Profiler.decode_flags(GC.stat[:last_collection_flags]))
- end
+ assert_equal :newobj, GC.latest_gc_info[:gc_by]
- def test_gc_reason_method
GC.start
- assert_equal({:major_by=>:nofree, :gc_by=>:method, :immediate_sweep=>true},
- GC::Profiler.decode_flags(GC.stat[:last_collection_flags]))
- end
+ assert_equal :nofree, GC.latest_gc_info[:major_by]
+ assert_equal :method, GC.latest_gc_info[:gc_by]
+ assert_equal true, GC.latest_gc_info[:immediate_sweep]
- def test_gc_reason_stress
GC.stress = true
- assert_equal({:major_by=>:stress, :gc_by=>:malloc, :immediate_sweep=>true},
- GC::Profiler.decode_flags(GC.stat[:last_collection_flags]))
+ assert_equal :stress, GC.latest_gc_info[:major_by]
ensure
GC.stress = false
end
+ def test_latest_gc_info_argument
+ info = {}
+ GC.latest_gc_info(info)
+
+ assert_not_empty info
+ assert_equal info[:gc_by], GC.latest_gc_info(:gc_by)
+ assert_raises(ArgumentError){ GC.latest_gc_info(:invalid) }
+ end
+
def test_singleton_method
assert_in_out_err(%w[--disable-gems], <<-EOS, [], [], "[ruby-dev:42832]")
GC.stress = true