2012-11-28 21:58:34 -05:00
|
|
|
# -*- coding: us-ascii -*-
|
2005-02-04 08:35:37 -05:00
|
|
|
require 'test/unit'
|
2009-03-07 12:21:40 -05:00
|
|
|
require_relative '../ruby/envutil'
|
2012-11-28 21:58:34 -05:00
|
|
|
EnvUtil.suppress_warning {require 'dl'}
|
2009-03-07 12:21:40 -05:00
|
|
|
|
|
|
|
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"
|
2011-04-28 02:34:01 -04:00
|
|
|
libc_so = libm_so = RbConfig::CONFIG["RUBY_SO_NAME"].split(/-/).find{|e| /^msvc/ =~ e} + ".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"
|
2010-04-23 11:38:11 -04:00
|
|
|
when /kfreebsd/
|
|
|
|
libc_so = "/lib/libc.so.0.1"
|
|
|
|
libm_so = "/lib/libm.so.1"
|
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"
|
2010-05-08 12:05:27 -04:00
|
|
|
when /solaris/
|
|
|
|
libdir = '/lib'
|
|
|
|
case [0].pack('L!').size
|
|
|
|
when 4
|
|
|
|
# 32-bit ruby
|
|
|
|
libdir = '/lib' if File.directory? '/lib'
|
|
|
|
when 8
|
|
|
|
# 64-bit ruby
|
|
|
|
libdir = '/lib/64' if File.directory? '/lib/64'
|
|
|
|
end
|
2011-08-08 23:36:18 -04:00
|
|
|
libc_so = File.join(libdir, "libc.so")
|
|
|
|
libm_so = File.join(libdir, "libm.so")
|
2010-08-25 21:16:53 -04:00
|
|
|
when /aix/
|
|
|
|
pwd=Dir.pwd
|
|
|
|
libc_so = libm_so = "#{pwd}/libaixdltest.so"
|
|
|
|
unless File.exist? libc_so
|
|
|
|
cobjs=%w!strcpy.o!
|
|
|
|
mobjs=%w!floats.o sin.o!
|
|
|
|
funcs=%w!sin sinf strcpy strncpy!
|
|
|
|
expfile='dltest.exp'
|
|
|
|
require 'tmpdir'
|
|
|
|
Dir.mktmpdir do |dir|
|
|
|
|
begin
|
|
|
|
Dir.chdir dir
|
|
|
|
%x!/usr/bin/ar x /usr/lib/libc.a #{cobjs.join(' ')}!
|
|
|
|
%x!/usr/bin/ar x /usr/lib/libm.a #{mobjs.join(' ')}!
|
|
|
|
%x!echo "#{funcs.join("\n")}\n" > #{expfile}!
|
|
|
|
require 'rbconfig'
|
|
|
|
if RbConfig::CONFIG["GCC"] = 'yes'
|
|
|
|
lflag='-Wl,'
|
|
|
|
else
|
|
|
|
lflag=''
|
|
|
|
end
|
|
|
|
flags="#{lflag}-bE:#{expfile} #{lflag}-bnoentry -lm"
|
|
|
|
%x!#{RbConfig::CONFIG["LDSHARED"]} -o #{libc_so} #{(cobjs+mobjs).join(' ')} #{flags}!
|
|
|
|
ensure
|
|
|
|
Dir.chdir pwd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
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="")
|
2010-02-16 05:03:02 -05:00
|
|
|
assert_operator(expected, :===, actual, message)
|
2005-02-04 08:35:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def assert_positive(actual)
|
2010-02-16 05:03:02 -05:00
|
|
|
assert_operator(actual, :>, 0)
|
2005-02-04 08:35:37 -05:00
|
|
|
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)
|
2010-02-16 05:03:02 -05:00
|
|
|
assert_operator(actual, :<, 0)
|
2005-02-04 08:35:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|