#!/bin/bash
# Reproduce ANGLE-GL TransformFeedback program-binding desync.
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
CHROME="${CHROME:-/chromium/chromium/src/out/asan/chrome}"
PORT="${PORT:-8765}"

python3 "$DIR/server.py" "$PORT" >/dev/null 2>&1 &
SRV=$!
trap 'kill $SRV 2>/dev/null' EXIT
sleep 1

rm -rf /tmp/chrome-poc-profile
timeout 30 "$CHROME" \
  --no-sandbox --disable-gpu-sandbox \
  --headless=new \
  --no-first-run --no-default-browser-check \
  --ignore-gpu-blocklist \
  --use-gl=angle --use-angle=gl-egl \
  --enable-logging=stderr --v=0 \
  --user-data-dir=/tmp/chrome-poc-profile \
  "http://127.0.0.1:$PORT/poc.html" 2>&1 \
  | grep -vE 'dbus|inotify|NameHasOwner|UPower|FontService|OAuth|Registration|idle_linux|dbind|gcm|DEPRECATED' \
  || true
