# Test Case: Deterministic Random Reads

**Test ID**: TC129-random-read-pattern  
**Category**: Boundary & Stress  
**Priority**: Medium  
**Regression**: None

## Objective

Compare every 4 KiB random read to the exact source at deterministic offsets,
and record TCG IOPS/latency without fixed performance thresholds.

## Preconditions

- Complete `G7-MANUAL-SETUP.md` and compile the exact `g7_probe.c`.
- Do not use `fio` without data verification and do not impose 1000 IOPS or
  10 ms cross-machine gates.

## Manual Steps

```sh
G7=/root/repo22-g7
FIX=$G7/fixtures
SRC=$FIX/sources/workloads/random/random.bin
IMAGE=$FIX/images/workloads.erofs
MNT=/mnt/repo22-g7-tc129
E=$G7/evidence/TC129
mkdir -p "$MNT" "$E"
test "$(stat -f %z "$SRC")" -eq 67108864
unit=$(mdconfig -a -t vnode -f "$IMAGE")
mount -t erofs -o ro "/dev/$unit" "$MNT"
TARGET=$MNT/random/random.bin
source_hash=$(sha256 -q "$SRC")
target_hash=$(sha256 -q "$TARGET")
printf 'source=%s\ntarget=%s\n' "$source_hash" "$target_hash" \
  | tee "$E/hashes.txt"
test "$source_hash" = "$target_hash"
cmp "$SRC" "$TARGET"
: > "$E/runs.tsv"
run=1
while [ "$run" -le 3 ]; do
  "$G7/g7_probe" random "$SRC" "$TARGET" \
    0x6a09e667f3bcc909 16384 4096 > "$E/run-$run.log"
  rc=$?
  digest=$(awk '{ for (i=1; i<=NF; i++) if ($i ~ /^digest=/) print $i }' \
    "$E/run-$run.log")
  printf '%s\t%s\t%s\n' "$run" "$rc" "$digest" >> "$E/runs.tsv"
  cat "$E/run-$run.log"
  test "$rc" -eq 0 || exit 1
  run=$((run + 1))
done
cat "$E/runs.tsv"
test "$(awk '$2 != 0 { bad++ } END { print bad + 0 }' "$E/runs.tsv")" -eq 0
test "$(awk '{ print $3 }' "$E/runs.tsv" | sort -u | wc -l | tr -d ' ')" -eq 1
grep 'mismatches=0' "$E"/run-*.log
umount "$MNT"
mdconfig -d -u "${unit#md}"
test -z "$(mount -p | awk -v m="$MNT" '$2 == m { print }')"
test -z "$(mdconfig -l | tr ' ' '\n' | grep -x "$unit")"
```

## PASS Gate

- Full source/mount SHA256 and bytes match.
- Each run compares exactly 16,384 source/target 4 KiB reads, reports zero
  mismatches, exits 0, and produces the same deterministic digest.
- IOPS, mean microseconds, and elapsed time are recorded only as TCG metrics.
- No fixed speed gate, panic, hang, or cleanup leak occurs.
