git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-11-03 11:15:15 +00:00
Родитель df6a0fe8bb
Коммит 88f1b8cf0c
5 изменённых файлов: 94 добавлений и 0 удалений

Просмотреть файл

@ -2030,4 +2030,29 @@ End
end
assert_equal("[Feature #5029]\n[ruby-core:38070]\n", stderr)
end
def test_cloexec
return unless defined? Fcntl::FD_CLOEXEC
open(__FILE__) {|f|
assert(f.close_on_exec?)
g = f.dup
begin
assert(g.close_on_exec?)
f.reopen(g)
assert(f.close_on_exec?)
ensure
g.close
end
g = IO.new(f.fcntl(Fcntl::F_DUPFD))
begin
assert(g.close_on_exec?)
ensure
g.close
end
}
IO.pipe {|r,w|
assert(r.close_on_exec?)
assert(w.close_on_exec?)
}
end
end

Просмотреть файл

@ -1323,4 +1323,11 @@ class TestProcess < Test::Unit::TestCase
end
end
end
def test_popen_cloexec
return unless defined? Fcntl::FD_CLOEXEC
IO.popen([RUBY, "-e", ""]) {|io|
assert(io.close_on_exec?)
}
end
end

Просмотреть файл

@ -1,6 +1,7 @@
begin
require "socket"
require "tmpdir"
require "fcntl"
require "test/unit"
rescue LoadError
end
@ -15,6 +16,16 @@ class TestSocket < Test::Unit::TestCase
end
end
def test_socket_new_cloexec
return unless defined? Fcntl::FD_CLOEXEC
begin
s = Socket.new(:INET, :STREAM)
assert(s.close_on_exec?)
ensure
s.close
end
end
def test_unpack_sockaddr
sockaddr_in = Socket.sockaddr_in(80, "")
assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(sockaddr_in) }
@ -103,6 +114,22 @@ class TestSocket < Test::Unit::TestCase
}
end
def test_tcp_cloexec
return unless defined? Fcntl::FD_CLOEXEC
TCPServer.open(0) {|serv|
addr = serv.connect_address
addr.connect {|s1|
s2 = serv.accept
begin
assert(s2.close_on_exec?)
ensure
s2.close
end
}
}
end
def random_port
# IANA suggests dynamic port for 49152 to 65535
# http://www.iana.org/assignments/port-numbers
@ -159,6 +186,7 @@ class TestSocket < Test::Unit::TestCase
assert(s2raddr.to_sockaddr.empty? ||
s1laddr.to_sockaddr.empty? ||
s2raddr.unix_path == s1laddr.unix_path)
assert(s2.close_on_exec?)
ensure
s2.close
end

Просмотреть файл

@ -22,6 +22,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
r2 = s2.recv_io
assert_equal(r1.stat.ino, r2.stat.ino)
assert_not_equal(r1.fileno, r2.fileno)
assert(r2.close_on_exec?)
w.syswrite "a"
assert_equal("a", r2.sysread(10))
ensure
@ -61,6 +62,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
send_io_ary.length.times {|i|
assert_not_equal(send_io_ary[i].fileno, recv_io_ary[i].fileno)
assert(File.identical?(send_io_ary[i], recv_io_ary[i]))
assert(recv_io_ary[i].close_on_exec?)
}
}
}
@ -97,6 +99,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
send_io_ary.length.times {|i|
assert_not_equal(send_io_ary[i].fileno, recv_io_ary[i].fileno)
assert(File.identical?(send_io_ary[i], recv_io_ary[i]))
assert(recv_io_ary[i].close_on_exec?)
}
}
}
@ -150,6 +153,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
r2 = s2.recv_io
begin
assert(File.identical?(r1, r2))
assert(r2.close_on_exec?)
ensure
r2.close
end
@ -230,6 +234,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
r2 = ios[0]
begin
assert(File.identical?(r1, r2))
assert(r2.close_on_exec?)
ensure
r2.close
end
@ -260,6 +265,16 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
}
end
def test_cloexec
bound_unix_socket(UNIXServer) {|serv, path|
c = UNIXSocket.new(path)
s = serv.accept
assert(serv.close_on_exec?)
assert(c.close_on_exec?)
assert(s.close_on_exec?)
}
end
def test_noname_path
s1, s2 = UNIXSocket.pair
assert_equal("", s1.path)
@ -374,6 +389,14 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
assert_kind_of(UNIXSocket, pair[1])
end
def test_unix_socket_pair_close_on_exec
pair = nil
UNIXSocket.pair {|s1, s2|
assert(s1.close_on_exec?)
assert(s2.close_on_exec?)
}
end
def test_initialize
Dir.mktmpdir {|d|
Socket.open(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) {|s|

Просмотреть файл

@ -195,5 +195,16 @@ class TestPTY < Test::Unit::TestCase
assert_nil(st1)
assert_equal(pid, st2.pid)
end
def test_cloexec
PTY.open {|m, s|
assert(m.close_on_exec?)
assert(s.close_on_exec?)
}
PTY.spawn(RUBY, '-e', '') {|r, w, pid|
assert(r.close_on_exec?)
assert(w.close_on_exec?)
}
end
end if defined? PTY