summaryrefslogtreecommitdiff
path: root/test/daemon.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 11:52:10 -0300
committerGabriel Schneider <[email protected]>2026-11-24 11:53:55 -0300
commit9124da2051f72dec9ed301af19d62b5ff17b20d8 (patch)
tree34cff9d19388cc11cb8bc3949c9be5cbabee11ae /test/daemon.py
parent3baad4850b25a250649ab4928365b5c3d20f03df (diff)
downloadpardes-9124da2051f72dec9ed301af19d62b5ff17b20d8.tar.gz
pardes-9124da2051f72dec9ed301af19d62b5ff17b20d8.zip
test/daemon.py --client-resize-real (FAILING on main, the hunt's second cause of "resizing feels very slow" and of "contents cut" in a client): a client window of a window's session resized by the real compositor (driftwm `msg resize`, the caller's display, 30 sizes in a second, a terminal with output and a PDF shown) posts its size a few times a size and draws within its target: on main it sent its session 623 and 1308 inputs besides pointer motion for 30 sizes (two runs; 25 against a detached terminal's session), each a unit for every client and a rollback of its own, going on after the drag ended (the hunt's real run: its frames 2.7 s past the last size); and in the hunt's runs with a Changes layer and a terminal beside the PDF the window met SDL's release assertion 'Scissor rectangle size exceeds current render target dimensions' (SDL_SetGPUScissor, from the page's clip, dev/gui/gui.zig imageScissor 3878, never held to the target: sketchbook dev/draw/Cells.zig drawImages 398) 1 and 215 times in 30 sizes: with SDL's default its dialog (zenity) blocks the window's thread, which then stays at its old size (918x610 after 30 sizes to 1170x750), draws nothing more and shows no pane opened after; the test asserts no assertion (SDL_ASSERT=ignore: counted on stderr, never a dialog), the last size taken, and at most three inputs a size; skipped without driftwm, a display or pdf.so
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/daemon.py')
-rw-r--r--test/daemon.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 16c40ea9..a94fbbbf 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -51,6 +51,10 @@ private HOME and runtime directory:
python3 -B test/daemon.py --client-motion <pardes> <pardes-gui>
a run of pointer motions over a client window is a few inputs, not
one each (also run by --window-clients)
+ python3 -B test/daemon.py --client-resize-real <pardes> <pardes-gui>
+ 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, a few inputs a size
"""
import fcntl
import json
@@ -2224,6 +2228,122 @@ def client_motion(binary, gui_binary):
shutil.rmtree(root, ignore_errors=True)
+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:
+ no SDL assertion (on main every frame drawn larger than the target it
+ is drawn into placed the page's scissor past it: `SDL_SetGPUScissor`'s
+ release assertion, whose dialog blocks the window's thread: the window
+ frozen at its old size, cut, and nothing opened after shows in it), it
+ takes the last size, and its inputs are a few a size. Real windows: the
+ caller's display and runtime directory reach the compositor; the
+ session's runtime directory is the test's own; skipped without driftwm."""
+ real_runtime = os.environ.get('XDG_RUNTIME_DIR', '')
+ wayland = os.environ.get('WAYLAND_DISPLAY') or 'wayland-1'
+ display = wayland if wayland.startswith('/') else os.path.join(real_runtime, wayland)
+ lib = Path(binary).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so'
+ if not shutil.which('driftwm') or not os.path.exists(display) or not lib.exists():
+ print('daemon: client resize on a real compositor: skipped (no driftwm, display or pdf.so)')
+ return
+ drift_env = dict(os.environ, XDG_RUNTIME_DIR=real_runtime, WAYLAND_DISPLAY=wayland)
+
+ def drift(*args):
+ out = subprocess.run(['driftwm', 'msg', '--json', *map(str, args)], env=drift_env, capture_output=True, text=True, timeout=10)
+ return json.loads(out.stdout) if out.stdout.strip() else {}
+
+ def window_of(pid):
+ state = drift('state')['Ok']['State']
+ return next((w for w in state['windows'] if w.get('pid') == pid), None)
+
+ scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
+ scratch.mkdir(parents=True, exist_ok=True)
+ root = Path(tempfile.mkdtemp(prefix='cr-', 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', SDL_AUDIODRIVER='dummy')
+ env.pop('XDG_DATA_HOME', None)
+ (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(300)))
+ doc = root / 'design.pdf'
+ shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc)
+ started = []
+ try:
+ state = drift('state')['Ok']['State']
+ focused = next((w['id'] for w in state['windows'] if w.get('is_focused')), None)
+ # The session a window of its own, as a desktop's is, its daemon on;
+ # a terminal with output in it beside the PDF.
+ sess = subprocess.Popen([gui_binary, '--9p=files', str(notes), '--geometry=1120x760'],
+ env=dict(env, PARDES_DAEMON='on', WAYLAND_DISPLAY=display, SDL_VIDEO_DRIVER='wayland', SDL_ASSERT='ignore'),
+ cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(root / 's.err', 'w'),
+ start_new_session=True)
+ started.append(sess.pid)
+ sid = wait_for('the session\'s window', lambda: (window_of(sess.pid) or {}).get('id'), timeout=30)
+ drift('move', '--id', sid, 59400, -18000)
+ if focused is not None:
+ drift('focus', '--id', focused)
+ sock = root / 'pardes-replica.sock'
+ wait_for('the replica socket', sock.exists, timeout=30)
+ wait_for('the session\'s 9P socket', (root / 'pardes-9p-files.sock').exists, timeout=30)
+ nine = Client(root / 'pardes-9p-files.sock')
+ pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text')
+ nine.write(f'/pane/{pane}/exec', b'Term\n')
+ shell = wait_for('a shell pane', lambda: next((int(row.split()[0]) for row in nine.read('/index').splitlines()
+ if row.split()[1] == b'term'), None))
+ wait_for('the shell\'s prompt', lambda: b'$' in nine.read(f'/pane/{shell}/body'))
+ nine.write(f'/pane/{shell}/pty/data', b'seq 1 400\r')
+ nine.write(f'/pane/{pane}/look', f'{doc}\n'.encode())
+ wait_for('the PDF pane', lambda: any(row.split()[1] == b'pdf' for row in nine.read('/index').splitlines()))
+ err = root / 'w.err'
+ stats = root / 'w.stats'
+ # SDL's assertion counted on stderr, never its dialog on the desktop.
+ w = subprocess.Popen([gui_binary, f'--attach={sock}:files', '--geometry=900x600'],
+ env=dict(env, WAYLAND_DISPLAY=display, SDL_VIDEO_DRIVER='wayland', SDL_ASSERT='ignore',
+ PARDES_REPLICA_STATS=str(stats), SDL_EVENT_LOGGING='2'),
+ cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(err, 'w'), start_new_session=True)
+ started.append(w.pid)
+ wid = wait_for('the client\'s window', lambda: (window_of(w.pid) or {}).get('id'), timeout=30)
+ # Far from where the desktop's user looks, the focus given back.
+ drift('move', '--id', wid, 62000, -18000)
+ if focused is not None:
+ drift('focus', '--id', focused)
+ time.sleep(3)
+ steps = 30
+ t0 = time.monotonic()
+ for i in range(steps):
+ time.sleep(max(0, t0 + i / 30 - time.monotonic()))
+ last = (900 + 9 * (i + 1), 600 + 5 * (i + 1))
+ drift('resize', '--id', wid, *last)
+ time.sleep(3)
+ size = window_of(w.pid)['size']
+ said = err.read_text(errors='replace')
+ w.send_signal(signal.SIGTERM)
+ w.wait(timeout=15)
+ line = checks(stats)[-1].split() if checks(stats) else []
+ sent = int(line[line.index('inputs') + 1]) if 'inputs' in line else -1
+ asserted = said.count('Assertion failure')
+ # A pointer that crossed the window (one sliding under it as it was
+ # moved away) is motion's, --client-motion's: not counted here.
+ motions = said.count('SDL_EVENT_MOUSE_MOTION')
+ sent -= motions
+ print(f'daemon: a client window resized {steps} times in a second by the compositor: {asserted} SDL assertions, '
+ f'its size {size} (asked {list(last)}), {sent} inputs besides {motions} pointer motions')
+ assert asserted == 0, ('a client window drew past its target while resized', said[-600:])
+ assert abs(size[0] - last[0]) <= 2 and abs(size[1] - last[1]) <= 40, ('the client window did not take the last size', size, last)
+ assert 0 < sent <= 3 * steps, ('a client window resized posted its size again and again', sent)
+ exit_session(nine, pane)
+ sess.wait(timeout=60)
+ nine.socket.close()
+ finally:
+ for pid in started + processes(root):
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except OSError:
+ pass
+ shutil.rmtree(root, ignore_errors=True)
+
+
def joins(path):
"""A replica client's joins (PARDES_REPLICA_STATS, a line a link): how
many blobs each listed, how many it held already from the core it left
@@ -4294,6 +4414,8 @@ if __name__ == '__main__':
client_motion(sys.argv[2], sys.argv[3])
elif sys.argv[1:2] == ['--client-motion']:
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] == ['--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']: