1 """Test program for the fcntl C module.
3 OS/2+EMX doesn't support the file locking operations.
10 from test
.test_support
import (verbose
, TESTFN
, unlink
, run_unittest
,
13 # Skip test if no fnctl module.
14 fcntl
= import_module('fcntl')
17 # TODO - Write tests for flock() and lockf().
20 if sys
.platform
.startswith('atheos'):
25 except AttributeError:
30 if sys
.platform
in ('netbsd1', 'netbsd2', 'netbsd3',
31 'Darwin1.2', 'darwin',
32 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
33 'freebsd6', 'freebsd7', 'freebsd8',
34 'bsdos2', 'bsdos3', 'bsdos4',
35 'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
36 if struct
.calcsize('l') == 8:
42 lockdata
= struct
.pack(off_t
+ off_t
+ pid_t
+ 'hh', 0, 0, 0,
44 elif sys
.platform
in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
45 lockdata
= struct
.pack('hhlllii', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0, 0)
46 elif sys
.platform
in ['os2emx']:
49 lockdata
= struct
.pack('hh'+start_len
+'hh', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0)
52 print 'struct.pack: ', repr(lockdata
)
55 lockdata
= get_lockdata()
58 class TestFcntl(unittest
.TestCase
):
64 if self
.f
and not self
.f
.closed
:
68 def test_fcntl_fileno(self
):
69 # the example from the library docs
70 self
.f
= open(TESTFN
, 'w')
71 rv
= fcntl
.fcntl(self
.f
.fileno(), fcntl
.F_SETFL
, os
.O_NONBLOCK
)
73 print 'Status from fcntl with O_NONBLOCK: ', rv
74 if sys
.platform
not in ['os2emx']:
75 rv
= fcntl
.fcntl(self
.f
.fileno(), fcntl
.F_SETLKW
, lockdata
)
77 print 'String from fcntl with F_SETLKW: ', repr(rv
)
80 def test_fcntl_file_descriptor(self
):
81 # again, but pass the file rather than numeric descriptor
82 self
.f
= open(TESTFN
, 'w')
83 rv
= fcntl
.fcntl(self
.f
, fcntl
.F_SETFL
, os
.O_NONBLOCK
)
84 if sys
.platform
not in ['os2emx']:
85 rv
= fcntl
.fcntl(self
.f
, fcntl
.F_SETLKW
, lockdata
)
88 def test_fcntl_64_bit(self
):
89 # Issue #1309352: fcntl shouldn't fail when the third arg fits in a
90 # C 'long' but not in a C 'int'.
93 # This flag is larger than 2**31 in 64-bit builds
94 flags
= fcntl
.DN_MULTISHOT
95 except AttributeError:
96 self
.skipTest("F_NOTIFY or DN_MULTISHOT unavailable")
97 fd
= os
.open(os
.path
.dirname(os
.path
.abspath(TESTFN
)), os
.O_RDONLY
)
99 fcntl
.fcntl(fd
, cmd
, flags
)
105 run_unittest(TestFcntl
)
107 if __name__
== '__main__':