From c31129ffb8dba79be9754af96a464ea8dc123cf0 Mon Sep 17 00:00:00 2001 From: wanabe Date: Fri, 26 Mar 2010 14:55:00 +0000 Subject: [PATCH] * NEWS: add Thread#add_trace_func and Thread#set_trace_func. * test/ruby/test_settracefunc.rb (test_thread_trace): add test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++ NEWS | 5 +++ test/ruby/test_settracefunc.rb | 60 ++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8c1dbc0554..f8e45e571f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Mar 26 23:52:07 2010 wanabe + + * NEWS: add Thread#add_trace_func and Thread#set_trace_func. + Fri Mar 26 22:58:10 2010 Yusuke Endoh * ext/openssl/ossl_x509store.c (ossl_x509store_initialize): initialize diff --git a/NEWS b/NEWS index 805a928e74..43f481cc52 100644 --- a/NEWS +++ b/NEWS @@ -122,6 +122,11 @@ with all sufficient information, see the ChangeLog file. * extended methods: * string[regexp, name] is supported for named capture. + * Thread + * new methods: + * Thread#add_trace_func + * Thread#set_trace_func + * Time * extended feature: * time_t restriction is removed to represent before 1901 and after 2038. diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index f66b728146..f885cb0042 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -294,4 +294,64 @@ class TestSetTraceFunc < Test::Unit::TestCase set_trace_func proc {raise rescue nil} assert_equal(42, (raise rescue 42), '[ruby-core:24118]') end + + def test_thread_trace + events = {:set => [], :add => []} + prc = Proc.new { |event, file, lineno, mid, binding, klass| + events[:set] << [event, lineno, mid, klass, :set] + } + prc2 = Proc.new { |event, file, lineno, mid, binding, klass| + events[:add] << [event, lineno, mid, klass, :add] + } + + th = Thread.new do + th = Thread.current + eval <<-EOF.gsub(/^.*?: /, "") + 1: th.set_trace_func(prc) + 2: th.add_trace_func(prc2) + 3: class ThreadTraceInnerClass + 4: def foo + 5: x = 1 + 1 + 6: end + 7: end + 8: ThreadTraceInnerClass.new.foo + 9: th.set_trace_func(nil) + EOF + end + th.join + + [["c-return", 1, :set_trace_func, Thread, :set], + ["line", 2, __method__, self.class, :set], + ["c-call", 2, :add_trace_func, Thread, :set]].each do |e| + assert_equal(e, events[:set].shift) + end + + [["c-return", 2, :add_trace_func, Thread], + ["line", 3, __method__, self.class], + ["c-call", 3, :inherited, Class], + ["c-return", 3, :inherited, Class], + ["class", 3, nil, nil], + ["line", 4, nil, nil], + ["c-call", 4, :method_added, Module], + ["c-return", 4, :method_added, Module], + ["end", 7, nil, nil], + ["line", 8, __method__, self.class], + ["c-call", 8, :new, Class], + ["c-call", 8, :initialize, BasicObject], + ["c-return", 8, :initialize, BasicObject], + ["c-return", 8, :new, Class], + ["call", 4, :foo, ThreadTraceInnerClass], + ["line", 5, :foo, ThreadTraceInnerClass], + ["c-call", 5, :+, Fixnum], + ["c-return", 5, :+, Fixnum], + ["return", 6, :foo, ThreadTraceInnerClass], + ["line", 9, __method__, self.class], + ["c-call", 9, :set_trace_func, Thread]].each do |e| + [:set, :add].each do |type| + assert_equal(e + [type], events[type].shift) + end + end + assert_equal([], events[:set]) + assert_equal([], events[:add]) + end end