2 from test
.test_support
import run_unittest
, import_module
, get_attribute
4 fcntl
= import_module('fcntl')
5 termios
= import_module('termios')
6 get_attribute(termios
, 'TIOCGPGRP') #Can't run tests without this feature
9 tty
= open("/dev/tty", "r")
12 raise unittest
.SkipTest("Unable to open /dev/tty")
19 class IoctlTests(unittest
.TestCase
):
21 # If this process has been put into the background, TIOCGPGRP returns
22 # the session ID instead of the process group id.
23 ids
= (os
.getpgrp(), os
.getsid(0))
24 tty
= open("/dev/tty", "r")
25 r
= fcntl
.ioctl(tty
, termios
.TIOCGPGRP
, " ")
26 rpgrp
= struct
.unpack("i", r
)[0]
27 self
.assertIn(rpgrp
, ids
)
29 def test_ioctl_mutate(self
):
31 buf
= array
.array('i', [0])
32 ids
= (os
.getpgrp(), os
.getsid(0))
33 tty
= open("/dev/tty", "r")
34 r
= fcntl
.ioctl(tty
, termios
.TIOCGPGRP
, buf
, 1)
36 self
.assertEquals(r
, 0)
37 self
.assertIn(rpgrp
, ids
)
39 def test_ioctl_signed_unsigned_code_param(self
):
41 raise unittest
.SkipTest('pty module required')
42 mfd
, sfd
= pty
.openpty()
44 if termios
.TIOCSWINSZ
< 0:
45 set_winsz_opcode_maybe_neg
= termios
.TIOCSWINSZ
46 set_winsz_opcode_pos
= termios
.TIOCSWINSZ
& 0xffffffffL
48 set_winsz_opcode_pos
= termios
.TIOCSWINSZ
49 set_winsz_opcode_maybe_neg
, = struct
.unpack("i",
50 struct
.pack("I", termios
.TIOCSWINSZ
))
52 our_winsz
= struct
.pack("HHHH",80,25,0,0)
53 # test both with a positive and potentially negative ioctl code
54 new_winsz
= fcntl
.ioctl(mfd
, set_winsz_opcode_pos
, our_winsz
)
55 new_winsz
= fcntl
.ioctl(mfd
, set_winsz_opcode_maybe_neg
, our_winsz
)
61 run_unittest(IoctlTests
)
63 if __name__
== "__main__":