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 / osh-platform / tools / check-stream-vectors.sh

76 lines · 3685 bytes Raw Blame History
1#!/bin/bash
2# check-stream-vectors.sh: check the OSH stream and task vectors (vectors/s*.vec, vectors/t*.vec) against the
3# reference model, and guard the shell-core corpus next to them.
4#
5# Usage: check-stream-vectors.sh [CC] (default CC: cc)
6#
7# 1. Lints every s*.vec / t*.vec header (case, kind, exec, domain, needs; file name ends in _<case>.vec;
8# case names unique).
9# 2. Builds tools/osh_sv_ref.c with warnings as errors (C99, libc only) and runs the corpus; every vector must
10# PASS. Then the same with ASan/UBSan when the compiler supports it.
11# 3. Runs tools/mutate-stream-ref.sh: every check of the model must be caught by a vector.
12# 4. Regenerates the shell-core inputs (tools/make-vectors.sh) into a scratch directory and requires them
13# byte-identical to vectors/v*.in and v*.env, so the stream corpus never disturbs the existing format.
14# Host-only check of the corpus: it is not evidence about any adapter and qualifies no hardware. Shell and C
15# only. Found by the PROTO-C-VECTORS 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# 1. header lint
25bad=0
26n=0
27for f in "$vec"/s*.vec "$vec"/t*.vec; do
28 [ -e "$f" ] || continue
29 n=$((n + 1))
30 b=$(basename "$f" .vec)
31 c=$(sed -n 's/^case \([a-z0-9_]*\)$/\1/p' "$f" | head -n 1)
32 for key in case kind exec domain needs; do
33 grep -q "^$key " "$f" || { echo "OSHSV1_LINT $b: missing '$key' line" >&2; bad=1; }
34 done
35 grep -q -E '^kind (positive|negative)$' "$f" || { echo "OSHSV1_LINT $b: kind must be positive or negative" >&2; bad=1; }
36 grep -q -E '^exec (host-logic|native-qemu)$' "$f" || { echo "OSHSV1_LINT $b: exec must be host-logic or native-qemu" >&2; bad=1; }
37 grep -q -E '^domain (1|2|any)$' "$f" || { echo "OSHSV1_LINT $b: domain must be 1, 2 or any" >&2; bad=1; }
38 case "$b" in
39 [st][0-9][0-9][0-9]_"$c") ;;
40 *) echo "OSHSV1_LINT $b: file name must be sNNN_<case> or tNNN_<case>" >&2; bad=1 ;;
41 esac
42 echo "$c" >>"$tmp/cases"
43done
44test "$n" -gt 0 || { echo "OSHSV1_LINT no stream or task vectors found" >&2; exit 1; }
45dups=$(sort "$tmp/cases" | uniq -d)
46test -z "$dups" || { echo "OSHSV1_LINT duplicate case names: $dups" >&2; bad=1; }
47test "$bad" -eq 0 || exit 1
48echo "OSHSV1_LINT ok vectors=$n"
49
50# 2. reference model, plain and sanitized
51corpus=$(git -C "$here" rev-parse HEAD 2>/dev/null || echo unpinned)
52tc=$("$CC" --version 2>/dev/null | head -n 1 | tr ' ' '_')
53"$CC" -std=c99 -O2 -Wall -Wextra -Werror -pedantic -o "$tmp/ref" "$here/osh_sv_ref.c"
54"$tmp/ref" --corpus "$vec" --pin "corpus=$corpus" --pin "toolchain=$tc"
55if "$CC" -std=c99 -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \
56 -o "$tmp/ref_san" "$here/osh_sv_ref.c" 2>/dev/null; then
57 "$tmp/ref_san" --corpus "$vec" | sed 's/impl=reference-model/impl=reference-model-asan-ubsan/' | grep -v '^PASS '
58 test "${PIPESTATUS[0]}" -eq 0
59else
60 echo "OSHSV1_SANITIZER NOT_RUN (compiler lacks -fsanitize=address,undefined)"
61fi
62
63# 3. every check has teeth
64bash "$here/mutate-stream-ref.sh" "$CC"
65
66# 4. the shell-core corpus is untouched
67mkdir -p "$tmp/core"
68bash "$here/make-vectors.sh" "$tmp/core"
69for f in "$tmp"/core/v*; do
70 cmp -s "$f" "$vec/$(basename "$f")" || { echo "OSHSV1_CORE_STALE $(basename "$f") differs from make-vectors.sh" >&2; exit 1; }
71done
72for f in "$vec"/v*.in "$vec"/v*.env; do
73 [ -e "$tmp/core/$(basename "$f")" ] || { echo "OSHSV1_CORE_STALE $(basename "$f") is not generated" >&2; exit 1; }
74done
75echo "OSHSV1_CORE_REGEN identical"
76echo "OSHSV1_VECTORS_PASS"