summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-30 08:17:30 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-30 08:17:30 +0000
commit1450e0b5ac0a49aa1f0d1db521b293b18f6fa99c (patch)
treee2760d70069ea827fa62db64d795e1a1c47a9bba /test/objspace
parent6a1a08c945b92b3755bf94de55be4f5678d0744c (diff)
* ext/objspace/object_tracing.c: add new 3 methods to control tracing.
* ObjectSpace::trace_object_allocations_start * ObjectSpace::trace_object_allocations_stop * ObjectSpace::trace_object_allocations_clear And some refactoring. * test/objspace/test_objspace.rb: add a test for new methods. * NEWS: add a description for new methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index c956705..133b1e9 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -109,7 +109,7 @@ class TestObjSpace < Test::Unit::TestCase
eom
end
- def test_traceobject
+ def test_trace_object_allocations
o0 = Object.new
ObjectSpace.trace_object_allocations{
o1 = Object.new; line1 = __LINE__; c1 = GC.count
@@ -139,4 +139,37 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal(__method__, ObjectSpace.allocation_method_id(o3))
}
end
+
+ def test_trace_object_allocations_start_stop_clear
+ begin
+ ObjectSpace.trace_object_allocations_start
+ begin
+ ObjectSpace.trace_object_allocations_start
+ begin
+ ObjectSpace.trace_object_allocations_start
+ obj0 = Object.new
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ obj1 = Object.new
+ end
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ obj2 = Object.new
+ end
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ obj3 = Object.new
+ end
+
+ assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj0))
+ assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj1))
+ assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(obj2))
+ assert_equal(nil , ObjectSpace.allocation_sourcefile(obj3)) # after tracing
+
+ ObjectSpace.trace_object_allocations_clear
+ assert_equal(nil, ObjectSpace.allocation_sourcefile(obj0))
+ assert_equal(nil, ObjectSpace.allocation_sourcefile(obj1))
+ assert_equal(nil, ObjectSpace.allocation_sourcefile(obj2))
+ assert_equal(nil, ObjectSpace.allocation_sourcefile(obj3))
+ end
end