* test/ruby/test_settracefunc.rb: Ignore events from other threads.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-11-22 03:03:11 +00:00
parent 2cf7281c44
commit a89132ca7f
2 changed files with 32 additions and 3 deletions

View File

@ -1,3 +1,7 @@
Fri Nov 22 12:02:58 2013 Tanaka Akira <akr@fsij.org>
* test/ruby/test_settracefunc.rb: Ignore events from other threads.
Fri Nov 22 10:35:57 2013 Koichi Sasada <ko1@atdot.net> Fri Nov 22 10:35:57 2013 Koichi Sasada <ko1@atdot.net>
* vm.c (ruby_vm_destruct): do not use ruby_xfree() after freeing * vm.c (ruby_vm_destruct): do not use ruby_xfree() after freeing

View File

@ -8,11 +8,17 @@ class TestSetTraceFunc < Test::Unit::TestCase
:trace_instruction => true, :trace_instruction => true,
:specialized_instruction => false :specialized_instruction => false
} }
@target_thread = Thread.current
end end
def teardown def teardown
set_trace_func(nil) set_trace_func(nil)
RubyVM::InstructionSequence.compile_option = @original_compile_option RubyVM::InstructionSequence.compile_option = @original_compile_option
@target_thread = nil
end
def target_thread?
Thread.current == @target_thread
end end
def test_c_call def test_c_call
@ -437,7 +443,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
trace = nil trace = nil
begin begin
eval <<-EOF.gsub(/^.*?: /, ""), nil, 'xyzzy' eval <<-EOF.gsub(/^.*?: /, ""), nil, 'xyzzy'
1: trace = TracePoint.trace(*trace_events){|tp| 1: trace = TracePoint.trace(*trace_events){|tp| next if !target_thread?
2: events << [tp.event, tp.lineno, tp.path, _defined_class.(tp), tp.method_id, tp.self, tp.binding.eval("_local_var"), _get_data.(tp)] if tp.path == 'xyzzy' 2: events << [tp.event, tp.lineno, tp.path, _defined_class.(tp), tp.method_id, tp.self, tp.binding.eval("_local_var"), _get_data.(tp)] if tp.path == 'xyzzy'
3: } 3: }
4: 1.times{|;_local_var| _local_var = :inner 4: 1.times{|;_local_var| _local_var = :inner
@ -593,6 +599,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_object_id def test_tracepoint_object_id
tps = [] tps = []
trace = TracePoint.trace(){|tp| trace = TracePoint.trace(){|tp|
next if !target_thread?
tps << tp tps << tp
} }
tap{} tap{}
@ -609,6 +616,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_access_from_outside def test_tracepoint_access_from_outside
tp_store = nil tp_store = nil
trace = TracePoint.trace(){|tp| trace = TracePoint.trace(){|tp|
next if !target_thread?
tp_store = tp tp_store = tp
} }
tap{} tap{}
@ -631,6 +639,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_enable def test_tracepoint_enable
ary = [] ary = []
trace = TracePoint.new(:call){|tp| trace = TracePoint.new(:call){|tp|
next if !target_thread?
ary << tp.method_id ary << tp.method_id
} }
foo foo
@ -654,6 +663,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_disable def test_tracepoint_disable
ary = [] ary = []
trace = TracePoint.trace(:call){|tp| trace = TracePoint.trace(:call){|tp|
next if !target_thread?
ary << tp.method_id ary << tp.method_id
} }
foo foo
@ -694,6 +704,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_return_value def test_tracepoint_return_value
trace = TracePoint.new(:call, :return){|tp| trace = TracePoint.new(:call, :return){|tp|
next if !target_thread?
next if tp.path != __FILE__ next if tp.path != __FILE__
case tp.event case tp.event
when :call when :call
@ -714,6 +725,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_raised_exception def test_tracepoint_raised_exception
trace = TracePoint.new(:call, :return){|tp| trace = TracePoint.new(:call, :return){|tp|
next if !target_thread?
case tp.event case tp.event
when :call, :return when :call, :return
assert_raise(RuntimeError) { tp.raised_exception } assert_raise(RuntimeError) { tp.raised_exception }
@ -739,6 +751,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_block def test_tracepoint_block
events = [] events = []
TracePoint.new(:call, :return, :c_call, :b_call, :c_return, :b_return){|tp| TracePoint.new(:call, :return, :c_call, :b_call, :c_return, :b_return){|tp|
next if !target_thread?
events << [ events << [
tp.event, tp.method_id, tp.defined_class, tp.self.class, tp.event, tp.method_id, tp.defined_class, tp.self.class,
/return/ =~ tp.event ? tp.return_value : nil /return/ =~ tp.event ? tp.return_value : nil
@ -773,6 +786,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
thread_self = nil thread_self = nil
created_thread = nil created_thread = nil
TracePoint.new(:thread_begin, :thread_end){|tp| TracePoint.new(:thread_begin, :thread_end){|tp|
next if Thread.current != created_thread
events << [Thread.current, events << [Thread.current,
tp.event, tp.event,
tp.lineno, #=> 0 tp.lineno, #=> 0
@ -793,7 +807,10 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_inspect def test_tracepoint_inspect
events = [] events = []
trace = TracePoint.new{|tp| events << [tp.event, tp.inspect]} trace = TracePoint.new{|tp|
next if !target_thread?
events << [tp.event, tp.inspect]
}
assert_equal("#<TracePoint:disabled>", trace.inspect) assert_equal("#<TracePoint:disabled>", trace.inspect)
trace.enable{ trace.enable{
assert_equal("#<TracePoint:enabled>", trace.inspect) assert_equal("#<TracePoint:enabled>", trace.inspect)
@ -818,7 +835,10 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_exception_at_line def test_tracepoint_exception_at_line
assert_raise(RuntimeError) do assert_raise(RuntimeError) do
TracePoint.new(:line) {raise}.enable { TracePoint.new(:line) {
next if !target_thread?
raise
}.enable {
1 1
} }
end end
@ -861,6 +881,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_trace_point_at_return_when_exception def test_trace_point_at_return_when_exception
bug_7624 = '[ruby-core:51128] [ruby-trunk - Bug #7624]' bug_7624 = '[ruby-core:51128] [ruby-trunk - Bug #7624]'
TracePoint.new{|tp| TracePoint.new{|tp|
next if !target_thread?
if tp.event == :return && if tp.event == :return &&
tp.method_id == :m2_test_trace_point_at_return_when_exception tp.method_id == :m2_test_trace_point_at_return_when_exception
raise FOO_ERROR raise FOO_ERROR
@ -874,6 +895,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
bug_7668 = '[Bug #7668]' bug_7668 = '[Bug #7668]'
ary = [] ary = []
trace = TracePoint.new{|tp| trace = TracePoint.new{|tp|
next if !target_thread?
ary << tp.event ary << tp.event
raise raise
} }
@ -929,6 +951,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
# TracePoint # TracePoint
tp_b = nil tp_b = nil
TracePoint.new(:raise) do |tp| TracePoint.new(:raise) do |tp|
next if !target_thread?
tp_b = tp.binding tp_b = tp.binding
end.enable do end.enable do
m1_for_test_trace_point_binding_in_ifunc(0) m1_for_test_trace_point_binding_in_ifunc(0)
@ -957,6 +980,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_b_return_with_next def test_tracepoint_b_return_with_next
n = 0 n = 0
TracePoint.new(:b_return){ TracePoint.new(:b_return){
next if !target_thread?
n += 1 n += 1
}.enable{ }.enable{
3.times{ 3.times{
@ -970,6 +994,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_tracepoint_b_return_with_lambda def test_tracepoint_b_return_with_lambda
n = 0 n = 0
TracePoint.new(:b_return){ TracePoint.new(:b_return){
next if !target_thread?
n+=1 n+=1
}.enable{ }.enable{
lambda{ lambda{