source `dirname $0`/util.sh

record $TESTNAME &

until grep -q ready record.out; do
  sleep 0
done

for i in $(seq 1 100); do
  sleep 0.001
  kill -CHLD $(pidof $TESTNAME-$nonce) >& /dev/null
done
kill -USR2 $(pidof $TESTNAME-$nonce) >& /dev/null

# Wait for 'record' to actually terminate. Otherwise we might start
# replaying before the trace file has been completely written.
wait %1 || failed "Abnormal record termination"

echo "Replaying ..."
replay
check 'EXIT-SUCCESS'
