def test_rts(): config = ("connection: &con", " accepter: telnet(rfc2217),tcp,3023", " connector: serialdev,/dev/ttyPipeA0,9600n81", " options:", " banner: 12345") io1str = "telnet(rfc2217),tcp,localhost,3023" io2str = "serialdev,/dev/ttyPipeB0,9600N81" print("serialdev rts rfc2217:\n config=%s io1=%s\n io2=%s" % (config, io1str, io2str)) o = utils.o ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str) sio1 = io1.cast_to_sergensio() io1.handler.set_compare("12345") if (io1.handler.wait_timeout(1000) == 0): raise Exception("%s: %s: Timed out waiting for banner" % (name, io1.handler.name)) io1.read_cb_enable(True); io2.read_cb_enable(True); set_remote_null_modem(utils.remote_id_int(io2), False); val = sio1.sg_rts_s(0) if (val != gensio.SERGENSIO_RTS_ON): raise Exception("Expected RTS on at start, got %d" % val); val = get_remote_modem_ctl(utils.remote_id_int(io2)) if (not (val & SERIALSIM_TIOCM_RTS)): raise Exception("Expected remote RTS on at start"); val = sio1.sg_rts_s(gensio.SERGENSIO_RTS_OFF) if (val != gensio.SERGENSIO_RTS_OFF): raise Exception("Expected RTS off"); val = get_remote_modem_ctl(utils.remote_id_int(io2)) if (val & SERIALSIM_TIOCM_RTS): raise Exception("Expected remote RTS off"); val = sio1.sg_rts_s(gensio.SERGENSIO_RTS_ON) if (val != gensio.SERGENSIO_RTS_ON): raise Exception("Expected RTS on"); val = get_remote_modem_ctl(utils.remote_id_int(io2)) if (not (val & SERIALSIM_TIOCM_RTS)): raise Exception("Expected remote RTS on"); set_remote_null_modem(utils.remote_id_int(io2), True); utils.finish_2_ser2net(ser2net, io1, io2, handle_except = False) print(" Success!") return
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 = utils.o ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str) try: io1.handler.set_compare("12345") if (io1.handler.wait_timeout(1000) == 0): raise Exception("%s: %s: Timed out waiting for banner" % (name, io1.handler.name)) io1.read_cb_enable(True) io2.read_cb_enable(True) expected_termios = handler.op(io1, io2) io2_rem_termios = get_remote_termios(utils.remote_id_int(io2)) c = compare_termios(expected_termios, io2_rem_termios) if (c != -1): 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!")
def __init__(self, o, pipedev, configdata=None, emudata=None, extra_args=""): """Create a running ipmisim program The given config data is written to a file and used as the config file. It is started with the -r and -d options set, you can supply extra options if you like as a string. """ prog = os.getenv("IPMISIM_EXEC") if (not prog): prog = "ipmi_sim" if not configdata: configdata = default_ipmisim_config % pipedev if not emudata: emudata = default_ipmisim_emu self.cfile = tempfile.NamedTemporaryFile(mode="w+") self.cfile.write(configdata) self.cfile.flush() self.efile = tempfile.NamedTemporaryFile(mode="w+") self.efile.write(emudata) self.efile.flush() self.o = o args = "stdio," + prog + " -p -c " + self.cfile.name + " -f " + self.efile.name + " " + extra_args if (utils.debug): print("Running: " + args) self.handler = utils.HandleData(o, args, name="ipmisim daemon") self.io = self.handler.io self.io.closeme = True self.io.open_s() # Uncomment the following or set it yourself to get output from # the ipmisim daemon printed. #self.handler.debug = 2 self.pid = utils.remote_id_int(self.io) self.handler.set_waitfor("> ") if (self.handler.wait_timeout(2000) == 0): raise Exception("Timeout waiting for ipmi_sim to start") self.handler.ignore_input = True # Leave read on so if we enable debug we can see output from the # daemon. self.io.read_cb_enable(True) return
def test_modemstate(): config = ("connection: &con", " accepter: telnet(rfc2217),tcp,3023", " connector: serialdev,/dev/ttyPipeA0,9600n81,local") io1str = "telnet(rfc2217),tcp,localhost,3023" io2str = "serialdev,/dev/ttyPipeB0,9600N81" print("serialdev modemstate rfc2217:\n config=%s io1=%s\n io2=%s" % (config, io1str, io2str)) o = utils.o ser2net, io1, io2 = utils.setup_2_ser2net(o, config, io1str, io2str, do_io1_open=False) set_remote_null_modem(utils.remote_id_int(io2), False) set_remote_modem_ctl(utils.remote_id_int(io2), (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(utils.remote_id_int(io2), ((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(utils.remote_id_int(io2), ((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(utils.remote_id_int(io2), ((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(utils.remote_id_int(io2), ((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(utils.remote_id_int(io2), (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(utils.remote_id_int(io2), True) if (io1.handler.wait_timeout(2000) == 0): raise Exception("%s: %s: Timed out waiting for modemstate 7" % ("test dtr", io1.handler.name)) utils.finish_2_ser2net(ser2net, io1, io2, handle_except=False) print(" Success!") return