#!/bin/bash
# Run the POC against a Chrome build using the ANGLE Vulkan backend.
#
# Usage: ./run.sh [/path/to/chrome]
#
# By default this uses --use-angle=swiftshader so it works on machines without a
# Vulkan-capable GPU (Chrome ships libvk_swiftshader.so). On Android / Linux /
# ChromeOS where ANGLE-Vulkan is the production default, drop that flag.

set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
CHROME="${1:-/chromium/chromium/src/out/asan/chrome}"
PORT=8080

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

rm -rf /tmp/chrome-poc-profile
timeout 60 "$CHROME" \
    --headless=new \
    --no-first-run --no-default-browser-check \
    --user-data-dir=/tmp/chrome-poc-profile \
    --no-sandbox --disable-gpu-sandbox \
    --use-angle=swiftshader \
    --enable-logging=stderr --v=0 \
    "http://127.0.0.1:$PORT/poc.html" 2>&1 \
  | grep -E 'CONSOLE|POC-TRACE'
