Exemplo n.º 1
0
def test_ser2net_termios(name, handler, config, io1str, io2str):
    """Test the settings of ser2net termios

    Set up a ser2net daemon and two connections, call the given handler
    which will return a termios set.  Then fetch the termios from io2
    and make sure they match.
    """
    print("termios %s:\n  config=%s  io1=%s\n  io2=%s" %
          (name, config, io1str, io2str))

    o = genio.alloc_genio_selector();
    ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str)
    try:
        io1.handler.set_compare("12345")
        if (io1.handler.wait_timeout(1000)):
            raise Exception("%s: %s: Timed out waiting for banner" %
                            (name, io1.handler.name))
        sio2 = io2.cast_to_sergenio()
        io1.read_cb_enable(True)
        io2.read_cb_enable(True)

        expected_termios = handler.op(io1, io2)

        io2_rem_termios = sio2.get_remote_termios()

        c = compare_termios(expected_termios, io2_rem_termios)
        if (c != 0):
            raise Exception("Termios mismatch at %d\nExpected: %s\nBut got  %s" %
                            (c, str(expected_termios), str(io2_rem_termios)))

    finally:
        utils.finish_2_ser2net(ser2net, io1, io2, handle_except = False)
    print("  Success!")
Exemplo n.º 2
0
def test_write_drain(name,
                     data,
                     config,
                     io1str,
                     io2str,
                     timeout=3000,
                     initial_write_io1=None):
    """Test that close does not loose data

    This function takes a name (for reporting), some data to transfer,
    a config file for ser2net, and writes the data and immediately
    closes the connection after the write succeeds and makes sure all
    the written data gets there.

    If initial_write_io1 is not None, the string is written to io1 when
    transferring from io2 to io1.  This is a hack for UDP, ser2net will
    not be connected to the udp port until it receives some data from
    it.
    """
    print("Write drain %s:\n  config=%s  io1=%s\n  io2=%s" %
          (name, config, io1str, io2str))

    o = genio.alloc_genio_selector()
    ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str)
    try:
        print("  io1 to io2")
        utils.test_write_drain(io1, io2, data, timeout=timeout)
    finally:
        utils.finish_2_ser2net(ser2net, io1, io2)

    ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str)
    try:
        print("  io2 to io1")
        if initial_write_io1:
            io1.handler.set_write_data(initial_write_io1)
            io2.handler.set_compare(initial_write_io1)
            if io1.handler.wait_timeout(1000):
                raise Exception("%s: Timed out on dummy write completion" %
                                io1.handler.name)
            if io2.handler.wait_timeout(1000):
                raise Exception("%s: Timed out on dummy read completion" %
                                io1.handler.name)
        utils.test_write_drain(io2, io1, data, timeout=timeout)
    finally:
        utils.finish_2_ser2net(ser2net, io1, io2)

    print("  Success!")
    return
Exemplo n.º 3
0
def test_rts():
    config = "BANNER:b:12345\n    3023:telnet:100:/dev/ttyPipeA0:b remctl\n"
    io1str = "telnet,tcp,localhost,3023"
    io2str = "termios,/dev/ttyPipeB0,9600N81"

    print("termios rts rfc2217:\n  config=%s  io1=%s\n  io2=%s" %
          (config, io1str, io2str))

    o = genio.alloc_genio_selector()
    ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str)
    sio1 = io1.cast_to_sergenio()
    sio2 = io2.cast_to_sergenio()
    io1.handler.set_compare("12345")
    if (io1.handler.wait_timeout(1000)):
        raise Exception("%s: %s: Timed out waiting for banner" %
                        (name, io1.handler.name))

    io1.read_cb_enable(True)
    io2.read_cb_enable(True)

    sio2.set_remote_null_modem(False)

    val = sio1.sg_rts_s(0)
    if (val != genio.SERGENIO_RTS_ON):
        raise Exception("Expected RTS on at start, got %d" % val)
    val = sio2.get_remote_modem_ctl()
    if (not (val & genio.SERGENIO_TIOCM_RTS)):
        raise Exception("Expected remote RTS on at start")

    val = sio1.sg_rts_s(genio.SERGENIO_RTS_OFF)
    if (val != genio.SERGENIO_RTS_OFF):
        raise Exception("Expected RTS off")
    val = sio2.get_remote_modem_ctl()
    if (val & genio.SERGENIO_TIOCM_RTS):
        raise Exception("Expected remote RTS off")

    val = sio1.sg_rts_s(genio.SERGENIO_RTS_ON)
    if (val != genio.SERGENIO_RTS_ON):
        raise Exception("Expected RTS on")
    val = sio2.get_remote_modem_ctl()
    if (not (val & genio.SERGENIO_TIOCM_RTS)):
        raise Exception("Expected remote RTS on")

    utils.finish_2_ser2net(ser2net, io1, io2, handle_except=False)
    print("  Success!")
    return
Exemplo n.º 4
0
def test_transfer(name, data, config, io1str, io2str, timeout=1000):
    """Test a transfer between two genio objects

    This function takes a name (for reporting), some data to transfer,
    a config file for ser2net, and transfers the data one direction,
    then the other, then both ways at the same time.
    """
    print("Transfer %s:\n  config=%s  io1=%s\n  io2=%s" %
          (name, config, io1str, io2str))

    o = genio.alloc_genio_selector()
    ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str)
    try:
        print("  io1 to io2")
        utils.test_dataxfer(io1, io2, data, timeout=timeout)
        print("  io2 to io1")
        utils.test_dataxfer(io2, io1, data, timeout=timeout)
        print("  bidirectional")
        utils.test_dataxfer_simul(io1, io2, data, timeout=timeout)
    finally:
        utils.finish_2_ser2net(ser2net, io1, io2)
    print("  Success!")
    return
Exemplo n.º 5
0
#!/usr/bin/python
import utils
import genio

o = genio.alloc_genio_selector()


def t1():
    print("Test echo device")
    io = utils.alloc_io(o, "termios,/dev/ttyEcho0,38400")
    utils.test_dataxfer(io, io, "This is a test string!")


def t2():
    print("Test serial pipe device")
    io1 = utils.alloc_io(o, "termios,/dev/ttyPipeA0,9600")
    io2 = utils.alloc_io(o, "termios,/dev/ttyPipeB0,9600")
    utils.test_dataxfer(io1, io2, "This is a test string!")


class TestAccept:
    def __init__(self,
                 o,
                 io1,
                 iostr,
                 bufsize,
                 tester,
                 name=None,
                 io1_dummy_write=None):
        self.o = o
        if (name):