1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#
# This file is part of ruby-ffi.
# For licensing, see LICENSE.SPECS
#
require_relative 'fixtures/compile'
require 'timeout'
require 'objspace'
RSpec.configure do |c|
c.filter_run_excluding gc_dependent: true unless ENV['FFI_TEST_GC'] == 'true'
c.filter_run_excluding( :ractor ) unless defined?(Ractor) && RUBY_VERSION >= "3.1" && (RUBY_VERSION !~ /^3.3./ || RUBY_PLATFORM !~ /mingw/)
end
module TestLibrary
def self.force_gc
if RUBY_ENGINE == 'jruby'
java.lang.System.gc
elsif RUBY_ENGINE == 'rbx'
GC.run(true)
else
GC.start
end
end
end
module LibTest
extend FFI::Library
ffi_lib TestLibrary::PATH
end
def external_run(cmd, rb_file, options: [], timeout: 60)
path = File.join(File.dirname(__FILE__), rb_file)
log = "#{path}.log"
pid = spawn(cmd, "-Ilib", path, { [:out, :err] => log })
begin
Timeout.timeout(timeout){ Process.wait(pid) }
rescue Timeout::Error
Process.kill(9, pid)
raise
else
if $?.exitstatus != 0
raise "external process failed:\n#{ File.read(log) }"
end
end
File.read(log)
end
module OrderHelper
case FFI::Platform::BYTE_ORDER
when FFI::Platform::LITTLE_ENDIAN
ORDER = :little
OTHER_ORDER = :big
when FFI::Platform::BIG_ENDIAN
ORDER = :big
OTHER_ORDER = :little
else
raise
end
end
if ENV['FFI_GC_STRESS'] == 'true'
RSpec.configure do |config|
config.before :each do
GC.stress=true
end
config.after :each do
GC.stress=false
end
end
end
|