#!/bin/sh
# Run tests for different runners in parallel

MYDIR=$(dirname "$0")

# these are fast, run them first
set -e
pre-commit run --all-files --show-diff-on-failure shellcheck
"$MYDIR/mypy"
"$MYDIR/qemu"
"$MYDIR/testdesc"
"$MYDIR/autopkgtest_args"
set +e

# get sudo password early, to avoid asking for it in background jobs
[ "$(id -u)" -eq 0 ] || sudo true

(rc=0; OUT=$("$MYDIR/autopkgtest" QemuRunner 2>&1) || rc=$?; echo "=== $c ==="; echo "$OUT"; exit "$rc") &
(rc=0; OUT=$("$MYDIR/autopkgtest" LxcRunner SshRunnerNoScript SshRunnerWithScript 2>&1) || rc=$?; echo "=== $c ==="; echo "$OUT"; exit "$rc") &
(rc=0; OUT=$("$MYDIR/autopkgtest" NullRunner SchrootRunner LxdRunner 2>&1) || rc=$?; echo "=== $c ==="; echo "$OUT"; exit "$rc") &
(rc=0; OUT=$(sudo "$MYDIR/autopkgtest" NullRunnerRoot ChrootRunner 2>&1) || rc=$?; echo "=== $c ==="; echo "$OUT"; exit "$rc") &
for c in $(seq 5); do wait; done
