diff options
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/test/daemon.py b/test/daemon.py index e7fee37b..976b30e2 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -228,7 +228,7 @@ class Replica: """A replica's connection (src/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 21 + WIRE = 22 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout @@ -641,6 +641,76 @@ def sessions_listed(binary, env, root): return [[name, pid, rest] for name, pid, rest in rows] +def pdf_window(binary, gui_binary): + """A PDF in a terminal's detached session (the pdf addon its prefix + installs, `<prefix>/lib/pardes/addons/pdf.so`), a window client attached + and its wheel turned over the PDF: the session's page moves, the + window's digest is the session's, and the window, which runs no addon + code, draws the session's frames of it. Skipped when the build has no + pdf.so.""" + lib = Path(binary).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + if not lib.exists(): + print(f'daemon: no {lib}: the PDF window case skipped') + return + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='pdfw-', dir=os.environ.get('TMPDIR') or scratch)) + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + env.pop('XDG_DATA_HOME', None) + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + notes = root / 'notes.txt' + notes.write_text('notes\n') + started = [] + try: + sess = subprocess.Popen([binary, '--detach=pdf', str(notes)], env=env, cwd=root, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) + started.append(sess.pid) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-pdf.sock').exists) + nine = Client(root / 'pardes-9p-pdf.sock') + assert any(row.startswith(b'pdf ') for row in nine.read('/addons').splitlines()), nine.read('/addons') + nine.write('/look', f'{doc}\n'.encode()) + pdf = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'pdf') + for row in nine.read('/index').splitlines(): + if row.split()[1] == b'text': + nine.write(f'/pane/{int(row.split()[0])}/ctl', b'Del\n') + def page(): + # A kind's prefix is its last frame's: one drawn first. + nine.read('/screen') + tag = nine.read(f'/pane/{pdf}/tag') + return int(tag[1:tag.index(b'/')]) if tag.startswith(b'[') else 0 + wait_for('the PDF at its first page', lambda: page() == 1) + check = root / 'w.check' + w = Window(root, 'w', [gui_binary, '--attach=' + str(sock) + ':pdf'], dict(env, PARDES_REPLICA_CHECK=str(check))) + started.append(w.pid) + wait_for('the window client agrees', lambda: agreed(check, 0), timeout=30) + for _ in range(60): + w.mouse('wheel', -3, 400, 400) + time.sleep(0.02) + wait_for('the session\'s PDF past its first page', lambda: page() > 1, timeout=30) + n = len(checks(check)) + wait_for('the window client agrees after the wheel', lambda: agreed(check, n), timeout=30) + assert w.close() == 0, w.said()[-800:] + print(f'daemon: a PDF in a detached session, a window client\'s wheel over it: the session at page {page()}, ' + f'the window\'s digest the session\'s {len(checks(check))} times') + exit_session(nine, pdf) + sess.wait(timeout=10) + nine.socket.close() + finally: + for pid in started: + try: + os.killpg(pid, signal.SIGKILL) + except (ProcessLookupError, PermissionError): + pass + shutil.rmtree(root, ignore_errors=True) + + def window_clients(binary, gui_binary): """Window replica clients (`pardes-gui --attach=<socket>:<name>`): of a terminal's detached session, directly and through the delay relay at @@ -1785,6 +1855,7 @@ if __name__ == '__main__': far(sys.argv[2]) elif sys.argv[1:2] == ['--window-clients']: window_clients(sys.argv[2], sys.argv[3]) + pdf_window(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--ping']: ping(sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5]) if len(sys.argv) > 5 else 50) elif '--gui' in sys.argv: |
