2 from test
.test_support
import TestSkipped
, run_unittest
7 raise TestSkipped("No fcntl or termios module")
8 if not hasattr(termios
,'TIOCGPGRP'):
9 raise TestSkipped("termios module doesn't have TIOCGPGRP")
12 tty
= open("/dev/tty", "r")
15 raise TestSkipped("Unable to open /dev/tty")
22 class IoctlTests(unittest
.TestCase
):
24 # If this process has been put into the background, TIOCGPGRP returns
25 # the session ID instead of the process group id.
26 ids
= (os
.getpgrp(), os
.getsid(0))
27 tty
= open("/dev/tty", "r")
28 r
= fcntl
.ioctl(tty
, termios
.TIOCGPGRP
, " ")
29 rpgrp
= struct
.unpack("i", r
)[0]
30 self
.assert_(rpgrp
in ids
, "%s not in %s" % (rpgrp
, ids
))
32 def test_ioctl_mutate(self
):
34 buf
= array
.array('i', [0])
35 ids
= (os
.getpgrp(), os
.getsid(0))
36 tty
= open("/dev/tty", "r")
37 r
= fcntl
.ioctl(tty
, termios
.TIOCGPGRP
, buf
, 1)
39 self
.assertEquals(r
, 0)
40 self
.assert_(rpgrp
in ids
, "%s not in %s" % (rpgrp
, ids
))
42 def test_ioctl_signed_unsigned_code_param(self
):
44 raise TestSkipped('pty module required')
45 mfd
, sfd
= pty
.openpty()
47 if termios
.TIOCSWINSZ
< 0:
48 set_winsz_opcode_maybe_neg
= termios
.TIOCSWINSZ
49 set_winsz_opcode_pos
= termios
.TIOCSWINSZ
& 0xffffffffL
51 set_winsz_opcode_pos
= termios
.TIOCSWINSZ
52 set_winsz_opcode_maybe_neg
, = struct
.unpack("i",
53 struct
.pack("I", termios
.TIOCSWINSZ
))
55 our_winsz
= struct
.pack("HHHH",80,25,0,0)
56 # test both with a positive and potentially negative ioctl code
57 new_winsz
= fcntl
.ioctl(mfd
, set_winsz_opcode_pos
, our_winsz
)
58 new_winsz
= fcntl
.ioctl(mfd
, set_winsz_opcode_maybe_neg
, our_winsz
)
64 run_unittest(IoctlTests
)
66 if __name__
== "__main__":