mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
These tests use NM threads but NT is not freed for MN thread, causing it
to be reported as memory leaks in LSAN. For example:
#1 0x62ee7bc67e99 in calloc1 gc/default/default.c:1495:12
#2 0x62ee7bc7ba00 in rb_gc_impl_calloc gc/default/default.c:8216:5
#3 0x62ee7bc631d1 in ruby_xcalloc_body gc.c:5221:12
#4 0x62ee7bc5cdbc in ruby_xcalloc gc.c:5215:34
#5 0x62ee7bdea4c6 in native_thread_alloc thread_pthread.c:2187:35
#6 0x62ee7bdec31b in native_thread_check_and_create_shared thread_pthread_mn.c:429:39
#7 0x62ee7bdea484 in native_thread_create_shared thread_pthread_mn.c:531:12
#8 0x62ee7bdea1da in native_thread_create thread_pthread.c:2403:16
#9 0x62ee7bdde2eb in thread_create_core thread.c:884:11
#10 0x62ee7bde4466 in thread_initialize thread.c:992:16
55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
require 'envutil'
|
|
|
|
mn_supported_p = -> do
|
|
out, *_ = EnvUtil.invoke_ruby([{'RUBY_MN_THREADS' => '1'}, '-v'], '', true)
|
|
return /\+MN/ =~ out
|
|
end
|
|
|
|
if mn_supported_p.call
|
|
# test only on MN threads
|
|
else
|
|
return
|
|
end
|
|
|
|
class TestThreadLockNativeThread < Test::Unit::TestCase
|
|
def test_lock_native_thread
|
|
omit "LSAN reports memory leak because NT is not freed for MN thread" if Test::Sanitizers.lsan_enabled?
|
|
|
|
assert_separately([{'RUBY_MN_THREADS' => '1'}], <<-RUBY)
|
|
require '-test-/thread/lock_native_thread'
|
|
|
|
Thread.new{
|
|
assert_equal true, Thread.current.lock_native_thread
|
|
}.join
|
|
|
|
# main thread already has DNT
|
|
assert_equal false, Thread.current.lock_native_thread
|
|
RUBY
|
|
end
|
|
|
|
def test_lock_native_thread_tls
|
|
omit "LSAN reports memory leak because NT is not freed for MN thread" if Test::Sanitizers.lsan_enabled?
|
|
|
|
assert_separately([{'RUBY_MN_THREADS' => '1'}], <<-RUBY)
|
|
require '-test-/thread/lock_native_thread'
|
|
tn = 10
|
|
ln = 1_000
|
|
|
|
ts = tn.times.map{|i|
|
|
Thread.new(i){|i|
|
|
Thread.current.set_tls i
|
|
assert_equal true, Thread.current.lock_native_thread
|
|
|
|
ln.times{
|
|
assert_equal i, Thread.current.get_tls
|
|
Thread.pass
|
|
}
|
|
}
|
|
}
|
|
ts.each(&:join)
|
|
RUBY
|
|
end
|
|
end
|