diff options
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/test/daemon.py b/test/daemon.py index 5603131d..97b0de76 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -55,6 +55,11 @@ private HOME and runtime directory: a client window showing a PDF resized 30 times in a second by the real compositor (driftwm), the caller's display: no SDL assertion, the last size taken, an input a size at most + python3 -B test/daemon.py --client-idle <pardes> <pardes-gui> + a window's session (the test surface, and offscreen with no test + mode) and a terminal's, each with a PDF and a terminal client, + nobody typing: no more steps than the text alone (pdf.so in both + prefixes) """ import fcntl import json @@ -335,7 +340,7 @@ class Replica: """A replica's connection (abi/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 = 34 + WIRE = 35 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout @@ -2278,6 +2283,112 @@ def client_motion(binary, gui_binary): shutil.rmtree(root, ignore_errors=True) +def idle_session(binary, gui_binary, surface, pdf, secs): + """One session (`surface`: a window's on the test surface; a window's + offscreen with no test mode, `loop`: the loop a real window runs, asleep + until an event or its deadline; or a terminal's with its own terminal), + a text and, with `pdf`, a PDF, one terminal client attached, nobody + typing for `secs`: the session's boundaries and the units the client + took over its whole life, and the CPU each spent in the idle seconds + (ticks of 10 ms).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='ci-', dir=os.environ.get('TMPDIR') or scratch)) + env = base_env() + 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') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(60))) + stats = root / 'session.stats' + started, terms, windows = [], [], [] + try: + if surface == 'window': + win = Window(root, 'win', [gui_binary, '--9p=idle', str(notes)], dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats))) + windows.append(win) + started.append(win.pid) + elif surface == 'loop': + started.append(subprocess.Popen([gui_binary, '--9p=idle', str(notes)], cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, start_new_session=True, + env=dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats), SDL_VIDEO_DRIVER='offscreen')).pid) + else: + ts = Term(30, 100) + terms.append(ts) + started.append(ts.spawn([binary, '--tty', '--9p=idle', str(notes)], dict(env, PARDES_REPLICA_STATS=str(stats))).pid) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-idle.sock').exists, timeout=30) + nine = Client(root / 'pardes-9p-idle.sock') + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + started.append(session) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists, timeout=30) + pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + if pdf: + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + nine.write(f'/pane/{pane}/look', f'{doc}\n'.encode()) + wait_for('the PDF shown', lambda: any(row.split()[1] == b'pdf' for row in nine.read('/index').splitlines()), timeout=30) + tc = Term(24, 80) + terms.append(tc) + c = tc.spawn([binary, f'--attach={sock}:idle'], dict(env, PARDES_REPLICA_STATS=str(root / 'c.stats'))) + started.append(c.pid) + wait_for('the client\'s first frame', lambda: b'notes' in tc.text(), timeout=30) + # Its join and the frames after it over. + time.sleep(1.5) + cpu = (cpu_ticks(session), cpu_ticks(c.pid)) + time.sleep(secs) + cpu = (cpu_ticks(session) - cpu[0], cpu_ticks(c.pid) - cpu[1]) + c.send_signal(signal.SIGHUP) + c.wait(timeout=10) + line = checks(root / 'c.stats')[-1].split() + units = int(line[line.index('units') + 1]) + exit_session(nine, pane) + wait_for('the session ended', lambda: not alive(session), timeout=60) + nine.socket.close() + return int(session_stats(stats)[0]['boundaries']), units, cpu + finally: + for t in terms: + t.close() + for w in windows: + if w.p.poll() is None: + w.p.kill() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + +def client_idle(binary, gui_binary, secs=5): + """An idle session sends nothing (2026-11-24: a PDF in a window's session + with a client attached stepped the session ~700 times a second, nobody + typing, each step a unit every client replayed): a session showing a + text and a PDF, one terminal client, nobody typing for `secs`, takes at + most the steps the same session with the text alone takes, plus the + PDF's own opening (its page drawn, its views told: `opening`). On the + test surface the window's loop polls its feed every 16 ms, a step and a + unit each (the text alone's count is that rate); a window's own loop + (`loop`: offscreen, no test mode) and a terminal's session step for + nothing. The PDF's addon (`<prefix>/lib/pardes/addons/pdf.so`, `zig + build addons`) beside each binary.""" + for b in (binary, gui_binary): + lib = Path(b).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + assert lib.exists(), f'no {lib}: the PDF is this test\'s subject (zig build install addons into that prefix)' + opening = 40 + flooded = [] + for surface in ('window', 'loop', 'tty'): + text = idle_session(binary, gui_binary, surface, False, secs) + shown = idle_session(binary, gui_binary, surface, True, secs) + print(f'daemon: a {surface}\'s session idle {secs} s, a terminal client attached: ' + f'text alone {text[0]} boundaries, the client {text[1]} units, CPU {text[2][0] * 10}/{text[2][1] * 10} ms; ' + f'with a PDF {shown[0]} boundaries, {shown[1]} units, CPU {shown[2][0] * 10}/{shown[2][1] * 10} ms (session/client)') + if shown[0] > text[0] + opening or shown[1] > text[1] + opening: + flooded.append(f'{surface}: {shown[0]} boundaries and {shown[1]} units against the text alone\'s {text[0]} and {text[1]}') + assert not flooded, (f'a session showing a PDF, a client attached, nobody typing for {secs} s, steps with nothing to do, ' + f'a unit every client replays: {"; ".join(flooded)}') + + def client_resize_real(binary, gui_binary): """A client window resized by a real compositor (driftwm's `msg resize`, the configures a drag sends: 30 sizes in a second) while it shows a PDF: @@ -4493,6 +4604,8 @@ if __name__ == '__main__': client_motion(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--client-resize-real']: client_resize_real(sys.argv[2], sys.argv[3]) + elif sys.argv[1:2] == ['--client-idle']: + client_idle(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 sys.argv[1:2] == ['--pair-gui']: |
