2013-05-26 20:21:02 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require '-test-/tracepoint'
|
|
|
|
|
|
|
|
class TestTracepointObj < Test::Unit::TestCase
|
|
|
|
def test_not_available_from_ruby
|
2013-10-09 04:41:13 -04:00
|
|
|
assert_raise ArgumentError do
|
2013-05-26 20:21:02 -04:00
|
|
|
TracePoint.trace(:obj_new){}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tracks_objspace_events
|
|
|
|
result = Bug.tracepoint_track_objspace_events{
|
|
|
|
99
|
|
|
|
'abc'
|
2013-10-14 15:14:27 -04:00
|
|
|
_="foobar"
|
2013-05-26 20:21:02 -04:00
|
|
|
Object.new
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
2013-05-27 11:40:27 -04:00
|
|
|
newobj_count, free_count, gc_start_count, gc_end_count, *newobjs = *result
|
2013-05-26 20:21:02 -04:00
|
|
|
assert_equal 2, newobj_count
|
|
|
|
assert_equal 2, newobjs.size
|
|
|
|
assert_equal 'foobar', newobjs[0]
|
|
|
|
assert_equal Object, newobjs[1].class
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_operator free_count, :>=, 0
|
|
|
|
assert_operator gc_start_count, :>=, gc_end_count
|
2013-10-09 04:39:28 -04:00
|
|
|
end
|
2013-05-26 20:21:02 -04:00
|
|
|
|
2013-10-09 04:39:28 -04:00
|
|
|
def test_tracks_objspace_count
|
2013-05-26 20:21:02 -04:00
|
|
|
stat1 = {}
|
|
|
|
stat2 = {}
|
2013-07-23 19:08:48 -04:00
|
|
|
GC.disable
|
2013-05-26 20:21:02 -04:00
|
|
|
GC.stat(stat1)
|
|
|
|
result = Bug.tracepoint_track_objspace_events{
|
2013-07-23 19:08:48 -04:00
|
|
|
GC.enable
|
2013-05-26 20:21:02 -04:00
|
|
|
1_000_000.times{''}
|
2013-07-23 19:08:48 -04:00
|
|
|
GC.disable
|
2013-05-26 20:21:02 -04:00
|
|
|
}
|
|
|
|
GC.stat(stat2)
|
2013-07-23 19:08:48 -04:00
|
|
|
GC.enable
|
2013-05-26 20:21:02 -04:00
|
|
|
|
2013-10-14 15:14:27 -04:00
|
|
|
newobj_count, free_count, gc_start_count, gc_end_count, *_newobjs = *result
|
2013-05-26 20:21:02 -04:00
|
|
|
|
|
|
|
assert_operator stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count
|
2013-05-27 11:40:27 -04:00
|
|
|
assert_operator 1_000_000, :<=, newobj_count
|
|
|
|
|
2013-11-24 15:06:02 -05:00
|
|
|
assert_operator stat2[:total_freed_object] + stat2[:heap_final_slot] - stat1[:total_freed_object], :>=, free_count
|
2013-05-26 20:21:02 -04:00
|
|
|
assert_operator stat2[:count] - stat1[:count], :==, gc_start_count
|
2013-05-27 11:40:27 -04:00
|
|
|
|
|
|
|
assert_operator gc_start_count, :>=, gc_end_count
|
|
|
|
assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_count
|
2013-05-26 20:21:02 -04:00
|
|
|
end
|
|
|
|
end
|