#!/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-200 "$ref") <(cut -c1-200 "$OURS/$name" 2>/dev/null) | head -4 | tr '\n' ' ') echo "DIFFERENT ${name%.trace}: $first" fi done stats=$(cat "$REFDIR"/*.trace | awk ' $1 == "T" { t += 1 } $1 ~ /^T\*/ { t += substr($1, 3) } $1 == "S" { s++ } $1 == "r" { r++ } $1 == "k" || $1 == "I" || $1 == "D" { e++ } END { print t + 0, s + 0, r + 0, e + 0 }') read -r ticks states reads events <<< "$stats" echo "$LABEL: $same of $total traces identical ($ticks ticks, $reads reads, $states state lines, $events wiring calls)" [ $status = 0 ] && echo "$LABEL: PASS" || echo "$LABEL: FAIL" exit $status