diff options
author | Michael Leibowitz <michael.leibowitz@intel.com> | 2013-08-15 15:02:54 -0700 |
---|---|---|
committer | Michael Leibowitz <michael.leibowitz@intel.com> | 2013-08-15 15:02:54 -0700 |
commit | 6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06 (patch) | |
tree | d9d59f4b502927634d32832e963db76629ff5a2e /test/socket | |
parent | 3b35de2a90e26b99e2a6d4f61dc56d6ce7ded748 (diff) | |
download | ruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.tar.gz ruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.tar.bz2 ruby-6b0e2a11aeccf2ebc707c22548a0c15c8c2bae06.zip |
Imported Upstream version 1.9.3.p448upstream/1.9.3.p448upstream
Diffstat (limited to 'test/socket')
-rw-r--r-- | test/socket/test_socket.rb | 34 | ||||
-rw-r--r-- | test/socket/test_unix.rb | 72 |
2 files changed, 96 insertions, 10 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index f433be8..f693a62 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -275,8 +275,32 @@ class TestSocket < Test::Unit::TestCase Socket.udp_server_sockets(0) {|sockets| famlies = {} - sockets.each {|s| famlies[s.local_address.afamily] = true } - ip_addrs.reject! {|ai| !famlies[ai.afamily] } + sockets.each {|s| famlies[s.local_address.afamily] = s } + ip_addrs.reject! {|ai| + s = famlies[ai.afamily] + next true unless s + case RUBY_PLATFORM + when /linux/ + if ai.ip_address.include?('%') and + (`uname -r`[/[0-9.]+/].split('.').map(&:to_i) <=> [2,6,18]) <= 0 + # Cent OS 5.6 (2.6.18-238.19.1.el5xen) doesn't correctly work + # sendmsg with pktinfo for link-local ipv6 addresses + next true + end + when /freebsd/ + if ifr_name = ai.ip_address[/%(.*)/, 1] + # FreeBSD 9.0 with default setting (ipv6_activate_all_interfaces + # is not YES) sets IFDISABLED to interfaces which don't have + # global IPv6 address. + # Link-local IPv6 addresses on those interfaces don't work. + ulSIOCGIFINFO_IN6 = -1068996244 + bIFDISABLED = 4 + in6_ifreq = ifr_name + s.ioctl(ulSIOCGIFINFO_IN6, in6_ifreq) + next true if in6_ifreq.unpack('A16L6').last[bIFDISABLED-1] == 1 + end + end + } skipped = false begin port = sockets.first.local_address.ip_port @@ -290,12 +314,6 @@ class TestSocket < Test::Unit::TestCase } ip_addrs.each {|ai| - if /linux/ =~ RUBY_PLATFORM && ai.ip_address.include?('%') && - (`uname -r`[/[0-9.]+/].split('.').map(&:to_i) <=> [2,6,18]) <= 0 - # Cent OS 5.6 (2.6.18-238.19.1.el5xen) doesn't correctly work - # sendmsg with pktinfo for link-local ipv6 addresses - next - end Addrinfo.udp(ai.ip_address, port).connect {|s| msg1 = "<<<#{ai.inspect}>>>" s.sendmsg msg1 diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb index b4c4592..3559eb8 100644 --- a/test/socket/test_unix.rb +++ b/test/socket/test_unix.rb @@ -324,8 +324,11 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase assert_raise(ArgumentError) { UNIXServer.new("a" * 300) } end - def test_nul - assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") } + def test_abstract_namespace + return if /linux/ !~ RUBY_PLATFORM + addr = Socket.pack_sockaddr_un("\0foo") + assert_match(/\0foo\z/, addr) + assert_equal("\0foo", Socket.unpack_sockaddr_un(addr)) end def test_dgram_pair @@ -507,4 +510,69 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase } end + def test_abstract_unix_server + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + s0 = nil + UNIXServer.open(name) {|s| + assert_equal(name, s.local_address.unix_path) + s0 = s + UNIXSocket.open(name) {|c| + sock = s.accept + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + + def test_abstract_unix_socket_econnrefused + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + assert_raise(Errno::ECONNREFUSED) do + UNIXSocket.open(name) {} + end + end + + def test_abstract_unix_server_socket + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + s0 = nil + Socket.unix_server_socket(name) {|s| + assert_equal(name, s.local_address.unix_path) + s0 = s + Socket.unix(name) {|c| + sock, = s.accept + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + + def test_autobind + return if /linux/ !~ RUBY_PLATFORM + s0 = nil + Socket.unix_server_socket("") {|s| + name = s.local_address.unix_path + assert_match(/\A\0[0-9a-f]{5}\z/, name) + s0 = s + Socket.unix(name) {|c| + sock, = s.accept + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM |