summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fs.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/fs.py b/test/fs.py
index 1332c319..ff085a55 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -290,8 +290,47 @@ def discovery(binary, embedded=False):
print('9P discovery: listing/stat/find are inert; new, remove, look, exec, name, sel and log behave')
+def run_file(binary):
+ """pty/run: a line in, how it ended out, on the same open."""
+ def run(c, serial, line):
+ fid = c.open(f'/pane/{serial}/pty/run', 2)
+ try:
+ c.rpc(118, struct.pack('<IQI', fid, 0, len(line)) + line)
+ return c.read_fid(fid)
+ finally:
+ c.close(fid)
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ with session(binary, root, 'run') as (client, address):
+ client.write('/exec', b'Shell bash\n')
+ client.write('/exec', b'Tty\n')
+ term = int(max(r.split()[0] for r in client.read('/index').splitlines() if r.split()[1] == b'term'))
+ deadline = time.monotonic() + 10
+ while run(client, term, b'true\n') == b'busy\n': # until its first prompt
+ assert time.monotonic() < deadline, 'the shell never reached a prompt'
+ time.sleep(.05)
+ assert run(client, term, b'false\n') == b'exit 1\n'
+ assert run(client, term, b'sh -c "exit 7"\n') == b'exit 7\n'
+ with Client(address) as other:
+ slow = []
+ waiter = threading.Thread(target=lambda: slow.append(run(other, term, b'sleep 1\n')), daemon=True)
+ waiter.start()
+ time.sleep(.3)
+ assert run(client, term, b'true\n') == b'busy\n'
+ waiter.join(5)
+ assert slow == [b'exit 0\n'], slow
+ closing = []
+ waiter = threading.Thread(target=lambda: closing.append(run(other, term, b'sleep 30\n')), daemon=True)
+ waiter.start()
+ time.sleep(.3)
+ client.write(f'/pane/{term}/exec', b'Del\n')
+ waiter.join(5)
+ assert closing == [b'error shell gone\n'], closing
+
+
def test(binary, quic=False):
started = time.monotonic()
+ run_file(binary)
for options, message in [
(['--fs'], b'no such option'),
(['--fs9'], b'no such option'),