#!/bin/sh
# run.sh (run as the UNPRIVILEGED user) - drive the hammer2 flush race.
# Expects RACE_DIR to point at a writable dir on a mounted hammer2 fs.
# Args: passed through to race_flush (-w -s -i -t).
set -e
cd "$(dirname "$0")"

# If RACE_DIR isn't set, default to /h2mnt/race (created by setup.sh).
: "${RACE_DIR:=/h2mnt/race}"

if [ ! -d "$RACE_DIR" ]; then
    echo "run.sh: RACE_DIR=$RACE_DIR not found; run setup.sh as root first" >&2
    exit 1
fi

echo "=== DF-2568 hammer2 flush race ==="
echo "kernel: $(sysctl -n kern.version | head -1)"
echo "RACE_DIR=$RACE_DIR"

# Run with a generous timeout; the race may take seconds-to-minutes to hit.
# If the kernel panics on the NULL deref, this process gets killed (SIGKILL
# from the panic) and ssh drops. A clean exit means no panic this round.
exec ./race_flush -d "$RACE_DIR" -w 10 -s 4 -i 200000 -t 120
