summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2023-04-20 10:26:48 +0200
committerLars Kanis <lars@greiz-reinsdorf.de>2023-04-20 13:12:26 +0200
commit80726b2217eb43a094101377c4273b7b2fdf4833 (patch)
tree67d4b9aa13be44336067ca8a62370aa6fed64462
parent88fa99adc880b2ac82d0e963c065c7add65e2137 (diff)
downloadffi-80726b2217eb43a094101377c4273b7b2fdf4833.tar.gz
Add a spec file for FFI::DynamicLibrary
.. and test Ractor compatibility there.
-rw-r--r--spec/ffi/dynamic_library_spec.rb56
-rw-r--r--spec/ffi/fixtures/compile.rb2
-rw-r--r--spec/ffi/library_spec.rb17
3 files changed, 57 insertions, 18 deletions
diff --git a/spec/ffi/dynamic_library_spec.rb b/spec/ffi/dynamic_library_spec.rb
new file mode 100644
index 0000000..a6ea2a9
--- /dev/null
+++ b/spec/ffi/dynamic_library_spec.rb
@@ -0,0 +1,56 @@
+#
+# This file is part of ruby-ffi.
+# For licensing, see LICENSE.SPECS
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
+
+describe FFI::DynamicLibrary do
+ it "should be shareable for Ractor", :ractor do
+ libtest = FFI::DynamicLibrary.open(TestLibrary::PATH,
+ FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
+ Ractor.make_shareable(libtest)
+
+ res = Ractor.new(libtest) do |libtest2|
+ libtest2.find_symbol("testClosureVrV").address
+ end.take
+
+ expect( res ).to be > 0
+ end
+
+ it "load a library in a Ractor", :ractor do
+ res = Ractor.new do
+ libtest = FFI::DynamicLibrary.open(TestLibrary::PATH,
+ FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
+ libtest.find_symbol("testClosureVrV")
+ end.take
+
+ expect(res.address).to be > 0
+ end
+
+ it "has a memsize function", skip: RUBY_ENGINE != "ruby" do
+ base_size = ObjectSpace.memsize_of(Object.new)
+
+ libtest = FFI::DynamicLibrary.open(TestLibrary::PATH,
+ FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL)
+ size = ObjectSpace.memsize_of(libtest)
+ expect(size).to be > base_size
+ end
+
+ describe Symbol do
+ before do
+ @libtest = FFI::DynamicLibrary.open(
+ TestLibrary::PATH,
+ FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL,
+ )
+ end
+
+ it "has a memsize function", skip: RUBY_ENGINE != "ruby" do
+ base_size = ObjectSpace.memsize_of(Object.new)
+
+ symbol = @libtest.find_symbol("gvar_gstruct_set")
+ size = ObjectSpace.memsize_of(symbol)
+ expect(size).to be > base_size
+ end
+ end
+end
diff --git a/spec/ffi/fixtures/compile.rb b/spec/ffi/fixtures/compile.rb
index 58ee561..2be97cb 100644
--- a/spec/ffi/fixtures/compile.rb
+++ b/spec/ffi/fixtures/compile.rb
@@ -69,5 +69,5 @@ module TestLibrary
lib
end
- PATH = compile_library(".", "libtest.#{FFI::Platform::LIBSUFFIX}")
+ PATH = FFI.make_shareable(compile_library(".", "libtest.#{FFI::Platform::LIBSUFFIX}"))
end
diff --git a/spec/ffi/library_spec.rb b/spec/ffi/library_spec.rb
index a17d673..5b806bb 100644
--- a/spec/ffi/library_spec.rb
+++ b/spec/ffi/library_spec.rb
@@ -322,21 +322,4 @@ describe "Library" do
expect(val[:data]).to eq(i)
end
end
-
- describe "Symbol" do
- before do
- @libtest = FFI::DynamicLibrary.open(
- TestLibrary::PATH,
- FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_GLOBAL,
- )
- end
-
- it "has a memsize function", skip: RUBY_ENGINE != "ruby" do
- base_size = ObjectSpace.memsize_of(Object.new)
-
- symbol = @libtest.find_symbol("gvar_gstruct_set")
- size = ObjectSpace.memsize_of(symbol)
- expect(size).to be > base_size
- end
- end
end