#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Compare two directories of traces byte for byte: compare_traces.sh REF OURS LABEL. # Exit 0 when every reference trace has an identical twin. set -uo pipefail REFDIR=$1; OURS=$2; LABEL=$3 status=0; same=0; total=0 for ref in "$REFDIR"/*.trace; do total=$((total + 1)) name=$(basename "$ref") if cmp -s "$ref" "$OURS/$name"; then same=$((same + 1)) else status=1 first=$(diff <(cut -c1-160 "$ref") <(cut -c1-160 "$OURS/$name" 2>/dev/null) | head -4 | tr '\n' ' ') echo "DIFFERENT ${name%.trace}: $first" fi done stats=$(cat "$REFDIR"/*.trace | awk '$1=="take"{n+=$2} $1=="S"{s++} END{print n+0, s+0}') echo "$LABEL: $same of $total traces identical ($(echo "$stats" | cut -d' ' -f1) samples, $(echo "$stats" | cut -d' ' -f2) state lines)" [ $status = 0 ] && echo "$LABEL: PASS" || echo "$LABEL: FAIL" exit $status