[前][次][番号順一覧][スレッド一覧]

ruby-changes:21670

From: kosaki <ko1@a...>
Date: Sat, 12 Nov 2011 11:31:25 +0900 (JST)
Subject: [ruby-changes:21670] kosaki:r33719 (trunk): * test/ruby/test_io.rb (test_fcntl_lock_freebsd): add a testcase

kosaki	2011-11-12 11:31:15 +0900 (Sat, 12 Nov 2011)

  New Revision: 33719

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33719

  Log:
    * test/ruby/test_io.rb (test_fcntl_lock_freebsd): add a testcase
      of fcntl lock for freebsd.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33718)
+++ ChangeLog	(revision 33719)
@@ -1,3 +1,8 @@
+Sat Nov 12 11:18:17 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* test/ruby/test_io.rb (test_fcntl_lock_freebsd): add a testcase
+	  of fcntl lock for freebsd.
+
 Sat Nov 12 11:16:32 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* io.c (ioctl_narg_len): Linux doesn't have IOCPARM_LEN macro, but
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 33718)
+++ test/ruby/test_io.rb	(revision 33719)
@@ -1850,7 +1850,7 @@
     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
 
+  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|

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]