From f2708ce30f0bf7c7a0ace010a7f8461de1e41f8b Mon Sep 17 00:00:00 2001 From: kosaki Date: Sat, 12 Nov 2011 02:31:15 +0000 Subject: * test/ruby/test_io.rb (test_fcntl_lock_freebsd): add a testcase of fcntl lock for freebsd. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'test/ruby/test_io.rb') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f7670a1293..21a215d67a 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1850,7 +1850,7 @@ End end end - def test_fcntl_lock + def test_fcntl_lock_linux return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform pad=0 @@ -1883,6 +1883,41 @@ End end end + def test_fcntl_lock_freebsd + return if /freebsd/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform + + start = 12 + len = 34 + sysid = 0 + Tempfile.open(self.class.name) do |f| + r, w = IO.pipe + pid = fork do + r.close + lock = [start, len, 0, Fcntl::F_WRLCK, IO::SEEK_SET, sysid].pack("qqis!s!i!") + f.fcntl Fcntl::F_SETLKW, lock + w.syswrite "." + sleep + end + w.close + assert_equal ".", r.read(1) + r.close + + getlock = [0, 0, 0, Fcntl::F_WRLCK, 0, 0].pack("qqis!s!i!") + f.fcntl Fcntl::F_GETLK, getlock + + start, len, lockpid, ptype, whence, sysid = getlock.unpack("qqis!s!i!") + + assert_equal(ptype, Fcntl::F_WRLCK) + assert_equal(whence, IO::SEEK_SET) + assert_equal(start, 12) + assert_equal(len, 34) + assert_equal(pid, lockpid) + + Process.kill :TERM, pid + Process.waitpid2(pid) + end + end + def test_cross_thread_close_fd skip "cross thread close causes hung-up if pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM with_pipe do |r,w| -- cgit v1.2.3