ruby-changes:18991
From: kosaki <ko1@a...>
Date: Sat, 5 Mar 2011 19:45:12 +0900 (JST)
Subject: [ruby-changes:18991] Ruby:r31027 (trunk): * test/ruby/test_io.rb (TestIO#test_fcntl_lock): small clean up.
kosaki 2011-03-05 19:45:01 +0900 (Sat, 05 Mar 2011) New Revision: 31027 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31027 Log: * test/ruby/test_io.rb (TestIO#test_fcntl_lock): small clean up. Modified files: trunk/ChangeLog trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31026) +++ ChangeLog (revision 31027) @@ -1,3 +1,7 @@ +Sat Mar 5 19:44:03 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * test/ruby/test_io.rb (TestIO#test_fcntl_lock): small clean up. + Sat Mar 5 01:33:46 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * io.c (io_cntl, nogvl_io_cntl): IO.fcntl() and IO.ioctl() Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 31026) +++ test/ruby/test_io.rb (revision 31027) @@ -1777,37 +1777,36 @@ end end + def test_fcntl_lock + return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform - if /x86_64-linux/ =~ RUBY_PLATFORM # A binary form of struct flock depend on platform - F_WRLCK = 1 - F_UNLCK = 2 - SEEK_SET = 0 - - def test_fcntl_lock + 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 - flocktype = "s!s!s!s!L!L!i!" + getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!") + f.fcntl Fcntl::F_GETLK, getlock - Tempfile.open(self.class.name) do |f| - r, w = IO.pipe - pid = fork do - r.close - lock = [F_WRLCK, SEEK_SET, pad, pad, 0, 0, 0].pack(flocktype) - f.fcntl Fcntl::F_SETLKW, lock - w.syswrite "." - sleep - end - w.close - assert_equal ".", r.read(1) - r.close - pad = 0 - getlock = [F_WRLCK, 0, pad, pad, 0, 0, 0].pack(flocktype) - f.fcntl Fcntl::F_GETLK, getlock + ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!") - ptype, whence, pad, pad, start, len, lockpid = getlock.unpack(flocktype) - assert_equal(pid, lockpid) - Process.kill :TERM, pid - Process.waitpid2(pid) - end + 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/