2005-02-04 08:35:37 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require 'dl'
|
2009-03-07 12:21:40 -05:00
|
|
|
require_relative '../ruby/envutil'
|
|
|
|
|
|
|
|
libc_so = libm_so = nil
|
2005-02-04 08:35:37 -05:00
|
|
|
|
|
|
|
case RUBY_PLATFORM
|
|
|
|
when /cygwin/
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = "cygwin1.dll"
|
|
|
|
libm_so = "cygwin1.dll"
|
2008-12-29 07:39:31 -05:00
|
|
|
when /x86_64-linux/
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = "/lib64/libc.so.6"
|
|
|
|
libm_so = "/lib64/libm.so.6"
|
2005-02-04 08:35:37 -05:00
|
|
|
when /linux/
|
2008-12-29 09:54:24 -05:00
|
|
|
libdir = '/lib'
|
|
|
|
case [0].pack('L!').size
|
|
|
|
when 4
|
|
|
|
# 32-bit ruby
|
|
|
|
libdir = '/lib32' if File.directory? '/lib32'
|
|
|
|
when 8
|
|
|
|
# 64-bit ruby
|
|
|
|
libdir = '/lib64' if File.directory? '/lib64'
|
|
|
|
end
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = File.join(libdir, "libc.so.6")
|
|
|
|
libm_so = File.join(libdir, "libm.so.6")
|
2009-03-11 04:39:37 -04:00
|
|
|
when /mingw/, /mswin/
|
|
|
|
require "rbconfig"
|
|
|
|
libc_so = libm_so = RbConfig::CONFIG["RUBY_SO_NAME"].split(/-/, 2)[0] + ".dll"
|
2008-12-27 22:58:02 -05:00
|
|
|
when /darwin/
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = "/usr/lib/libc.dylib"
|
|
|
|
libm_so = "/usr/lib/libm.dylib"
|
2009-03-04 20:33:22 -05:00
|
|
|
when /bsd|dragonfly/
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = "/usr/lib/libc.so"
|
|
|
|
libm_so = "/usr/lib/libm.so"
|
2005-02-04 08:35:37 -05:00
|
|
|
else
|
2009-03-11 13:47:20 -04:00
|
|
|
libc_so = ARGV[0] if ARGV[0] && ARGV[0][0] == ?/
|
|
|
|
libm_so = ARGV[1] if ARGV[1] && ARGV[1][0] == ?/
|
2009-03-07 12:21:40 -05:00
|
|
|
if( !(libc_so && libm_so) )
|
2009-03-06 22:10:44 -05:00
|
|
|
$stderr.puts("libc and libm not found: #{$0} <libc> <libm>")
|
2005-02-04 08:35:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-11 04:39:37 -04:00
|
|
|
libc_so = nil if !libc_so || (libc_so[0] == ?/ && !File.file?(libc_so))
|
|
|
|
libm_so = nil if !libm_so || (libm_so[0] == ?/ && !File.file?(libm_so))
|
2009-03-07 12:21:40 -05:00
|
|
|
|
|
|
|
if !libc_so || !libm_so
|
|
|
|
ruby = EnvUtil.rubybin
|
|
|
|
ldd = `ldd #{ruby}`
|
|
|
|
#puts ldd
|
2009-03-18 08:19:52 -04:00
|
|
|
libc_so = $& if !libc_so && %r{/\S*/libc\.so\S*} =~ ldd
|
|
|
|
libm_so = $& if !libm_so && %r{/\S*/libm\.so\S*} =~ ldd
|
2009-03-07 12:21:40 -05:00
|
|
|
#p [libc_so, libm_so]
|
|
|
|
end
|
|
|
|
|
|
|
|
DL::LIBC_SO = libc_so
|
|
|
|
DL::LIBM_SO = libm_so
|
|
|
|
|
2005-02-04 08:35:37 -05:00
|
|
|
module DL
|
|
|
|
class TestBase < Test::Unit::TestCase
|
|
|
|
include Math
|
|
|
|
include DL
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@libc = dlopen(LIBC_SO)
|
|
|
|
@libm = dlopen(LIBM_SO)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-02-04 08:35:37 -05:00
|
|
|
def assert_match(expected, actual, message="")
|
|
|
|
assert(expected === actual, message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_positive(actual)
|
|
|
|
assert(actual > 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_zero(actual)
|
2010-02-02 20:23:48 -05:00
|
|
|
assert_equal(0, actual)
|
2005-02-04 08:35:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assert_negative(actual)
|
|
|
|
assert(actual < 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|