diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 10:56:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | f2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch) | |
| tree | c344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /test/gpu_snake.py | |
| parent | fc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff) | |
| download | pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip | |
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py.
Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open.
The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home.
The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so.
The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'test/gpu_snake.py')
| -rw-r--r-- | test/gpu_snake.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/test/gpu_snake.py b/test/gpu_snake.py new file mode 100644 index 00000000..430cabe9 --- /dev/null +++ b/test/gpu_snake.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +"""GPU snake pixels and frame timings in a private GUI session. + +python3 test/gpu_snake.py BINARY ADDON OUTPUT [--text] [--crt] +The output keeps pixels, timings, and logs; no installed session is touched. +""" +import argparse +import json +import os +from pathlib import Path +import statistics +import subprocess +import time +from ninep import Client + +def wait(check, timeout=15): + until = time.monotonic() + timeout + while time.monotonic() < until: + value = check() + if value: + return value + time.sleep(0.02) + raise TimeoutError('GUI did not reach the expected state') + +def run(binary, addon, root, text=False, crt=False): + root.mkdir(parents=True, exist_ok=True, mode=0o700) + root.chmod(0o700) + config = root / 'config/pardes' + config.mkdir(parents=True, exist_ok=True) + (config / 'init').write_text('Shell /bin/sh\nTheme orchard\n') + fixture = root / 'fixture.txt' + fixture.write_text(''.join((f'line {i:05d}: a reproducible scrolling fixture\n' for i in range(10000)))) + demo = root / 'demo.txt' + if text: + demo.write_text('500 phase scroll\n500 120x16 wheel 1\n2600 120x16 wheel -1\n4800 end\n') + else: + demo.write_text(f'100 exec Addon load {addon}\n200 exec SnakeShader\n500 phase snake\n500 180x16 key r\n3600 end\n') + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_')} + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), PARDES_TEST='1', PARDES_TEST_CAPTURE_DIR=str(root), PARDES_TEST_COLS='100', PARDES_TEST_ROWS='30', SDL_VIDEO_DRIVER='offscreen', PARDES_FRAMES=str(root / 'frames.tsv'), PARDES_FRAMES_DEMO=str(demo)) + with (root / 'stderr.log').open('w') as log: + child = subprocess.Popen([str(binary), '--9p=gpu', str(fixture)], env=env, cwd=root, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=log, start_new_session=True) + try: + socket = root / '9p/pardes/gpu' + wait(lambda: socket.exists() or child.poll() is not None) + if child.poll() is not None: + raise AssertionError((child.returncode, (root / 'stderr.log').read_text())) + with Client(socket) as client: + wait(lambda: (root / 'latest.ppm').exists()) + if not text: + wait(lambda: b'snake_shader' in client.read('/index')) + time.sleep(0.4) + (root / 'snake.ppm').write_bytes((root / 'latest.ppm').read_bytes()) + (root / 'index.txt').write_bytes(client.read('/index')) + child.wait(timeout=20) + assert child.returncode == 0, (child.returncode, (root / 'stderr.log').read_text()) + finally: + if child.poll() is None: + child.terminate() + child.wait(timeout=10) + child.stdin.close() + rows = [] + for line in (root / 'frames.tsv').read_text().splitlines(): + if not line or line.startswith('#'): + continue + values = list(map(float, line.split())) + if values[0] >= 500: + rows.append(values) + assert len(rows) >= 20, len(rows) + work = sorted((sum(row[1:4]) for row in rows)) + result = {'frames': len(rows), 'median_work_us': statistics.median(work), 'p95_work_us': work[int(len(work) * 0.95)], 'max_work_us': max(work), 'over_16ms': sum((v > 16667 for v in work))} + if not text: + from PIL import Image + im = Image.open(root / 'snake.ppm').convert('RGB') + green = sum((g > 90 and g > r * 1.7 and (g > b * 1.2) for r, g, b in im.get_flattened_data())) + orange = sum((r > 110 and r > g * 1.5 and (g > b * 1.5) for r, g, b in im.get_flattened_data())) + assert green > 300 and orange > 50, (green, orange) + result.update(green_pixels=green, orange_pixels=orange) + if crt: + pixels = list(im.get_flattened_data()) + triads = scanlines = 0 + for y in range(im.height // 2, im.height - 4): + for x in range(im.width - 3): + at = y * im.width + x + r, g, b = pixels[at:at + 3] + if min(r + g + b) < 8: + continue + if r[0] > g[0] * 1.8 and g[1] > r[1] * 1.8 and b[2] > g[2] * 1.8: + triads += 1 + rows = [pixels[at + 1 + dy * im.width][1] for dy in range(4)] + scanlines += max(rows) > min(rows) * 1.3 + assert triads > 100 and scanlines > 100, (triads, scanlines) + result.update(rgb_triads=triads, scanline_patches=scanlines) + (root / 'result.json').write_text(json.dumps(result, indent=2) + '\n') + print(json.dumps(result), flush=True) +if __name__ == '__main__': + p = argparse.ArgumentParser(description=__doc__) + p.add_argument('binary', type=Path) + p.add_argument('addon', type=Path) + p.add_argument('output', type=Path) + p.add_argument('--text', action='store_true') + p.add_argument('--crt', action='store_true', help='also require the RGB triads and scanline modulation') + a = p.parse_args() + run(a.binary.resolve(), a.addon.resolve(), a.output.resolve(), a.text, a.crt) |
