interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / microjob / tools / check-vectors.sh

47 lines · 1908 bytes Raw Blame History
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.
16set -eu
17export LC_ALL=C
18here=$(cd "$(dirname "$0")" && pwd)
19vec="$here/../vectors"
20CC=${1:-cc}
21tmp=$(mktemp -d)
22trap 'rm -rf "$tmp"' EXIT
23
24"$CC" -std=c99 -O2 -Wall -Wextra -Werror -pedantic -o "$tmp/mjb_verify" "$here/mjb_verify.c"
25
26mkdir -p "$tmp/regen"
27"$tmp/mjb_verify" --make-vectors "$tmp/regen"
28ignore="-x .crumb -x .crumb.local -x .gitattributes"
29if ! 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
33fi
34echo "MJB1_VECTORS_REGEN identical"
35
36"$tmp/mjb_verify" --corpus "$vec"
37
38if "$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
42else
43 echo "MJB1_SANITIZER NOT_RUN (compiler lacks -fsanitize=address,undefined)"
44fi
45
46bash "$here/mutate-verifier.sh" "$CC"
47echo "MJB1_VECTORS_PASS"