aien-protocols-mv
Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem
Brought by drakestapleton
aien-protocols-mv / specs / microjob / tools / check-vectors.sh
| 1 | #!/bin/bash |
| 2 | # check-vectors.sh: build the MJB1 reference checker and check the vectors. |
| 3 | # |
| 4 | # Usage: check-vectors.sh [CC] (default CC: cc) |
| 5 | # |
| 6 | # 1. Builds tools/mjb_verify.c with warnings as errors (C99, libc only). |
| 7 | # 2. Regenerates the vectors into a scratch directory (mjb_verify |
| 8 | # --make-vectors) and requires them byte-identical to vectors/, so a stale |
| 9 | # or hand-edited vector fails here. |
| 10 | # 3. Runs every vectors/expected.txt line (and re-encodes every accepted |
| 11 | # message, which must give the same bytes), plus an ASan/UBSan build when |
| 12 | # the compiler supports it. |
| 13 | # 4. Runs tools/mutate-verifier.sh: every check must be caught by a vector. |
| 14 | # Host-only check: no hardware. Shell and C only. Found by the PROTO-C-VECTORS |
| 15 | # gate (tests/gates/run.sh c-vectors) because its name matches check-*.sh. |
| 16 | set -eu |
| 17 | export LC_ALL=C |
| 18 | here=$(cd "$(dirname "$0")" && pwd) |
| 19 | vec="$here/../vectors" |
| 20 | CC=${1:-cc} |
| 21 | tmp=$(mktemp -d) |
| 22 | trap 'rm -rf "$tmp"' EXIT |
| 23 | |
| 24 | "$CC" -std=c99 -O2 -Wall -Wextra -Werror -pedantic -o "$tmp/mjb_verify" "$here/mjb_verify.c" |
| 25 | |
| 26 | mkdir -p "$tmp/regen" |
| 27 | "$tmp/mjb_verify" --make-vectors "$tmp/regen" |
| 28 | ignore="-x .crumb -x .crumb.local -x .gitattributes" |
| 29 | if ! diff -r $ignore "$vec" "$tmp/regen" >/dev/null; then |
| 30 | echo "MJB1_VECTORS_STALE: vectors/ differs from mjb_verify --make-vectors output" >&2 |
| 31 | diff -rq $ignore "$vec" "$tmp/regen" >&2 || true |
| 32 | exit 1 |
| 33 | fi |
| 34 | echo "MJB1_VECTORS_REGEN identical" |
| 35 | |
| 36 | "$tmp/mjb_verify" --corpus "$vec" |
| 37 | |
| 38 | if "$CC" -std=c99 -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \ |
| 39 | -o "$tmp/mjb_verify_san" "$here/mjb_verify.c" 2>/dev/null; then |
| 40 | "$tmp/mjb_verify_san" --corpus "$vec" | sed 's/^MJB1_CONFORMANCE impl=c/MJB1_CONFORMANCE impl=c-asan-ubsan/' |
| 41 | test "${PIPESTATUS[0]}" -eq 0 |
| 42 | else |
| 43 | echo "MJB1_SANITIZER NOT_RUN (compiler lacks -fsanitize=address,undefined)" |
| 44 | fi |
| 45 | |
| 46 | bash "$here/mutate-verifier.sh" "$CC" |
| 47 | echo "MJB1_VECTORS_PASS" |