@@ -1850,7 +1850,7 @@ def test_invalid_advise
1850
1850
end
1851
1851
end
1852
1852
1853
- def test_fcntl_lock
1853
+ def test_fcntl_lock_linux
1854
1854
return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
1855
1855
1856
1856
pad = 0
@@ -1883,6 +1883,41 @@ def test_fcntl_lock
1883
1883
end
1884
1884
end
1885
1885
1886
+ def test_fcntl_lock_freebsd
1887
+ return if /freebsd/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
1888
+
1889
+ start = 12
1890
+ len = 34
1891
+ sysid = 0
1892
+ Tempfile . open ( self . class . name ) do |f |
1893
+ r , w = IO . pipe
1894
+ pid = fork do
1895
+ r . close
1896
+ lock = [ start , len , 0 , Fcntl ::F_WRLCK , IO ::SEEK_SET , sysid ] . pack ( "qqis!s!i!" )
1897
+ f . fcntl Fcntl ::F_SETLKW , lock
1898
+ w . syswrite "."
1899
+ sleep
1900
+ end
1901
+ w . close
1902
+ assert_equal "." , r . read ( 1 )
1903
+ r . close
1904
+
1905
+ getlock = [ 0 , 0 , 0 , Fcntl ::F_WRLCK , 0 , 0 ] . pack ( "qqis!s!i!" )
1906
+ f . fcntl Fcntl ::F_GETLK , getlock
1907
+
1908
+ start , len , lockpid , ptype , whence , sysid = getlock . unpack ( "qqis!s!i!" )
1909
+
1910
+ assert_equal ( ptype , Fcntl ::F_WRLCK )
1911
+ assert_equal ( whence , IO ::SEEK_SET )
1912
+ assert_equal ( start , 12 )
1913
+ assert_equal ( len , 34 )
1914
+ assert_equal ( pid , lockpid )
1915
+
1916
+ Process . kill :TERM , pid
1917
+ Process . waitpid2 ( pid )
1918
+ end
1919
+ end
1920
+
1886
1921
def test_cross_thread_close_fd
1887
1922
skip "cross thread close causes hung-up if pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
1888
1923
with_pipe do |r , w |
0 commit comments