Remove dependency on fiddle from test/ruby
Co-authored-by: "Nobuyoshi Nakada" <nobu@ruby-lang.org>
This commit is contained in:
parent
8ff5458c2e
commit
892849ac98
3
ext/-test-/thread/id/extconf.rb
Normal file
3
ext/-test-/thread/id/extconf.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
if have_func("gettid")
|
||||||
|
create_makefile("-test-/thread/id")
|
||||||
|
end
|
15
ext/-test-/thread/id/id.c
Normal file
15
ext/-test-/thread/id/id.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <ruby.h>
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
bug_gettid(VALUE self)
|
||||||
|
{
|
||||||
|
pid_t tid = gettid();
|
||||||
|
return PIDT2NUM(tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Init_id(void)
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_module_under(rb_define_module("Bug"), "ThreadID");
|
||||||
|
rb_define_module_function(klass, "gettid", bug_gettid, 0);
|
||||||
|
}
|
@ -3,7 +3,6 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require "rbconfig/sizeof"
|
require "rbconfig/sizeof"
|
||||||
require "timeout"
|
require "timeout"
|
||||||
require "fiddle"
|
|
||||||
|
|
||||||
class TestThread < Test::Unit::TestCase
|
class TestThread < Test::Unit::TestCase
|
||||||
class Thread < ::Thread
|
class Thread < ::Thread
|
||||||
@ -1446,13 +1445,16 @@ q.pop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_thread_native_thread_id_across_fork_on_linux
|
def test_thread_native_thread_id_across_fork_on_linux
|
||||||
rtld_default = Fiddle.dlopen(nil)
|
begin
|
||||||
omit "this test is only for Linux" unless rtld_default.sym_defined?('gettid')
|
require '-test-/thread/id'
|
||||||
|
rescue LoadError
|
||||||
gettid = Fiddle::Function.new(rtld_default['gettid'], [], Fiddle::TYPE_INT)
|
omit "this test is only for Linux"
|
||||||
|
else
|
||||||
|
extend Bug::ThreadID
|
||||||
|
end
|
||||||
|
|
||||||
parent_thread_id = Thread.main.native_thread_id
|
parent_thread_id = Thread.main.native_thread_id
|
||||||
real_parent_thread_id = gettid.call
|
real_parent_thread_id = gettid
|
||||||
|
|
||||||
assert_equal real_parent_thread_id, parent_thread_id
|
assert_equal real_parent_thread_id, parent_thread_id
|
||||||
|
|
||||||
@ -1464,7 +1466,7 @@ q.pop
|
|||||||
else
|
else
|
||||||
# child
|
# child
|
||||||
puts Thread.main.native_thread_id
|
puts Thread.main.native_thread_id
|
||||||
puts gettid.call
|
puts gettid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
child_thread_id = child_lines[0].chomp.to_i
|
child_thread_id = child_lines[0].chomp.to_i
|
||||||
|
Loading…
x
Reference in New Issue
Block a user