예제 #1
0
    def __init__(self, o, accstr, acc2str, tester):
        self.o = o
        self.name = accstr
        self.io1 = None
        self.io2 = None
        self.waiter = gensio.waiter(o)
        gensios_enabled.check_iostr_gensios(accstr)

        self.acc = gensio.gensio_accepter(o, accstr, self)
        self.acc.startup()

        port = self.acc.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                                gensio.GENSIO_ACC_CONTROL_LPORT, "0")
        acc2str = acc2str + port
        self.acc2 = gensio.gensio_accepter(o, acc2str, self)

        print(" First connection")
        self.expect_connects = True
        self.acc2.startup()
        self.wait()
        tester(self.io1, self.io2)
        self.close()
        print(" Second connection")
        self.wait()
        tester(self.io1, self.io2)

        print(" Disable connections")
        self.expect_connects = False
        self.acc2.set_accept_callback_enable_cb(False, self)
        self.wait()
        self.close()

        # Make sure no connections come in
        if self.waiter.wait_timeout(1, 200) != 0:
            raise Exception("Got wakeup when nothing should happen")

        print(" Re-enable connections")
        self.expect_connects = True
        self.acc2.set_accept_callback_enable(True)
        self.wait()
        tester(self.io1, self.io2)

        print(" Disable connections synchronous")
        self.expect_connects = False
        self.acc2.set_accept_callback_enable_s(False)
        self.close()

        # Make sure no connections come in
        if self.waiter.wait_timeout(1, 200) != 0:
            raise Exception("Got wakeup when nothing should happen")

        print(" Re-enable connections")
        self.expect_connects = True
        self.acc2.set_accept_callback_enable(True)
        self.wait()
        tester(self.io1, self.io2)

        self.acc.shutdown_s()
        self.acc2.shutdown_s()
        self.close()
예제 #2
0
 def __init__(self,
              o,
              iostr,
              io2str,
              io3str,
              tester,
              name=None,
              io1_dummy_write=None,
              CA=None,
              do_close=True,
              auth_begin_rv=gensio.GE_NOTSUP,
              expect_pw=None,
              expect_pw_rv=gensio.GE_NOTSUP,
              password=None):
     self.o = o
     if (name):
         self.name = name
     else:
         self.name = iostr
     self.waiter = gensio.waiter(o)
     self.acc = gensio.gensio_accepter(o, iostr, self)
     self.acc.startup()
     self.acc2 = gensio.gensio_accepter(o, io2str, self)
     self.acc2.startup()
     self.io1 = self.acc2.str_to_gensio(io3str, None)
     self.io2 = None
     self.CA = CA
     h = utils.HandleData(o, io3str, io=self.io1, password=password)
     self.auth_begin_rv = auth_begin_rv
     self.expect_pw = expect_pw
     self.expect_pw_rv = expect_pw_rv
     try:
         self.io1.open_s()
     except:
         self.io1 = None
         self.close()
         raise
     if (io1_dummy_write):
         # For UDP, kick start things.
         self.io1.write(io1_dummy_write, None)
     try:
         self.wait()
     except:
         self.close()
         raise
     if (io1_dummy_write):
         self.io2.handler.set_compare(io1_dummy_write)
         if (self.io2.handler.wait_timeout(1000) == 0):
             raise Exception(
                 ("%s: %s: " % ("test_accept", self.io2.handler.name)) +
                 ("Timed out waiting for dummy read at byte %d" %
                  self.io2.handler.compared))
     tester(self.io1, self.io2)
     if do_close:
         self.close()
예제 #3
0
 def __init__(self, o, iostr, io2str, io3str, tester, name = None,
              io1_dummy_write = None, CA=None, do_close = True,
              auth_begin_rv = gensio.GE_NOTSUP, expect_pw = None,
              expect_pw_rv = gensio.GE_NOTSUP, password = None,
              expect_remclose = True, use_port = True):
     self.o = o
     if (name):
         self.name = name
     else:
         self.name = iostr
     self.waiter = gensio.waiter(o)
     gensios_enabled.check_iostr_gensios(iostr)
     gensios_enabled.check_iostr_gensios(io2str)
     self.acc = gensio.gensio_accepter(o, iostr, self);
     self.acc.startup()
     self.acc2 = gensio.gensio_accepter(o, io2str, self);
     self.acc2.startup()
     if (use_port):
         port = self.acc.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                                 gensio.GENSIO_ACC_CONTROL_LPORT, "0")
         io3str = io3str + port
     self.io1 = self.acc2.str_to_gensio(io3str, None);
     self.io2 = None
     self.CA = CA
     h = HandleData(o, io3str, io = self.io1, password = password,
                          expect_remclose = expect_remclose)
     self.auth_begin_rv = auth_begin_rv
     self.expect_pw = expect_pw
     self.expect_pw_rv = expect_pw_rv
     try:
         self.io1.open_s()
     except:
         self.io1 = None
         self.close()
         raise
     self.io1.read_cb_enable(True)
     if (io1_dummy_write):
         # For UDP, kick start things.
         self.io1.write(io1_dummy_write, None)
     try:
         self.wait()
     except:
         self.close()
         raise
     if (io1_dummy_write):
         self.io2.handler.set_compare(io1_dummy_write)
         if (self.io2.handler.wait_timeout(1000) == 0):
             raise Exception(("%s: %s: " % ("test_accept",
                                            self.io2.handler.name)) +
                     ("Timed out waiting for dummy read at byte %d" %
                      self.io2.handler.compared))
     tester(self.io1, self.io2)
     if do_close:
         self.close()
예제 #4
0
 def __init__(self,
              o,
              io1,
              iostr,
              tester,
              name=None,
              io1_dummy_write=None,
              do_close=True):
     self.o = o
     if (name):
         self.name = name
     else:
         self.name = iostr
     self.io1 = io1
     self.io2 = None
     self.waiter = gensio.waiter(o)
     self.acc = gensio.gensio_accepter(o, iostr, self)
     self.acc.startup()
     io1.open_s()
     if (io1_dummy_write):
         # For UDP, kick start things.
         io1.write(io1_dummy_write, None)
     self.wait()
     if (io1_dummy_write):
         self.io2.handler.set_compare(io1_dummy_write)
         if (self.io2.handler.wait_timeout(1000) == 0):
             raise Exception(
                 ("%s: %s: " % ("test_accept", self.io2.handler.name)) +
                 ("Timed out waiting for dummy read at byte %d" %
                  self.io2.handler.compared))
     tester(self.io1, self.io2)
     if do_close:
         self.close()
예제 #5
0
def test_sync_gensio_accepter(o):
    print("Testing sync accept")

    gensios_enabled.check_iostr_gensios("tcp")
    a = gensio.gensio_accepter(o, "tcp,0", None)
    a.set_sync()
    a.startup()
    port = a.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                     gensio.GENSIO_ACC_CONTROL_LPORT, "0")

    sa = SyncEvent()
    (io, time) = a.accept_s_timeout(o, sa, 1)
    if io != None or time != 0:
        raise Exception("accept_s_timeout didn't time out")

    sg = SyncEvent()
    gensios_enabled.check_iostr_gensios("tcp")
    g = gensio.gensio(o, "tcp,localhost," + port, sg)
    g.open(sg)

    (io, time) = a.accept_s_timeout(o, sa, 1000)
    if io == None or time == 0:
        raise Exception("accept_s_timeout timed out")

    return
예제 #6
0
    def __init__(self,
                 o,
                 io1str,
                 accstr,
                 tester,
                 name=None,
                 io1_dummy_write=None,
                 do_close=True,
                 expected_raddr=None,
                 expected_acc_laddr=None,
                 chunksize=10240,
                 get_port=True,
                 except_on_log=False):
        self.o = o
        self.except_on_log = except_on_log
        if (name):
            self.name = name
        else:
            self.name = accstr
        self.io2 = None
        self.waiter = gensio.waiter(o)
        gensios_enabled.check_iostr_gensios(accstr)
        self.acc = gensio.gensio_accepter(o, accstr, self)
        self.acc.startup()
        self.waiter.service(1)  # Wait a bit for the accepter to start up.

        if get_port:
            port = self.acc.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                                    gensio.GENSIO_ACC_CONTROL_LPORT, "0")
        else:
            port = ""
        io1str = io1str + port
        io1 = alloc_io(o, io1str, do_open=False, chunksize=chunksize)
        self.io1 = io1
        if expected_acc_laddr:
            expected_acc_laddr = expected_acc_laddr + port
        if expected_raddr:
            expected_raddr = expected_raddr + port

        if expected_acc_laddr:
            check_laddr(self.acc, self.name, expected_acc_laddr)
        io1.open_s()
        if expected_raddr:
            check_raddr(io1, self.name, expected_raddr)
        if (io1_dummy_write):
            # For UDP, kick start things.
            io1.write(io1_dummy_write, None)
        self.wait()
        if (io1_dummy_write):
            self.io2.handler.set_compare(io1_dummy_write)
            if (self.io2.handler.wait_timeout(1000) == 0):
                raise Exception(
                    ("%s: %s: " % ("test_accept", self.io2.handler.name)) +
                    ("Timed out waiting for dummy read at byte %d" %
                     self.io2.handler.compared))
        tester(self.io1, self.io2)
        if do_close:
            self.close()
예제 #7
0
    def __init__(self,
                 o,
                 iostr,
                 name=None,
                 chunksize=10240,
                 io=None,
                 io_is_accepter=False):
        """Start a gensio object with this handler"""
        if (name):
            self.name = name
        else:
            self.name = iostr
        self.waiter = gensio.waiter(o)
        self.to_write = None
        self.to_compare = None
        self.to_waitfor = None
        self.expecting_modemstate = False
        self.expecting_linestate = False
        self.expected_server_cb = None
        self.expected_server_value = 0
        self.expected_server_return = 0
        self.ignore_input = False
        self.expected_err = None
        self.io = None
        self.acc = None
        if io:
            if io_is_accepter:
                self.acc = io
            else:
                self.io = io
            io.set_cbs(self)
        else:
            if io_is_accepter:
                self.acc = gensio.gensio_accepter(o, iostr, self)
            else:
                self.io = gensio.gensio(o, iostr, self)

        if io_is_accepter:
            self.acc.handler = self
        else:
            self.io.handler = self
        self.chunksize = chunksize
        self.debug = 0
        return
예제 #8
0
def test_sync_gensio_accepter(o):
    a = gensio.gensio_accepter(o, "tcp,3023", None)
    a.set_sync()
    a.startup()

    sa = SyncEvent()
    (io, time) = a.accept_s_timeout(o, sa, 1)
    if io != None or time != 0:
        raise Exception("accept_s_timeout didn't time out")

    sg = SyncEvent()
    g = gensio.gensio(o, "tcp,localhost,3023", sg)
    g.open(sg)

    (io, time) = a.accept_s_timeout(o, sa, 1000)
    if io == None or time == 0:
        raise Exception("accept_s_timeout timed out")

    return
예제 #9
0
    def __init__(self, o, io1str, accstr, tester, name = None,
                 io1_dummy_write = None, do_close = True,
                 expected_raddr = None, expected_acc_laddr = None,
                 chunksize = 10240, get_port = True, except_on_log = False,
                 is_sergensio = False):
        self.o = o
        self.except_on_log = except_on_log
        if (name):
            self.name = name
        else:
            self.name = accstr
        if debug:
            print("TestAccept " + self.name);
        self.io2 = None
        self.waiter = gensio.waiter(o)
        gensios_enabled.check_iostr_gensios(accstr)
        self.acc = gensio.gensio_accepter(o, accstr, self);
        if is_sergensio:
            sga = self.acc.cast_to_sergensio_acc()
            if not sga:
                raise Exception("Cast to sergensio_accepter failed");
            ga = sga.cast_to_gensio_acc()
            del sga
            del ga
        else:
            sga = None
            try:
                sga = self.acc.cast_to_sergensio_acc()
            except:
                pass
            if sga:
                raise Exception("Cast to sergensio_accepter succeeded");
        if debug:
            print("acc startup");
        self.acc.startup()
        self.waiter.service(1) # Wait a bit for the accepter to start up.

        if get_port:
            port = self.acc.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                                    gensio.GENSIO_ACC_CONTROL_LPORT, "0")
        else:
            port = ""
        io1str = io1str + port
        io1 = alloc_io(o, io1str, do_open = False,
                       chunksize = chunksize)
        self.io1 = io1
        if expected_acc_laddr:
            expected_acc_laddr = expected_acc_laddr + port
        if expected_raddr:
            expected_raddr = expected_raddr + port

        if expected_acc_laddr:
            check_laddr(self.acc, self.name, expected_acc_laddr)
        if debug:
            print("io1 open " + self.name);
        io1.open_s()
        if expected_raddr:
            check_raddr(io1, self.name, expected_raddr)
        if (io1_dummy_write):
            # For UDP, kick start things.
            io1.write(io1_dummy_write, None)
        if debug:
            print("wait 1 " + self.name);
        # Wait for the accept to happen
        if (self.wait_timeout(1000) == 0):
            raise Exception(("%s: %s: " % ("test_accept", self.name)) +
                    ("Timed out waiting for initial connection"))
        if (io1_dummy_write):
            self.io2.handler.set_compare(io1_dummy_write)
            if (self.io2.handler.wait_timeout(1000) == 0):
                raise Exception(("%s: %s: " % ("test_accept",
                                               self.io2.handler.name)) +
                        ("Timed out waiting for dummy read at byte %d" %
                         self.io2.handler.compared))
        tester(self.io1, self.io2)
        if do_close:
            self.close()
예제 #10
0
        self.check_finish()
        return

    def shutdown_done(self, acc):
        self.acc = None
        self.check_finish()
        return

    def shutdown(self, ioev):
        if self.in_shutdown:
            return
        self.in_shutdown = True
        self.acc.shutdown(self)
        for i in self.ios:
            if i != ioev:
                # The caller will close itself, let it finish its write
                i.io.close(i)

    def wait(self):
        self.waiter.wait(1)

if len(sys.argv) < 2:
    print("No gensio supplied on commandline")
    sys.exit(1)

accev = AccEvent()
accev.acc = gensio.gensio_accepter(o, sys.argv[1], accev)
accev.acc.startup()

accev.wait()
예제 #11
0
def test_mux_limits():
    print("Testing mux limits")
    handlemuxacc = MuxHandler(o, num_channels=10)
    muxacc = gensio.gensio_accepter(o, "mux(max_channels=10),tcp,3023",
                                    handlemuxacc)
    muxacc.startup()

    handlemuxcl = MuxHandler(o, num_channels=10)
    muxcl = gensio.gensio(o,
                          "mux(service=0,max_channels=10),tcp,localhost,3023",
                          handlemuxcl)
    handlemuxcl.channels[0] = muxcl
    handlemuxacc.set_op_count(1)
    handlemuxcl.set_op_count(1)
    muxcl.open(handlemuxcl)

    if (handlemuxcl.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")
    if (handlemuxacc.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")

    print("Opening all channels")
    handlemuxcl.set_op_count(9)
    handlemuxacc.set_op_count(9)
    for i in range(1, 10):
        handlemuxcl.channels[i] = muxcl.alloc_channel(["service=%d" % i],
                                                      handlemuxcl)
        handlemuxcl.channels[i].open(handlemuxcl)

    print("Waiting for channels")
    if (handlemuxcl.wait(timeout=2000) == 0):
        raise utils.HandlerException("Timeout waiting for client open finish")
    if (handlemuxacc.wait(timeout=2000) == 0):
        raise utils.HandlerException("Timeout waiting for server open finish")

    print("Trying an open that should fail")
    try:
        muxcl.alloc_channel(["service=%d" % 10], handlemuxcl)
    except Exception as err:
        if str(err) != "gensio:alloc_channel: Object was already in use":
            raise utils.HandlerException("Got wrong error: %s" % str(err))
    else:
        raise utils.HandlerException(
            "No exception when opening too many channels")

    print("Close one channel")
    handlemuxcl.set_expect_close(3)
    handlemuxacc.set_expect_close(3)
    handlemuxcl.set_op_count(1)
    handlemuxacc.set_op_count(1)
    handlemuxacc.channels[3].close(handlemuxacc)

    if (handlemuxcl.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client close finish")
    if (handlemuxacc.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single server close finish")

    print("Open that channel again")
    handlemuxacc.set_op_count(1)
    handlemuxcl.set_op_count(1)
    handlemuxcl.channels[3] = muxcl.alloc_channel(["service=3"], handlemuxcl)
    handlemuxcl.channels[3].open(handlemuxcl)

    if (handlemuxcl.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for client singe close finish")
    if (handlemuxacc.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for server single close finish")

    print("Close all channels")
    handlemuxcl.set_expect_close(-1)
    handlemuxacc.set_expect_close(-1)
    handlemuxcl.set_op_count(10)
    handlemuxacc.set_op_count(10)
    for i in range(0, 10):
        if (i % 2 == 0):
            handlemuxcl.channels[i].close(handlemuxcl)
        else:
            handlemuxacc.channels[i].close(handlemuxacc)

    if (handlemuxcl.wait(timeout=2000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for client all close finish")
    if (handlemuxacc.wait(timeout=2000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for server all close finish")

    print("Re-open the mux")
    handlemuxacc.set_op_count(1)
    handlemuxcl.set_op_count(1)
    muxcl.open(handlemuxcl)
    if (handlemuxcl.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")
    if (handlemuxacc.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")

    print("Re-close the mux")
    handlemuxacc.set_op_count(1)
    handlemuxcl.set_op_count(1)
    handlemuxcl.channels[0] = muxcl
    muxcl.close(handlemuxcl)
    if (handlemuxcl.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")
    if (handlemuxacc.wait(timeout=1000) == 0):
        raise utils.HandlerException(
            "Timeout waiting for single client open finish")

    return
예제 #12
0
        io.read_cb_enable(True)
        self.dec_op_count()
        return

    def wait(self, count=1, timeout=0):
        if (timeout > 0):
            return self.waiter.wait_timeout(count, timeout)
        else:
            return self.waiter.wait(count)
        return


print("Testing mux limits")
handlemuxacc = MuxHandler(o, num_channels=10)
gensios_enabled.check_iostr_gensios("mux,tcp")
muxacc = gensio.gensio_accepter(o, "mux(max_channels=10),tcp,0", handlemuxacc)
muxacc.startup()
port = muxacc.control(gensio.GENSIO_CONTROL_DEPTH_FIRST, True,
                      gensio.GENSIO_ACC_CONTROL_LPORT, "0")

handlemuxcl = MuxHandler(o, num_channels=10)
muxcl = gensio.gensio(o,
                      "mux(service=0,max_channels=10),tcp,localhost," + port,
                      handlemuxcl)
handlemuxcl.channels[0] = muxcl
handlemuxacc.set_op_count(1)
handlemuxcl.set_op_count(1)
muxcl.open(handlemuxcl)

if (handlemuxcl.wait(timeout=1000) == 0):
    raise HandlerException("Timeout waiting for single client open finish")