From 4876dd3fb1715b4ea11051532ed3a3c2e6b0a628 Mon Sep 17 00:00:00 2001 From: tmm1 Date: Thu, 5 Dec 2013 10:30:38 +0000 Subject: 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 --- test/ruby/test_gc.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'test/ruby') 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 -- cgit v1.2.3