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")
|
2005-02-09 04:42:40 -05:00
|
|
|
when /mingw/, /mswin32/
|
2009-03-07 12:21:40 -05:00
|
|
|
libc_so = "msvcrt.dll"
|
|
|
|
libm_so = "msvcrt.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-07 12:21:40 -05:00
|
|
|
libc_so = ARGV[0]
|
|
|
|
libm_so = ARGV[1]
|
|
|
|
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-07 12:21:40 -05:00
|
|
|
libc_so = nil if !libc_so || !File.file?(libc_so)
|
|
|
|
libm_so = nil if !libm_so || !File.file?(libm_so)
|
|
|
|
|
|
|
|
if !libc_so || !libm_so
|
|
|
|
ruby = EnvUtil.rubybin
|
|
|
|
ldd = `ldd #{ruby}`
|
|
|
|
#puts ldd
|
|
|
|
libc_so = $1 if !libc_so && %r{libc\.so.*=>\s+(/\S*)} =~ ldd
|
|
|
|
libm_so = $1 if !libm_so && %r{libm\.so.*=>\s+(/\S*)} =~ ldd
|
|
|
|
#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)
|
|
|
|
assert(actual == 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_negative(actual)
|
|
|
|
assert(actual < 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|