2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
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
|
2019-06-29 20:52:31 -04:00
|
|
|
result = EnvUtil.suppress_warning {eval(<<-EOS, nil, __FILE__, __LINE__+1)}
|
|
|
|
Bug.tracepoint_track_objspace_events {
|
2013-05-26 20:21:02 -04:00
|
|
|
99
|
|
|
|
'abc'
|
2013-10-14 15:14:27 -04:00
|
|
|
_="foobar"
|
2013-05-26 20:21:02 -04:00
|
|
|
nil
|
|
|
|
}
|
2019-06-29 20:52:31 -04:00
|
|
|
EOS
|
2013-05-26 20:21:02 -04:00
|
|
|
|
2013-12-04 23:26:04 -05:00
|
|
|
newobj_count, free_count, gc_start_count, gc_end_mark_count, gc_end_sweep_count, *newobjs = *result
|
2020-01-08 02:14:01 -05:00
|
|
|
assert_equal 1, newobj_count
|
|
|
|
assert_equal 1, newobjs.size
|
2013-05-26 20:21:02 -04:00
|
|
|
assert_equal 'foobar', newobjs[0]
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_operator free_count, :>=, 0
|
2013-12-04 23:26:04 -05:00
|
|
|
assert_operator gc_start_count, :==, gc_end_mark_count
|
|
|
|
assert_operator gc_start_count, :>=, gc_end_sweep_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
|
|
|
|
2019-06-28 04:08:21 -04:00
|
|
|
newobj_count, free_count, gc_start_count, gc_end_mark_count, gc_end_sweep_count, = *result
|
2013-05-26 20:21:02 -04:00
|
|
|
|
2014-09-09 07:22:23 -04:00
|
|
|
assert_operator stat2[:total_allocated_objects] - stat1[:total_allocated_objects], :>=, newobj_count
|
2013-05-27 11:40:27 -04:00
|
|
|
assert_operator 1_000_000, :<=, newobj_count
|
|
|
|
|
2014-09-09 07:22:23 -04:00
|
|
|
assert_operator stat2[:total_freed_objects] + stat2[:heap_final_slots] - stat1[:total_freed_objects], :>=, 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
|
|
|
|
2013-12-04 23:26:04 -05:00
|
|
|
assert_operator gc_start_count, :==, gc_end_mark_count
|
|
|
|
assert_operator gc_start_count, :>=, gc_end_sweep_count
|
|
|
|
assert_operator stat2[:count] - stat1[:count] - 1, :<=, gc_end_sweep_count
|
2013-05-26 20:21:02 -04:00
|
|
|
end
|
2013-11-26 03:41:44 -05:00
|
|
|
|
|
|
|
def test_tracepoint_specify_normal_and_internal_events
|
|
|
|
assert_raise(TypeError){ Bug.tracepoint_specify_normal_and_internal_events }
|
|
|
|
end
|
2013-12-05 04:24:02 -05:00
|
|
|
|
|
|
|
def test_after_gc_start_hook_with_GC_stress
|
|
|
|
bug8492 = '[ruby-dev:47400] [Bug #8492]: infinite after_gc_start_hook reentrance'
|
|
|
|
assert_nothing_raised(Timeout::Error, bug8492) do
|
|
|
|
assert_in_out_err(%w[-r-test-/tracepoint], <<-'end;', /\A[1-9]/, timeout: 2)
|
|
|
|
stress, GC.stress = GC.stress, false
|
|
|
|
count = 0
|
|
|
|
Bug.after_gc_start_hook = proc {count += 1}
|
|
|
|
begin
|
|
|
|
GC.stress = true
|
|
|
|
3.times {Object.new}
|
|
|
|
ensure
|
|
|
|
GC.stress = stress
|
|
|
|
Bug.after_gc_start_hook = nil
|
|
|
|
end
|
|
|
|
puts count
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-11 10:37:14 -04:00
|
|
|
def test_teardown_with_active_GC_end_hook
|
|
|
|
assert_separately([], 'require("-test-/tracepoint"); Bug.after_gc_exit_hook = proc {}')
|
|
|
|
end
|
|
|
|
|
2013-05-26 20:21:02 -04:00
|
|
|
end
|