[前][次][番号順一覧][スレッド一覧]

ruby-changes:31694

From: akr <ko1@a...>
Date: Fri, 22 Nov 2013 12:03:19 +0900 (JST)
Subject: [ruby-changes:31694] akr:r43773 (trunk): * test/ruby/test_settracefunc.rb: Ignore events from other threads.

akr	2013-11-22 12:03:11 +0900 (Fri, 22 Nov 2013)

  New Revision: 43773

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43773

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

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_settracefunc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43772)
+++ ChangeLog	(revision 43773)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov 22 12:02:58 2013  Tanaka Akira  <akr@f...>
+
+	* test/ruby/test_settracefunc.rb: Ignore events from other threads.
+
 Fri Nov 22 10:35:57 2013  Koichi Sasada  <ko1@a...>
 
 	* vm.c (ruby_vm_destruct): do not use ruby_xfree() after freeing
Index: test/ruby/test_settracefunc.rb
===================================================================
--- test/ruby/test_settracefunc.rb	(revision 43772)
+++ test/ruby/test_settracefunc.rb	(revision 43773)
@@ -8,11 +8,17 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L8
       :trace_instruction => true,
       :specialized_instruction => false
     }
+    @target_thread = Thread.current
   end
 
   def teardown
     set_trace_func(nil)
     RubyVM::InstructionSequence.compile_option = @original_compile_option
+    @target_thread = nil
+  end
+
+  def target_thread?
+    Thread.current == @target_thread
   end
 
   def test_c_call
@@ -437,7 +443,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L443
     trace = nil
     begin
     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'
     3: }
     4: 1.times{|;_local_var| _local_var = :inner
@@ -593,6 +599,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L599
   def test_tracepoint_object_id
     tps = []
     trace = TracePoint.trace(){|tp|
+      next if !target_thread?
       tps << tp
     }
     tap{}
@@ -609,6 +616,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L616
   def test_tracepoint_access_from_outside
     tp_store = nil
     trace = TracePoint.trace(){|tp|
+      next if !target_thread?
       tp_store = tp
     }
     tap{}
@@ -631,6 +639,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L639
   def test_tracepoint_enable
     ary = []
     trace = TracePoint.new(:call){|tp|
+      next if !target_thread?
       ary << tp.method_id
     }
     foo
@@ -654,6 +663,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L663
   def test_tracepoint_disable
     ary = []
     trace = TracePoint.trace(:call){|tp|
+      next if !target_thread?
       ary << tp.method_id
     }
     foo
@@ -694,6 +704,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L704
 
   def test_tracepoint_return_value
     trace = TracePoint.new(:call, :return){|tp|
+      next if !target_thread?
       next if tp.path != __FILE__
       case tp.event
       when :call
@@ -714,6 +725,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L725
 
   def test_tracepoint_raised_exception
     trace = TracePoint.new(:call, :return){|tp|
+      next if !target_thread?
       case tp.event
       when :call, :return
         assert_raise(RuntimeError) { tp.raised_exception }
@@ -739,6 +751,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L751
   def test_tracepoint_block
     events = []
     TracePoint.new(:call, :return, :c_call, :b_call, :c_return, :b_return){|tp|
+      next if !target_thread?
       events << [
         tp.event, tp.method_id, tp.defined_class, tp.self.class,
         /return/ =~ tp.event ? tp.return_value : nil
@@ -773,6 +786,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L786
     thread_self = nil
     created_thread = nil
     TracePoint.new(:thread_begin, :thread_end){|tp|
+      next if Thread.current != created_thread
       events << [Thread.current,
                  tp.event,
                  tp.lineno,  #=> 0
@@ -793,7 +807,10 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L807
 
   def test_tracepoint_inspect
     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)
     trace.enable{
       assert_equal("#<TracePoint:enabled>", trace.inspect)
@@ -818,7 +835,10 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L835
 
   def test_tracepoint_exception_at_line
     assert_raise(RuntimeError) do
-      TracePoint.new(:line) {raise}.enable {
+      TracePoint.new(:line) {
+        next if !target_thread?
+        raise
+      }.enable {
         1
       }
     end
@@ -861,6 +881,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L881
   def test_trace_point_at_return_when_exception
     bug_7624 = '[ruby-core:51128] [ruby-trunk - Bug #7624]'
     TracePoint.new{|tp|
+      next if !target_thread?
       if tp.event == :return &&
         tp.method_id == :m2_test_trace_point_at_return_when_exception
         raise FOO_ERROR
@@ -874,6 +895,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L895
     bug_7668 = '[Bug #7668]'
     ary = []
     trace = TracePoint.new{|tp|
+      next if !target_thread?
       ary << tp.event
       raise
     }
@@ -929,6 +951,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L951
     # TracePoint
     tp_b = nil
     TracePoint.new(:raise) do |tp|
+      next if !target_thread?
       tp_b = tp.binding
     end.enable do
       m1_for_test_trace_point_binding_in_ifunc(0)
@@ -957,6 +980,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L980
   def test_tracepoint_b_return_with_next
     n = 0
     TracePoint.new(:b_return){
+      next if !target_thread?
       n += 1
     }.enable{
       3.times{
@@ -970,6 +994,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L994
   def test_tracepoint_b_return_with_lambda
     n = 0
     TracePoint.new(:b_return){
+      next if !target_thread?
       n+=1
     }.enable{
       lambda{

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]