1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/-ext-/tracepoint/test_tracepoint.rb
ko1 e4c58251b7 * include/ruby/ruby.h, gc.c: add new internal event
RUBY_INTERNAL_EVENT_GC_END. This event invokes at the end of
  after_sweep().
  Time chart with lazy sweep is here:
  (1) Kick RUBY_INTERNAL_EVENT_GC_START
  (2) [gc_marks()]
  (3) [lazy_sweep()]
  (4) [... run Ruby program (mutator) with lazy_sweep() ...]
  (5) [after_sweep()]
  (6) Kick RUBY_INTERNAL_EVENT_GC_END
  (7) [... run Ruby program (mutator), and go to (1) ...]
* ext/-test-/tracepoint/tracepoint.c,
  test/-ext-/tracepoint/test_tracepoint.rb: modify a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-27 15:40:27 +00:00

45 lines
1.3 KiB
Ruby

require 'test/unit'
require '-test-/tracepoint'
class TestTracepointObj < Test::Unit::TestCase
def test_not_available_from_ruby
assert_raises ArgumentError do
TracePoint.trace(:obj_new){}
end
end
def test_tracks_objspace_events
result = Bug.tracepoint_track_objspace_events{
99
'abc'
v="foobar"
Object.new
nil
}
newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result
assert_equal 2, newobj_count
assert_equal 2, newobjs.size
assert_equal 'foobar', newobjs[0]
assert_equal Object, newobjs[1].class
stat1 = {}
stat2 = {}
GC.stat(stat1)
result = Bug.tracepoint_track_objspace_events{
1_000_000.times{''}
}
GC.stat(stat2)
newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result
assert_operator stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count
assert_operator 1_000_000, :<=, newobj_count
assert_operator stat2[:total_freed_object] - stat1[:total_freed_object], :>=, free_count
assert_operator stat2[:count] - stat1[:count], :==, gc_start_count
assert_operator gc_start_count, :>=, gc_end_count
assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_count
end
end