Skip to content

Commit

Permalink
* NEWS: add Thread#add_trace_func and Thread#set_trace_func.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wanabe committed Mar 26, 2010
1 parent 2b0156b commit c31129f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Mar 26 23:52:07 2010 wanabe <s.wanabe@gmail.com>

* NEWS: add Thread#add_trace_func and Thread#set_trace_func.

Fri Mar 26 22:58:10 2010 Yusuke Endoh <mame@tsg.ne.jp>

* ext/openssl/ossl_x509store.c (ossl_x509store_initialize): initialize
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 60 additions & 0 deletions test/ruby/test_settracefunc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,64 @@ def test_raise_in_trace
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

0 comments on commit c31129f

Please sign in to comment.