e2e-exploit/run_exploit.sh
#!/usr/bin/env bash
set -euo pipefail

BUILD_DIR="${1:-build}"

DEFAULT_SYNC_ARGS=(
  --core 5
  --hammer-fn self_sync
  --sync-base-row 14
  --num-sync-rows 8

  --ref-threshold        1150
  --sync-cycles-min      25000
  --sync-cycles-max      25000
  --sync-cycles-step     1000

  --reads-per-trefi-min  92
  --reads-per-trefi-max  92
  --reads-per-trefi-step 2
  --column-stride        1024

  --pattern skh_mod128_parallel
  --aggressor-row-base-offset 0
  --aggressor-row-base-limit 0
  --aggressor-row-offset-increment 4
  --num-patterns         1
  --hammer-rounds 1
  --repeatable-hammer-rounds 5
  --refs-per-hammer      $((8 * 512000))
  --num-allocations 1000
  --num-repeatability-checks 1
  --subchannels 0
  --ranks 0
  --bank-groups 0 1 2 3
  --banks 0
  --burst-rotate 16
)

summary="$BUILD_DIR/runs_summary.csv"
if [[ ! -e $summary ]]; then
    echo "run_id,duration_s,exit_status" > "$summary"
fi

for n in $(seq 1 1); do
    run_id=$(date +"%Y%m%d-%H%M%S")-${n}
    log_file="$BUILD_DIR/stdout-${run_id}.log"

#    echo "===> run ${n} (log: $log_file)"
    { time -p "$BUILD_DIR/hammer" hammer "${DEFAULT_SYNC_ARGS[@]}"; } \
        2> >(awk '/^real/ {print $2 >"'"$BUILD_DIR/time.tmp"'"}') \
        | tee "$log_file"
    rc=${PIPESTATUS[0]}
    dur=$(cat "$BUILD_DIR/time.tmp")
    rm -f "$BUILD_DIR/time.tmp"

    echo "${run_id},${dur},${rc}" >> "$summary"
done

echo "All done – see $summary for runtimes."
