annotate Lib/test/test_ioctl.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents f4c5e3a64be2
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
1 import unittest
52491
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52355
diff changeset
2 from test.test_support import run_unittest, import_module, get_attribute
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
3 import os, struct
52491
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52355
diff changeset
4 fcntl = import_module('fcntl')
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52355
diff changeset
5 termios = import_module('termios')
f4c5e3a64be2 Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents: 52355
diff changeset
6 get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
7
28327
1858bcb61706 Skip the ioctl test if we can't open /dev/tty. This happens on
Neal Norwitz <nnorwitz@gmail.com>
parents: 28145
diff changeset
8 try:
1858bcb61706 Skip the ioctl test if we can't open /dev/tty. This happens on
Neal Norwitz <nnorwitz@gmail.com>
parents: 28145
diff changeset
9 tty = open("/dev/tty", "r")
1858bcb61706 Skip the ioctl test if we can't open /dev/tty. This happens on
Neal Norwitz <nnorwitz@gmail.com>
parents: 28145
diff changeset
10 tty.close()
1858bcb61706 Skip the ioctl test if we can't open /dev/tty. This happens on
Neal Norwitz <nnorwitz@gmail.com>
parents: 28145
diff changeset
11 except IOError:
52355
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
12 raise unittest.SkipTest("Unable to open /dev/tty")
28327
1858bcb61706 Skip the ioctl test if we can't open /dev/tty. This happens on
Neal Norwitz <nnorwitz@gmail.com>
parents: 28145
diff changeset
13
45950
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
14 try:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
15 import pty
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
16 except ImportError:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
17 pty = None
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
18
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
19 class IoctlTests(unittest.TestCase):
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
20 def test_ioctl(self):
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
21 # If this process has been put into the background, TIOCGPGRP returns
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
22 # the session ID instead of the process group id.
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
23 ids = (os.getpgrp(), os.getsid(0))
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
24 tty = open("/dev/tty", "r")
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
25 r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
26 rpgrp = struct.unpack("i", r)[0]
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
27 self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
28
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
29 def test_ioctl_mutate(self):
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
30 import array
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
31 buf = array.array('i', [0])
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
32 ids = (os.getpgrp(), os.getsid(0))
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
33 tty = open("/dev/tty", "r")
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
34 r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
35 rpgrp = buf[0]
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
36 self.assertEquals(r, 0)
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 28327
diff changeset
37 self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
38
45950
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
39 def test_ioctl_signed_unsigned_code_param(self):
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
40 if not pty:
52355
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
41 raise unittest.SkipTest('pty module required')
45950
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
42 mfd, sfd = pty.openpty()
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
43 try:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
44 if termios.TIOCSWINSZ < 0:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
45 set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
46 set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
47 else:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
48 set_winsz_opcode_pos = termios.TIOCSWINSZ
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
49 set_winsz_opcode_maybe_neg, = struct.unpack("i",
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
50 struct.pack("I", termios.TIOCSWINSZ))
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
51
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
52 our_winsz = struct.pack("HHHH",80,25,0,0)
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
53 # test both with a positive and potentially negative ioctl code
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
54 new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
55 new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
56 finally:
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
57 os.close(mfd)
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
58 os.close(sfd)
6a3ef3c9095c Attempt to fix the Solaris Sparc 10 buildbot. It was failing with an invalid
Gregory P. Smith <greg@mad-scientist.com>
parents: 35551
diff changeset
59
28145
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
60 def test_main():
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
61 run_unittest(IoctlTests)
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
62
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
63 if __name__ == "__main__":
898ce4e96f59 Fix bug
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
64 test_main()