Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-protocols-mv/blob/main/specs/osh-platform/tools/check-stream-vectors.sh # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 _.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. 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 # 1. header lint 25 bad=0 26 n=0 27 for 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_ or tNNN_" >&2; bad=1 ;; 41 esac 42 echo "$c" >>"$tmp/cases" 43 done 44 test "$n" -gt 0 || { echo "OSHSV1_LINT no stream or task vectors found" >&2; exit 1; } 45 dups=$(sort "$tmp/cases" | uniq -d) 46 test -z "$dups" || { echo "OSHSV1_LINT duplicate case names: $dups" >&2; bad=1; } 47 test "$bad" -eq 0 || exit 1 48 echo "OSHSV1_LINT ok vectors=$n" 49 50 # 2. reference model, plain and sanitized 51 corpus=$(git -C "$here" rev-parse HEAD 2>/dev/null || echo unpinned) 52 tc=$("$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" 55 if "$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 59 else 60 echo "OSHSV1_SANITIZER NOT_RUN (compiler lacks -fsanitize=address,undefined)" 61 fi 62 63 # 3. every check has teeth 64 bash "$here/mutate-stream-ref.sh" "$CC" 65 66 # 4. the shell-core corpus is untouched 67 mkdir -p "$tmp/core" 68 bash "$here/make-vectors.sh" "$tmp/core" 69 for 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; } 71 done 72 for 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; } 74 done 75 echo "OSHSV1_CORE_REGEN identical" 76 echo "OSHSV1_VECTORS_PASS"