def test_write_drain(name, data, config, io1str, io2str, timeout=3000, initial_write_io1=None, switch_delay=0.0): """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)) 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") end = time.time() + switch_delay while (time.time() < end): gensio.waiter(o).wait_timeout(1, int(switch_delay / 5)) 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) == 0: raise Exception("%s: Timed out on dummy write completion" % io1.handler.name) if io2.handler.wait_timeout(1000) == 0: 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
def __init__(self, o, num_channels=10): self.o = o self.channels = [None for x in range(num_channels)] self.waiter = gensio.waiter(o) self.expect_close = -1 self.op_count = 0 return
def finish_2_ser2net(ser2net, io1, io2, handle_except=True): if io1.closeme: if io1.is_accepter and io1.handler.io is not None: try: io_close(io1.handler.io) except Exception as E: pass try: io_close(io1) except: pass else: io1.handler.ignore_input = True if io2.closeme: try: io_close(io2) except: pass else: io2.handler.ignore_input = True if handle_except and sys.exc_info()[0]: g = gensio.waiter(ser2net.o) print("Exception occurred, waiting a bit for things to clear.") g.wait_timeout(1, 2000) ser2net.terminate() return
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()
def __init__(self, o, iostr, name = None, chunksize=10240, io = None, password = None, expect_remclose = True): """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.compared = 0 self.to_compare = None self.compared_oob = 0 self.to_compare_oob = None self.to_waitfor = None self.expecting_modemstate = False self.expecting_linestate = False self.expecting_remclose = expect_remclose self.expected_server_cb = None self.expected_server_value = 0 self.expected_server_return = 0 self.expected_sig_server_cb = False self.expected_sig_server_val = None self.ignore_input = False self.stream = None self.password = password if (io): self.io = io io.set_cbs(self) else: gensios_enabled.check_iostr_gensios(iostr) self.io = gensio.gensio(o, iostr, self) self.io.handler = self self.chunksize = chunksize self.debug = 0 return
def __init__(self, o, io1, io2, tester, name, do_close=True, expected_raddr1=None, expected_raddr2=None, timeout=None): self.o = o self.name = name self.io1 = io1 self.io2 = io2 self.waiter = gensio.waiter(o) io1.open(self) io2.open(self) self.wait(2) if expected_raddr1: check_raddr(io1, self.name, expected_raddr1) if expected_raddr2: check_raddr(io2, self.name, expected_raddr2) if timeout is None: tester(self.io1, self.io2) else: tester(self.io1, self.io2, timeout=timeout) if do_close: self.close()
def __init__(self, o, iostr, name=None, chunksize=10240, io=None): """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 if (io): self.io = io io.set_cbs(self) else: self.io = gensio.gensio(o, iostr, self) self.io.handler = self self.chunksize = chunksize self.debug = 0 return
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()
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()
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()
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()
def __init__(self, o): self.waiter = gensio.waiter(o)
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()
def __init__(self): self.mdns_closed = False self.watch_closed = False self.waiter = gensio.waiter(utils.o)
def __init__(self, outbuf): self.outbuf = outbuf + "\n" self.in_close = False self.incount = 0 self.waiter = gensio.waiter(o) return
import ipmisimdaemon import gensio import utils o = utils.o isim = ipmisimdaemon.IPMISimDaemon(o) test_transfer( "basic ipmisol", "This is a test!", ("connection: &con", " accepter: tcp,3023", " connector: ipmisol,lan -U ipmiusr -P test -p %d localhost,9600" % ipmisimdaemon.ipmisol_port), "tcp,localhost,3023", "serialdev,/dev/ttyPipeA0,9600N81") # Give the old ipmi_sim a little time to shut down. gensio.waiter(o).wait_timeout(1, 1000) # Note that ipmi_sim messes with the modem state lines, so adding # LOCAL is required on termios. Also, we had to add a small delay # after the opens are complete to give time for ser2net to connect to # ipmi_sim and set things up. Otherwise it would often lose the first # couple of characters going from io2 to io1. test_write_drain( "basic tcp", "This is a write drain test!", ("connection: &con", " accepter: tcp,3023", " connector: ipmisol,lan -U ipmiusr -P test -p %d localhost,9600" % ipmisimdaemon.ipmisol_port), "tcp,localhost,3023", "serialdev,/dev/ttyPipeA0,9600N81,LOCAL", switch_delay=0.25)
def __init__(self): self.ios = [] self.waiter = gensio.waiter(o) self.in_shutdown = False return
def __init__(self, o, sigval): self.sigval = sigval self.waiter = gensio.waiter(o) return
def __init__(self): self.done = False self.check = None self.print = True self.waiter = gensio.waiter(utils.o)