Scripts: Change wording for pseudoterminals

This commit is contained in:
Jeff Epler 2020-06-14 14:28:32 -05:00 committed by Jeff Epler
parent 9110e36636
commit 9737dd9c30
2 changed files with 13 additions and 9 deletions

View File

@ -87,28 +87,32 @@ def run_micropython(pyb, args, test_file, is_special=False):
def get(required=False): def get(required=False):
rv = b'' rv = b''
while True: while True:
ready = select.select([master], [], [], 0.02) ready = select.select([emulator], [], [], 0.02)
if ready[0] == [master]: if ready[0] == [emulator]:
rv += os.read(master, 1024) rv += os.read(emulator, 1024)
else: else:
if not required or rv: if not required or rv:
return rv return rv
def send_get(what): def send_get(what):
os.write(master, what) os.write(emulator, what)
return get() return get()
with open(test_file, 'rb') as f: with open(test_file, 'rb') as f:
# instead of: output_mupy = subprocess.check_output(args, stdin=f) # instead of: output_mupy = subprocess.check_output(args, stdin=f)
master, slave = pty.openpty() # openpty returns two read/write file descriptors. The first one is
p = subprocess.Popen(args, stdin=slave, stdout=slave, # used by the program which provides the virtual
# terminal service, and the second one is used by the
# subprogram which requires a tty to work.
emulator, subterminal = pty.openpty()
p = subprocess.Popen(args, stdin=subterminal, stdout=subterminal,
stderr=subprocess.STDOUT, bufsize=0) stderr=subprocess.STDOUT, bufsize=0)
banner = get(True) banner = get(True)
output_mupy = banner + b''.join(send_get(line) for line in f) output_mupy = banner + b''.join(send_get(line) for line in f)
send_get(b'\x04') # exit the REPL, so coverage info is saved send_get(b'\x04') # exit the REPL, so coverage info is saved
p.kill() p.kill()
os.close(master) os.close(emulator)
os.close(slave) os.close(subterminal)
else: else:
output_mupy = subprocess.check_output(args + [test_file], stderr=subprocess.STDOUT) output_mupy = subprocess.check_output(args + [test_file], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:

View File

@ -191,7 +191,7 @@ class ProcessToSerial:
class ProcessPtyToTerminal: class ProcessPtyToTerminal:
"""Execute a process which creates a PTY and prints slave PTY as """Execute a process which creates a PTY and prints secondary PTY as
first line of its output, and emulate serial connection using first line of its output, and emulate serial connection using
this PTY.""" this PTY."""