Exemplo n.º 1
0
def test_basic_pty():
    try:
        debug("Calling master_open()")
        master_fd, slave_name = pty.master_open()
        debug("Got master_fd '%d', slave_name '%s'"%(master_fd, slave_name))
        debug("Calling slave_open(%r)"%(slave_name,))
        slave_fd = pty.slave_open(slave_name)
        debug("Got slave_fd '%d'"%slave_fd)
    except OSError:
        # " An optional feature could not be imported " ... ?
        raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

    if not os.isatty(slave_fd):
        raise TestFailed, "slave_fd is not a tty"

    debug("Writing to slave_fd")
    os.write(slave_fd, TEST_STRING_1)
    s1 = os.read(master_fd, 1024)
    sys.stdout.write(normalize_output(s1))

    debug("Writing chunked output")
    os.write(slave_fd, TEST_STRING_2[:5])
    os.write(slave_fd, TEST_STRING_2[5:])
    s2 = os.read(master_fd, 1024)
    sys.stdout.write(normalize_output(s2))

    os.close(slave_fd)
    os.close(master_fd)
Exemplo n.º 2
0
def test_basic_pty():
    try:
        debug("Calling master_open()")
        master_fd, slave_name = pty.master_open()
        debug("Got master_fd '%d', slave_name '%s'" % (master_fd, slave_name))
        debug("Calling slave_open(%r)" % (slave_name, ))
        slave_fd = pty.slave_open(slave_name)
        debug("Got slave_fd '%d'" % slave_fd)
    except OSError:
        # " An optional feature could not be imported " ... ?
        raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

    if not os.isatty(slave_fd):
        raise TestFailed, "slave_fd is not a tty"

    debug("Writing to slave_fd")
    os.write(slave_fd, TEST_STRING_1)
    s1 = os.read(master_fd, 1024)
    sys.stdout.write(normalize_output(s1))

    debug("Writing chunked output")
    os.write(slave_fd, TEST_STRING_2[:5])
    os.write(slave_fd, TEST_STRING_2[5:])
    s2 = os.read(master_fd, 1024)
    sys.stdout.write(normalize_output(s2))

    os.close(slave_fd)
    os.close(master_fd)
Exemplo n.º 3
0
    def test_basic(self):
        try:
            debug("Calling master_open()")
            master_fd, slave_name = pty.master_open()
            debug("Got master_fd '%d', slave_name '%s'" %
                  (master_fd, slave_name))
            debug("Calling slave_open(%r)" % (slave_name,))
            slave_fd = pty.slave_open(slave_name)
            debug("Got slave_fd '%d'" % slave_fd)
        except OSError:
            # " An optional feature could not be imported " ... ?
            raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

        self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')

        # Solaris requires reading the fd before anything is returned.
        # My guess is that since we open and close the slave fd
        # in master_open(), we need to read the EOF.

        # Ensure the fd is non-blocking in case there's nothing to read.
        orig_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL)
        fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags | os.O_NONBLOCK)
        try:
            s1 = os.read(master_fd, 1024)
            self.assertEquals('', s1)
        except OSError, e:
            if e.errno != errno.EAGAIN:
                raise
Exemplo n.º 4
0
def test_basic_pty():
    try:
        debug("Calling master_open()")
        master_fd, slave_name = pty.master_open()
        debug("Got master_fd '%d', slave_name '%s'" % (master_fd, slave_name))
        debug("Calling slave_open(%r)" % (slave_name, ))
        slave_fd = pty.slave_open(slave_name)
        debug("Got slave_fd '%d'" % slave_fd)
    except OSError:
        # " An optional feature could not be imported " ... ?
        raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

    if not os.isatty(slave_fd) and sys.platform not in fickle_isatty:
        raise TestFailed, "slave_fd is not a tty"

    # IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
    # differences (like extra whitespace, trailing garbage, etc.)

    debug("Writing to slave_fd")
    os.write(slave_fd, TEST_STRING_1)
    s1 = os.read(master_fd, 1024)
    sys.stdout.write(s1.replace("\r\n", "\n"))

    debug("Writing chunked output")
    os.write(slave_fd, TEST_STRING_2[:5])
    os.write(slave_fd, TEST_STRING_2[5:])
    s2 = os.read(master_fd, 1024)
    sys.stdout.write(s2.replace("\r\n", "\n"))

    os.close(slave_fd)
    os.close(master_fd)
Exemplo n.º 5
0
    def test_basic(self):
        try:
            debug("Calling master_open()")
            master_fd, slave_name = pty.master_open()
            debug("Got master_fd '%d', slave_name '%s'" %
                  (master_fd, slave_name))
            debug("Calling slave_open(%r)" % (slave_name, ))
            slave_fd = pty.slave_open(slave_name)
            debug("Got slave_fd '%d'" % slave_fd)
        except OSError:
            # " An optional feature could not be imported " ... ?
            raise unittest.SkipTest, "Pseudo-terminals (seemingly) not functional."

        self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')

        # Solaris requires reading the fd before anything is returned.
        # My guess is that since we open and close the slave fd
        # in master_open(), we need to read the EOF.

        # Ensure the fd is non-blocking in case there's nothing to read.
        orig_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL)
        fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags | os.O_NONBLOCK)
        try:
            s1 = os.read(master_fd, 1024)
            self.assertEqual('', s1)
        except OSError, e:
            if e.errno != errno.EAGAIN:
                raise
Exemplo n.º 6
0
def test_basic_pty():
    try:
        debug("Calling master_open()")
        master_fd, slave_name = pty.master_open()
        debug("Got master_fd '%d', slave_name '%s'"%(master_fd, slave_name))
        debug("Calling slave_open(%r)"%(slave_name,))
        slave_fd = pty.slave_open(slave_name)
        debug("Got slave_fd '%d'"%slave_fd)
    except OSError:
        # " An optional feature could not be imported " ... ?
        raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

    if not os.isatty(slave_fd) and sys.platform not in fickle_isatty:
        raise TestFailed, "slave_fd is not a tty"

    # IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
    # differences (like extra whitespace, trailing garbage, etc.)

    debug("Writing to slave_fd")
    os.write(slave_fd, TEST_STRING_1)
    s1 = os.read(master_fd, 1024)
    sys.stdout.write(s1.replace("\r\n", "\n"))

    debug("Writing chunked output")
    os.write(slave_fd, TEST_STRING_2[:5])
    os.write(slave_fd, TEST_STRING_2[5:])
    s2 = os.read(master_fd, 1024)
    sys.stdout.write(s2.replace("\r\n", "\n"))

    os.close(slave_fd)
    os.close(master_fd)
Exemplo n.º 7
0
    def test_basic(self):
        try:
            debug("Calling master_open()")
            master_fd, slave_name = pty.master_open()
            debug("Got master_fd '%d', slave_name '%s'" %
                  (master_fd, slave_name))
            debug("Calling slave_open(%r)" % (slave_name, ))
            slave_fd = pty.slave_open(slave_name)
            debug("Got slave_fd '%d'" % slave_fd)
        except OSError:
            # " An optional feature could not be imported " ... ?
            raise unittest.SkipTest(
                "Pseudo-terminals (seemingly) not functional.")

        self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')

        # Solaris requires reading the fd before anything is returned.
        # My guess is that since we open and close the slave fd
        # in master_open(), we need to read the EOF.

        # Ensure the fd is non-blocking in case there's nothing to read.
        blocking = os.get_blocking(master_fd)
        try:
            os.set_blocking(master_fd, False)
            try:
                s1 = os.read(master_fd, 1024)
                self.assertEqual(b'', s1)
            except OSError as e:
                if e.errno != errno.EAGAIN:
                    raise
        finally:
            # Restore the original flags.
            os.set_blocking(master_fd, blocking)

        debug("Writing to slave_fd")
        os.write(slave_fd, TEST_STRING_1)
        s1 = _readline(master_fd)
        self.assertEqual(b'I wish to buy a fish license.\n',
                         normalize_output(s1))

        debug("Writing chunked output")
        os.write(slave_fd, TEST_STRING_2[:5])
        os.write(slave_fd, TEST_STRING_2[5:])
        s2 = _readline(master_fd)
        self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2))

        os.close(slave_fd)
        # closing master_fd can raise a SIGHUP if the process is
        # the session leader: we installed a SIGHUP signal handler
        # to ignore this signal.
        os.close(master_fd)
Exemplo n.º 8
0
    def test_basic(self):
        try:
            debug("Calling master_open()")
            master_fd, slave_name = pty.master_open()
            debug("Got master_fd '%d', slave_name '%s'" %
                  (master_fd, slave_name))
            debug("Calling slave_open(%r)" % (slave_name,))
            slave_fd = pty.slave_open(slave_name)
            debug("Got slave_fd '%d'" % slave_fd)
        except OSError:
            # " An optional feature could not be imported " ... ?
            raise unittest.SkipTest("Pseudo-terminals (seemingly) not functional.")

        self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')

        # Solaris requires reading the fd before anything is returned.
        # My guess is that since we open and close the slave fd
        # in master_open(), we need to read the EOF.

        # Ensure the fd is non-blocking in case there's nothing to read.
        blocking = os.get_blocking(master_fd)
        try:
            os.set_blocking(master_fd, False)
            try:
                s1 = os.read(master_fd, 1024)
                self.assertEqual(b'', s1)
            except OSError as e:
                if e.errno != errno.EAGAIN:
                    raise
        finally:
            # Restore the original flags.
            os.set_blocking(master_fd, blocking)

        debug("Writing to slave_fd")
        os.write(slave_fd, TEST_STRING_1)
        s1 = _readline(master_fd)
        self.assertEqual(b'I wish to buy a fish license.\n',
                         normalize_output(s1))

        debug("Writing chunked output")
        os.write(slave_fd, TEST_STRING_2[:5])
        os.write(slave_fd, TEST_STRING_2[5:])
        s2 = _readline(master_fd)
        self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2))

        os.close(slave_fd)
        os.close(master_fd)
Exemplo n.º 9
0
    def test_basic(self):
        try:
            debug("Calling master_open()")
            master_fd, slave_name = pty.master_open()
            debug("Got master_fd '%d', slave_name '%s'" %
                  (master_fd, slave_name))
            debug("Calling slave_open(%r)" % (slave_name, ))
            slave_fd = pty.slave_open(slave_name)
            debug("Got slave_fd '%d'" % slave_fd)
        except OSError:
            # " An optional feature could not be imported " ... ?
            raise unittest.SkipTest(
                "Pseudo-terminals (seemingly) not functional.")

        self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')

        # Solaris requires reading the fd before anything is returned.
        # My guess is that since we open and close the slave fd
        # in master_open(), we need to read the EOF.

        # Ensure the fd is non-blocking in case there's nothing to read.
        orig_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL)
        fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags | os.O_NONBLOCK)
        try:
            s1 = os.read(master_fd, 1024)
            self.assertEqual(b'', s1)
        except OSError as e:
            if e.errno != errno.EAGAIN:
                raise
        # Restore the original flags.
        fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags)

        debug("Writing to slave_fd")
        os.write(slave_fd, TEST_STRING_1)
        s1 = os.read(master_fd, 1024)
        self.assertEqual(b'I wish to buy a fish license.\n',
                         normalize_output(s1))

        debug("Writing chunked output")
        os.write(slave_fd, TEST_STRING_2[:5])
        os.write(slave_fd, TEST_STRING_2[5:])
        s2 = os.read(master_fd, 1024)
        self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2))

        os.close(slave_fd)
        os.close(master_fd)
Exemplo n.º 10
0
    def open(self, dev, terminal):
        if self.fd is not None:
            self.close()

        ipty = dev and dev.source_path or None
        logging.debug("Opening serial tty path: %s", ipty)
        if ipty is None:
            return

        self.fd = pty.slave_open(ipty)
        fcntl.fcntl(self.fd, fcntl.F_SETFL, os.O_NONBLOCK)
        self.source = GLib.io_add_watch(self.fd,
                            GLib.IO_IN | GLib.IO_ERR | GLib.IO_HUP,
                            self.display_data, terminal)

        # Save term settings & set to raw mode
        self.origtermios = termios.tcgetattr(self.fd)
        tty.setraw(self.fd, termios.TCSANOW)
Exemplo n.º 11
0
 def start_serial(self, var):
     """Create a pseudo serial port pair, and start listening for data on
     the server port. The slave port name is declared in an environment
     variable var, so drvAsynSerialPortConfigure should connect to $(var)"""
     if self.started:
         self.diagnostic("Server already started")
     else:
         self.inq, self.outq = Queue.Queue(), Queue.Queue()
         self.started = True
         # create a pseudo serial port, open slave port so listening doesn't fail
         self.mfd, sname = pty.master_open()
         self.sfd = pty.slave_open(sname)
         # start to listen on the master port
         self.__daemon(self.__serial_in)
         # start to respond to any messages put on the outq
         self.__daemon(self.__serial_out)
         # start the worker thread
         self.__daemon(self.__process)
         # put the portname for the IOC to connect to in var
         os.environ[var] = sname
Exemplo n.º 12
0
 def start_serial(self,var):
     """Create a pseudo serial port pair, and start listening for data on
     the server port. The slave port name is declared in an environment
     variable var, so drvAsynSerialPortConfigure should connect to $(var)"""
     if self.started:
         self.diagnostic("Server already started")
     else:
         self.inq, self.outq = Queue.Queue(), Queue.Queue()
         self.started = True
         # create a pseudo serial port, open slave port so listening doesn't fail
         self.mfd,sname = pty.master_open()
         self.sfd = pty.slave_open(sname)
         # start to listen on the master port
         self.__daemon(self.__serial_in)
         # start to respond to any messages put on the outq
         self.__daemon(self.__serial_out)    
         # start the worker thread
         self.__daemon(self.__process)
         # put the portname for the IOC to connect to in var
         os.environ[var] = sname
Exemplo n.º 13
0
 def test_basic(self):
     try:
         debug('Calling master_open()')
         master_fd, slave_name = pty.master_open()
         debug("Got master_fd '%d', slave_name '%s'" %
               (master_fd, slave_name))
         debug('Calling slave_open(%r)' % (slave_name, ))
         slave_fd = pty.slave_open(slave_name)
         debug("Got slave_fd '%d'" % slave_fd)
     except OSError:
         raise unittest.SkipTest(
             'Pseudo-terminals (seemingly) not functional.')
     self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty')
     blocking = os.get_blocking(master_fd)
     try:
         os.set_blocking(master_fd, False)
         try:
             s1 = os.read(master_fd, 1024)
             self.assertEqual(b'', s1)
         except OSError as e:
             if e.errno != errno.EAGAIN:
                 raise
     finally:
         os.set_blocking(master_fd, blocking)
     debug('Writing to slave_fd')
     os.write(slave_fd, TEST_STRING_1)
     s1 = os.read(master_fd, 1024)
     self.assertEqual(b'I wish to buy a fish license.\n',
                      normalize_output(s1))
     debug('Writing chunked output')
     os.write(slave_fd, TEST_STRING_2[:5])
     os.write(slave_fd, TEST_STRING_2[5:])
     s2 = os.read(master_fd, 1024)
     self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2))
     os.close(slave_fd)
     os.close(master_fd)
Exemplo n.º 14
0
        print msg
else:

    def debug(msg):
        pass


# Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
# because pty code is not too portable.

try:
    debug("Calling master_open()")
    master_fd, slave_name = pty.master_open()
    debug("Got master_fd '%d', slave_name '%s'" % (master_fd, slave_name))
    debug("Calling slave_open(%s)" % ` slave_name `)
    slave_fd = pty.slave_open(slave_name)
    debug("Got slave_fd '%d'" % slave_fd)
except OSError:
    # " An optional feature could not be imported " ... ?
    raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

if not os.isatty(slave_fd):
    raise TestFailed, "slave_fd is not a tty"

# IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
# differences (like extra whitespace, trailing garbage, etc.)

debug("Writing to slave_fd")
os.write(slave_fd, TEST_STRING_1)
s1 = os.read(master_fd, 1024)
sys.stdout.write(s1.replace("\r\n", "\n"))
Exemplo n.º 15
0
if verbose:
    def debug(msg):
        print msg
else:
    def debug(msg):
        pass

# Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
# because pty code is not too portable.

try:
    debug("Calling master_open()")
    master_fd, slave_name = pty.master_open()
    debug("Got master_fd '%d', slave_name '%s'"%(master_fd, slave_name))
    debug("Calling slave_open(%s)"%`slave_name`)
    slave_fd = pty.slave_open(slave_name)
    debug("Got slave_fd '%d'"%slave_fd)
except OSError:
    # " An optional feature could not be imported " ... ?
    raise TestSkipped, "Pseudo-terminals (seemingly) not functional."

if not os.isatty(slave_fd):
    raise TestFailed, "slave_fd is not a tty"

# IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
# differences (like extra whitespace, trailing garbage, etc.)

debug("Writing to slave_fd")
os.write(slave_fd, TEST_STRING_1)
s1 = os.read(master_fd, 1024)
sys.stdout.write(s1.replace("\r\n", "\n"))
Exemplo n.º 16
0
import pty, os, sys
from test_support import verbose, TestFailed, TestSkipped
TEST_STRING_1 = "I wish to buy a fish license.\n"
TEST_STRING_2 = "For my pet fish, Eric.\n"
if verbose:
    def debug(msg):
        print msg
else:
    def debug(msg):
        pass

# Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
# because pty code is not too portable.
try:
    debug("Calling master_open()")
    master_fd, slave_name = pty.master_open()
    debug("Got master_fd '%d', slave_name '%s'" % (master_fd, slave_name))
    debug("Calling slave_open(%s)" % ` slave_name `)
    slave_fd = pty.slave_open(slave_name)
    debug("Got slave_fd '%d'" % slave_fd)
except OSError:
    # " An optional feature could not be imported " ... ?
    raise TestSkipped, "Pseudo-terminals (seemingly) not functional."
if not os.isatty(slave_fd):
    raise TestFailed, "slave_fd is not a tty"
# IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
# differences (like extra whitespace, trailing garbage, etc.)
debug("Writing to slave_fd")
os.write(slave_fd, TEST_STRING_1)
s1 = os.read(master_fd, 1024)
Exemplo n.º 17
0
import pty, os, sys
from test_support import verbose, TestFailed, TestSkipped
TEST_STRING_1 = "I wish to buy a fish license.\n"
TEST_STRING_2 = "For my pet fish, Eric.\n"
if verbose:
    def debug(msg):
        print msg
else:
    def debug(msg):
        pass
# Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
# because pty code is not too portable.
try:
    debug("Calling master_open()")
    master_fd, slave_name = pty.master_open()
    debug("Got master_fd '%d', slave_name '%s'"%(master_fd, slave_name))
    debug("Calling slave_open(%s)"%`slave_name`)
    slave_fd = pty.slave_open(slave_name)
    debug("Got slave_fd '%d'"%slave_fd)
except OSError:
    # " An optional feature could not be imported " ... ?
    raise TestSkipped, "Pseudo-terminals (seemingly) not functional."
if not os.isatty(slave_fd):
    raise TestFailed, "slave_fd is not a tty"
# IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
# differences (like extra whitespace, trailing garbage, etc.)
debug("Writing to slave_fd")
os.write(slave_fd, TEST_STRING_1)
s1 = os.read(master_fd, 1024)
sys.stdout.write(s1.replace("\r\n", "\n"))