summaryrefslogtreecommitdiff
path: root/test/ruby/test_io.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r--test/ruby/test_io.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 6cc2897f5f..6b8e6b58ce 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1776,4 +1776,37 @@ End
end
end
end
+
+ def test_fcntl_lock
+ return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
+
+ pad=0
+ Tempfile.open(self.class.name) do |f|
+ r, w = IO.pipe
+ pid = fork do
+ r.close
+ lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!")
+ f.fcntl Fcntl::F_SETLKW, lock
+ w.syswrite "."
+ sleep
+ end
+ w.close
+ assert_equal ".", r.read(1)
+ r.close
+ pad = 0
+ getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!")
+ f.fcntl Fcntl::F_GETLK, getlock
+
+ ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!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
end