Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_ioctl.py

    r2 r391  
     1import array
    12import unittest
    2 from test.test_support import TestSkipped, run_unittest
     3from test.test_support import run_unittest, import_module, get_attribute
    34import os, struct
    4 try:
    5     import fcntl, termios
    6 except ImportError:
    7     raise TestSkipped("No fcntl or termios module")
    8 if not hasattr(termios,'TIOCGPGRP'):
    9     raise TestSkipped("termios module doesn't have TIOCGPGRP")
     5fcntl = import_module('fcntl')
     6termios = import_module('termios')
     7get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
    108
    119try:
    1210    tty = open("/dev/tty", "r")
     11except IOError:
     12    raise unittest.SkipTest("Unable to open /dev/tty")
     13else:
     14    # Skip if another process is in foreground
     15    r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
    1316    tty.close()
    14 except IOError:
    15     raise TestSkipped("Unable to open /dev/tty")
     17    rpgrp = struct.unpack("i", r)[0]
     18    if rpgrp not in (os.getpgrp(), os.getsid(0)):
     19        raise unittest.SkipTest("Neither the process group nor the session "
     20                                "are attached to /dev/tty")
     21    del tty, r, rpgrp
    1622
    1723try:
     
    2834        r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
    2935        rpgrp = struct.unpack("i", r)[0]
    30         self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
     36        self.assertIn(rpgrp, ids)
     37
     38    def _check_ioctl_mutate_len(self, nbytes=None):
     39        buf = array.array('i')
     40        intsize = buf.itemsize
     41        ids = (os.getpgrp(), os.getsid(0))
     42        # A fill value unlikely to be in `ids`
     43        fill = -12345
     44        if nbytes is not None:
     45            # Extend the buffer so that it is exactly `nbytes` bytes long
     46            buf.extend([fill] * (nbytes // intsize))
     47            self.assertEqual(len(buf) * intsize, nbytes)   # sanity check
     48        else:
     49            buf.append(fill)
     50        with open("/dev/tty", "r") as tty:
     51            r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
     52        rpgrp = buf[0]
     53        self.assertEqual(r, 0)
     54        self.assertIn(rpgrp, ids)
    3155
    3256    def test_ioctl_mutate(self):
    33         import array
    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)
    38         rpgrp = buf[0]
    39         self.assertEquals(r, 0)
    40         self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))
     57        self._check_ioctl_mutate_len()
     58
     59    def test_ioctl_mutate_1024(self):
     60        # Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be
     61        # copied back after the system call.
     62        self._check_ioctl_mutate_len(1024)
     63
     64    def test_ioctl_mutate_2048(self):
     65        # Test with a larger buffer, just for the record.
     66        self._check_ioctl_mutate_len(2048)
    4167
    4268    def test_ioctl_signed_unsigned_code_param(self):
    4369        if not pty:
    44             raise TestSkipped('pty module required')
     70            raise unittest.SkipTest('pty module required')
    4571        mfd, sfd = pty.openpty()
    4672        try:
Note: See TracChangeset for help on using the changeset viewer.