def test_serial_pipe_device(): print("Test serial pipe device") io1 = utils.alloc_io(o, "serialdev,/dev/ttyPipeA0,9600") io2 = utils.alloc_io(o, "serialdev,/dev/ttyPipeB0,9600") utils.test_dataxfer(io1, io2, "This is a test string!") utils.io_close(io1) utils.io_close(io2) print(" Success!")
def test_ipmisol_small(): print("Test ipmisol small") isim = ipmisimdaemon.IPMISimDaemon(o) io1 = utils.alloc_io(o, "serialdev,/dev/ttyPipeA0,9600") io2 = utils.alloc_io( o, "ipmisol,lan -U ipmiusr -P test -p 9001 localhost,9600") utils.test_dataxfer(io1, io2, "This is a test string!") utils.io_close(io1) utils.io_close(io2) print(" Success!")
def test_ipmisol_large(): print("Test ipmisol large") isim = ipmisimdaemon.IPMISimDaemon(o) io1 = utils.alloc_io(o, "serialdev,/dev/ttyPipeA0,115200") io2 = utils.alloc_io( o, "ipmisol,lan -U ipmiusr -P test -p 9001 localhost,115200") rb = gensio.get_random_bytes(104857) utils.test_dataxfer(io1, io2, rb, timeout=10000) utils.io_close(io1) utils.io_close(io2) print(" Success!")
def ta_sctp(): print("Test accept sctp") io1 = utils.alloc_io(o, "sctp,localhost,3023", do_open=False) TestAccept(o, io1, "sctp,3023", do_test) c = io1.control(0, True, gensio.GENSIO_CONTROL_STREAMS, None) if c != "instreams=1,ostreams=1": raise Exception("Invalid stream settings: %s" % c)
def tc_small_relpkt(): print("Test small relpkt over msgdelim over serial") io1 = utils.alloc_io( o, "relpkt(mode=server),msgdelim,serialdev,/dev/ttyPipeA0", do_open=False) io2 = utils.alloc_io(o, "relpkt,msgdelim,serialdev,/dev/ttyPipeB0", do_open=False) TestConCon(o, io1, io2, do_small_test, "relpkt1", expected_raddr1="/dev/ttyPipeA0,9600N81 RTSHI DTRHI", expected_raddr2="/dev/ttyPipeB0,9600N81 RTSHI DTRHI")
def ta_certauth_tcp(): print("Test accept certauth-ssl-tcp") io1 = utils.alloc_io( o, "certauth(cert=%s/clientcert.pem,key=%s/clientkey.pem,username=testuser,service=myservice),ssl(CA=%s/CA.pem),tcp,localhost,3023" % (utils.srcdir, utils.srcdir, utils.srcdir), do_open=False) ta = TestAccept( o, io1, "certauth(CA=%s/clientcert.pem),ssl(key=%s/key.pem,cert=%s/cert.pem),tcp,3023" % (utils.srcdir, utils.srcdir, utils.srcdir), do_test, do_close=False) cn = ta.io2.control(0, True, gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, "-1,CN") i = cn.index(',') cn2 = cn[i + 1:] i = cn2.index(',') if cn2[0:i] != "CN": raise Exception("Invalid object name, expected %s, got %s" % ("CN", cn2[0:i])) if cn2[i + 1:] != "gensio.org": raise Exception( "Invalid common name in certificate, expected %s, got %s" % ("gensio.org", cn2[i + 1:])) username = ta.io2.control(0, True, gensio.GENSIO_CONTROL_USERNAME, None) if username != "testuser": raise Exception("Invalid username, expected %s, got %s" % ("testuser", username)) service = ta.io2.control(0, True, gensio.GENSIO_CONTROL_SERVICE, None) if service != "myservice": raise Exception("Invalid service, expected %s, got %s" % ("myservice", service)) ta.close()
def test_echo_gensio(): print("Test echo gensio") io = utils.alloc_io(o, "echo") check_raddr(io, "echo", "echo") utils.test_dataxfer(io, io, "This is a test string!") utils.io_close(io) print(" Success!")
def test_mux_tcp_large(): print("Test mux tcp large") io1 = utils.alloc_io(o, "mux,tcp,localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "mux,tcp,3023", do_large_test)
def test_telnet_small(): print("Test telnet small") io1 = utils.alloc_io(o, "telnet,tcp,localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "telnet(rfc2217=true),3023", do_small_test)
def test_mux_sctp_small(): print("Test mux sctp small") io1 = utils.alloc_io(o, "mux,sctp,localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "mux,sctp,3023", do_small_test)
def test_echo_device(): print("Test echo device") io = utils.alloc_io(o, "serialdev,/dev/ttyEcho0,38400") check_raddr(io, "echo device", "/dev/ttyEcho0,38400N81 RTSHI DTRHI") utils.test_dataxfer(io, io, "This is a test string!") utils.io_close(io) print(" Success!")
def test_pty_basic(): print("Test pty basic echo") io = utils.alloc_io(o, "pty,cat", chunksize=64) check_raddr(io, "pty basic", '"cat"') utils.test_dataxfer(io, io, "This is a test string!") utils.io_close(io) print(" Success!")
def test_stdio_small(): print("Test stdio small echo") rb = gensio.get_random_bytes(512) io = utils.alloc_io(o, "stdio,cat", chunksize=64) utils.test_dataxfer(io, io, rb) utils.io_close(io) print(" Success!")
def test_sctp_streams(): print("Test sctp streams") io1 = utils.alloc_io(o, "sctp(instreams=2,ostreams=3),localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "sctp(instreams=3,ostreams=2),3023", do_stream_test)
def ta_ssl_tcp(): print("Test accept ssl-tcp") io1 = utils.alloc_io(o, "ssl(CA=%s/CA.pem),tcp,localhost,3024" % utils.srcdir, do_open=False) ta = TestAccept( o, io1, "ssl(key=%s/key.pem,cert=%s/cert.pem,CA=%s/CA.pem),3024" % (utils.srcdir, utils.srcdir, utils.srcdir), 1024, do_test)
def ta_sctp(): print("Test accept sctp") io1 = utils.alloc_io(o, "sctp,localhost,3023", do_open=False) # FIXME - the raddr and laddr areq not tested here, it's hard to # know what it would be because of sctp multihoming. TestAccept(o, io1, "sctp,3023", do_test, expected_acc_port="3023") c = io1.control(0, True, gensio.GENSIO_CONTROL_STREAMS, None) if c != "instreams=1,ostreams=1": raise Exception("Invalid stream settings: %s" % c)
def test_rs485(): io1str = "serialdev,/dev/ttyPipeA0,9600N81,LOCAL,rs485=103:495" io2str = "serialdev,/dev/ttyPipeB0,9600N81" print("serialdev rs485:\n io1=%s\n io2=%s" % (io1str, io2str)) io1 = utils.alloc_io(o, io1str) io2 = utils.alloc_io(o, io2str) rs485 = get_remote_rs485(io2.remote_id()) check_rs485 = "103 495 enabled" if rs485 != check_rs485: raise Exception("%s: %s: RS485 was not '%s', it was '%s'" % ("test rs485", io1.handler.name, check_rs485, rs485)) utils.io_close(io1) utils.io_close(io2) print(" Success!")
def ta_tcp(): print("Test accept tcp") io1 = utils.alloc_io(o, "tcp,localhost,3023", do_open=False) TestAccept(o, io1, "tcp,localhost,3023", do_test, expected_raddr="ipv4,127.0.0.1,3023", expected_acc_laddr="ipv4,127.0.0.1,3023", expected_acc_port="3023")
def ta_mux_sctp(): print("Test accept mux-tcp") io1 = utils.alloc_io(o, "mux(service=myservice),sctp,localhost,3023", do_open=False) ta = TestAccept(o, io1, "mux,sctp,3023", do_test, do_close=False) service = ta.io2.control(0, True, gensio.GENSIO_CONTROL_SERVICE, None) if service != "myservice": raise Exception("Invalid service, expected %s, got %s" % ("myservice", service)) ta.close()
def ta_udp(): print("Test accept udp") io1 = utils.alloc_io(o, "udp,localhost,3023", do_open=False) TestAccept(o, io1, "udp,localhost,3023", do_test, io1_dummy_write="A", expected_raddr="ipv4,127.0.0.1,3023", expected_acc_laddr="ipv4,127.0.0.1,3023", expected_acc_port="3023")
def test_stdio_basic_stderr(): print("Test stdio basic stderr echo") io = utils.alloc_io(o, "stdio,sh -c 'cat 1>&2'", chunksize=64) io.handler.ignore_input = True io.read_cb_enable(True) err = io.open_channel_s(None, None) utils.HandleData(o, "stderr", chunksize=64, io=err) utils.test_dataxfer(io, err, "This is a test string!") utils.io_close(io) utils.io_close(err) print(" Success!")
def ta_ssl_tcp(): print("Test accept ssl-tcp") io1 = utils.alloc_io(o, "ssl(CA=%s/CA.pem),tcp,localhost,3023" % utils.keydir, do_open=False) ta = TestAccept(o, io1, "ssl(key=%s/key.pem,cert=%s/cert.pem),3023" % (utils.keydir, utils.keydir), do_test, do_close=False, expected_raddr="ipv4,127.0.0.1,3023") cn = io1.control(0, True, gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, "-1,CN") i = cn.index(',') cn2 = cn[i + 1:] i = cn2.index(',') if cn2[0:i] != "CN": raise Exception("Invalid object name, expected %s, got %s" % ("CN", cn2[0:i])) if cn2[i + 1:] != "ser2net.org": raise Exception( "Invalid common name in certificate, expected %s, got %s" % ("ser2net.org", cn2[i + 1:])) cert = io1.control(0, True, gensio.GENSIO_CONTROL_CERT, None) print("Cert = \n" + cert) finger = io1.control(0, True, gensio.GENSIO_CONTROL_CERT_FINGERPRINT, None) print("Fingerprint = " + finger) i = 0 while True: v = io1.control(0, True, gensio.GENSIO_CONTROL_GET_PEER_CERT_NAME, str(i)) if v is None: break print(v) i = i + 1 ta.close()
import tempfile import os print("Testing miscellaneous features") print(" kickolduser") ser2net, io1, io2 = utils.setup_2_ser2net( utils.o, ("connection: &con", " accepter: tcp,3023", " connector: serialdev,/dev/ttyPipeA0,9600N81", " options:", " kickolduser: true"), "tcp,localhost,3023", "serialdev,/dev/ttyPipeB0,9600N81") io3 = None try: io1.handler.set_expected_err("Remote end closed connection") io1.read_cb_enable(True) io3 = utils.alloc_io(utils.o, "tcp,localhost,3023") if io1.handler.wait_timeout(1000) == 0: raise Exception("kickolduser: remote end didn't close") finally: if io3 is not None: utils.io_close(io3) utils.finish_2_ser2net(ser2net, io1, io2) print(" multiple connections") ser2net, io1, io2 = utils.setup_2_ser2net( utils.o, ("connection: &con", " accepter: tcp,3023", " connector: serialdev,/dev/ttyPipeA0,9600N81", " options:", " max-connections: 2"), "tcp,localhost,3023", "serialdev,/dev/ttyPipeB0,9600N81") io3 = None io4 = None
def ta_tcp(): print("Test accept tcp") io1 = utils.alloc_io(o, "tcp,localhost,3023", do_open=False) TestAccept(o, io1, "tcp,3023", do_test)
def test_sctp_oob(): print("Test sctp oob") io1 = utils.alloc_io(o, "sctp,localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "sctp,3023", do_oob_test)
def ta_udp(): print("Test accept udp") io1 = utils.alloc_io(o, "udp,localhost,3023", do_open=False) TestAccept(o, io1, "udp,3023", do_test, io1_dummy_write="A")
def test_tcp_urgent(): print("Test tcp urgent") io1 = utils.alloc_io(o, "tcp,localhost,3023", do_open=False, chunksize=64) ta = TestAccept(o, io1, "tcp,3023", do_urgent_test)
def ta_telnet(): print("Test accept telnet") io1 = utils.alloc_io(o, "telnet(rfc2217),tcp,localhost,3027", do_open=False) ta = TestAccept(o, io1, "telnet(rfc2217=true),3027", do_telnet_test)
def test_stdio_basic(): print("Test stdio basic echo") io = utils.alloc_io(o, "stdio,cat", chunksize=64) utils.test_dataxfer(io, io, "This is a test string!") utils.io_close(io) print(" Success!")
def test_modemstate(): io1str = "serialdev,/dev/ttyPipeA0,9600N81,LOCAL" io2str = "serialdev,/dev/ttyPipeB0,9600N81" print("serialdev modemstate:\n io1=%s\n io2=%s" % (io1str, io2str)) io1 = utils.alloc_io(o, io1str, do_open=False) io2 = utils.alloc_io(o, io2str) set_remote_null_modem(io2.remote_id(), False) set_remote_modem_ctl(io2.remote_id(), (SERIALSIM_TIOCM_CAR | SERIALSIM_TIOCM_CTS | SERIALSIM_TIOCM_DSR | SERIALSIM_TIOCM_RNG) << 16) io1.handler.set_expected_modemstate(0) io1.open_s() io1.read_cb_enable(True) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 1" % ("test dtr", io1.handler.name)) io2.read_cb_enable(True) io1.handler.set_expected_modemstate(gensio.SERGENSIO_MODEMSTATE_CD_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD) set_remote_modem_ctl(io2.remote_id(), ((SERIALSIM_TIOCM_CAR << 16) | SERIALSIM_TIOCM_CAR)) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 2" % ("test dtr", io1.handler.name)) io1.handler.set_expected_modemstate(gensio.SERGENSIO_MODEMSTATE_DSR_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD | gensio.SERGENSIO_MODEMSTATE_DSR) set_remote_modem_ctl(io2.remote_id(), ((SERIALSIM_TIOCM_DSR << 16) | SERIALSIM_TIOCM_DSR)) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 3" % ("test dtr", io1.handler.name)) io1.handler.set_expected_modemstate(gensio.SERGENSIO_MODEMSTATE_CTS_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD | gensio.SERGENSIO_MODEMSTATE_DSR | gensio.SERGENSIO_MODEMSTATE_CTS) set_remote_modem_ctl(io2.remote_id(), ((SERIALSIM_TIOCM_CTS << 16) | SERIALSIM_TIOCM_CTS)) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 4" % ("test dtr", io1.handler.name)) io1.handler.set_expected_modemstate(gensio.SERGENSIO_MODEMSTATE_RI_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD | gensio.SERGENSIO_MODEMSTATE_DSR | gensio.SERGENSIO_MODEMSTATE_CTS | gensio.SERGENSIO_MODEMSTATE_RI) set_remote_modem_ctl(io2.remote_id(), ((SERIALSIM_TIOCM_RNG << 16) | SERIALSIM_TIOCM_RNG)) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 5" % ("test dtr", io1.handler.name)) io1.handler.set_expected_modemstate( gensio.SERGENSIO_MODEMSTATE_RI_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD_CHANGED | gensio.SERGENSIO_MODEMSTATE_DSR_CHANGED | gensio.SERGENSIO_MODEMSTATE_CTS_CHANGED) set_remote_modem_ctl(io2.remote_id(), (SERIALSIM_TIOCM_CAR | SERIALSIM_TIOCM_CTS | SERIALSIM_TIOCM_DSR | SERIALSIM_TIOCM_RNG) << 16) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 6" % ("test dtr", io1.handler.name)) io1.handler.set_expected_modemstate( gensio.SERGENSIO_MODEMSTATE_CD_CHANGED | gensio.SERGENSIO_MODEMSTATE_DSR_CHANGED | gensio.SERGENSIO_MODEMSTATE_CTS_CHANGED | gensio.SERGENSIO_MODEMSTATE_CD | gensio.SERGENSIO_MODEMSTATE_DSR | gensio.SERGENSIO_MODEMSTATE_CTS) set_remote_null_modem(io2.remote_id(), True) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 7" % ("test dtr", io1.handler.name)) utils.io_close(io1) utils.io_close(io2) print(" Success!") return