def terminate(self): """Terminate the running ipmi_sim This closes the io and sends a SIGTERM to ipmi_sim and waits a bit for it to terminate. If it does not terminate, send SIGTERM a few more times. If it still refuses to close, send a SIGKILL. If all that fails, raise an exception. """ if (self.handler.debug or utils.debug): print("Terminating") if self.io.closeme: utils.io_close(self.io) count = 10 while (count > 0): if (count < 6): self.signal(signal.SIGTERM) else: self.signal(signal.SIGKILL) # It would be really nice if waitpid had a timeout options, # in absense of that simulate it, sort of. subcount = 500 while (subcount > 0): time.sleep(.01) pid, rv = os.waitpid(self.pid, os.WNOHANG) if (pid > 0): self.handler = None return subcount -= 1 count -= 1 raise Exception("ipmisim did not terminate")
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_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_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_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 close(self): self.io1.read_cb_enable(False) self.io2.read_cb_enable(False) utils.io_close(self.io1) utils.io_close(self.io2) # Break all the possible circular references. del self.io1 del self.io2
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 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 close(self): self.io1.read_cb_enable(False) if self.io2: self.io2.read_cb_enable(False) utils.io_close(self.io1) if self.io2: utils.io_close(self.io2) # Break all the possible circular references. del self.io1 del self.io2 self.acc.shutdown_s() del self.acc
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 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
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 try: utils.test_dataxfer(io2, io1, "Test string") io3 = utils.alloc_io(utils.o, "tcp,localhost,3023") io3.handler.set_compare("Test 2 string") utils.test_dataxfer(io2, io1, "Test 2 string")