#!/usr/bin/env bash # Does the web build actually render in parallel, and does it still produce # the right pixels? # # Both halves matter. A worker pool that silently falls back to one thread # looks exactly like a working one except for the clock, and a pool that # assembles bands in the wrong order produces a plausible-looking but wrong # frame. So this times 1 worker against many and compares both against a # straight single-instance render. # # The page POSTs its results back rather than logging them: headless Chrome's # console plumbing is unreliable, and --virtual-time-budget would make # performance.now() meaningless for timing anyway. set -euo pipefail cd "$(dirname "$0")/.." chrome="${CHROME_EXECUTABLE:-$(command -v google-chrome-stable || command -v google-chrome || command -v chromium || true)}" [ -n "$chrome" ] || { echo "no Chrome found; set CHROME_EXECUTABLE"; exit 1; } [ -f example/web/nimflutter.js ] || { echo "run 'just wasm' first"; exit 1; } work="$(mktemp -d)" port="${PORT:-8793}" profile="$work/profile" trap 'rm -rf "$work"' EXIT cp example/web/nimflutter.js example/web/nimflutter.wasm \ example/web/nimflutter_worker.js example/web/nimflutter_pool.js "$work/" cat > "$work/index.html" <<'HTML' pool HTML # Serves the directory, and exits after the page POSTs its results to /result. cat > "$work/server.py" <<'PY' import sys, http.server out = sys.argv[1] class H(http.server.SimpleHTTPRequestHandler): def do_POST(self): body = self.rfile.read(int(self.headers['Content-Length'])).decode() open(out, 'w').write(body) self.send_response(204); self.end_headers() raise SystemExit(0) def log_message(self, *a): pass http.server.HTTPServer(('127.0.0.1', int(sys.argv[2])), H).serve_forever() PY (cd "$work" && exec python3 server.py results.txt "$port") >/dev/null 2>&1 & sleep 2 "$chrome" --headless=new --no-sandbox --disable-dev-shm-usage \ --user-data-dir="$profile" --disable-gpu \ "http://127.0.0.1:$port/index.html" >/dev/null 2>&1 & chrome_pid=$! for _ in $(seq 1 60); do [ -s "$work/results.txt" ] && break sleep 1 done kill "$chrome_pid" 2>/dev/null || true kill %1 %2 2>/dev/null || true [ -s "$work/results.txt" ] || { echo "FAIL page produced no result"; exit 1; } { cat "$work/results.txt"; echo; } grep -q '^error=' "$work/results.txt" && { echo "FAIL page threw"; exit 1; } grep -q 'diff-1worker=0' "$work/results.txt" || { echo "FAIL 1-worker frame differs"; exit 1; } grep -q 'diff-pool=0' "$work/results.txt" || { echo "FAIL pooled frame differs"; exit 1; } echo "ok pooled and single-instance frames are identical"