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 / osc-unit-artifact / tools / check-vectors.sh

45 lines · 2482 bytes Raw Blame History
1#!/bin/bash
2# check-vectors.sh: regenerate the vectors into a scratch directory, require
3# them byte-identical to the committed ones, then run the reference checker
4# over every line of vectors/expected.txt. Exit 1 on any difference.
5set -eu
6export LC_ALL=C
7here=$(cd "$(dirname "$0")" && pwd)
8tmp=$(mktemp -d)
9trap 'rm -rf "$tmp"' EXIT
10bash "$here/make-vectors.sh" "$tmp/vectors" "$tmp/keys"
11# the committed keys must also be the regenerated ones
12diff -r "$tmp/keys" "$here/../keys" >/dev/null || { echo "OSC_UNIT_KEYS_STALE" >&2; exit 1; }
13diff -r "$tmp/vectors" "$here/../vectors" -x README.md >/dev/null || { echo "OSC_UNIT_VECTORS_STALE" >&2; diff -rq "$tmp/vectors" "$here/../vectors" -x README.md >&2 || true; exit 1; }
14echo "OSC_UNIT_REGEN identical"
15fail=0; n=0
16while read -r name mode domains anchors rest; do
17 case $name in '#'*|'') continue ;; esac
18 got=$(bash "$here/osc-unit-check.sh" "$here/../vectors/$name" "$mode" "$domains" "$anchors")
19 n=$((n + 1))
20 if [ "$got" != "$rest" ]; then echo "MISMATCH $name: want '$rest' got '$got'" >&2; fail=1; fi
21done <"$here/../vectors/expected.txt"
22while read -r name mode domains anchors lname rest; do
23 case $name in '#'*|'') continue ;; esac
24 got=$(bash "$here/osc-unit-check.sh" "$here/../vectors/$name" "$mode" "$domains" "$anchors" "$lname")
25 n=$((n + 1))
26 if [ "$got" != "$rest" ]; then echo "MISMATCH lookup $name $lname: want '$rest' got '$got'" >&2; fail=1; fi
27done <"$here/../vectors/lookups.txt"
28while read -r name mode domains anchors state rest; do
29 case $name in '#'*|'') continue ;; esac
30 case $state in
31 gens=*) got=$(OSC_STATE_GENS="${state#gens=}" bash "$here/osc-unit-check.sh" "$here/../vectors/$name" "$mode" "$domains" "$anchors") ;;
32 noreserve) got=$(OSC_STATE_NORESERVE=1 bash "$here/osc-unit-check.sh" "$here/../vectors/$name" "$mode" "$domains" "$anchors") ;;
33 esac
34 n=$((n + 1))
35 if [ "$got" != "$rest" ]; then echo "MISMATCH state $name $state: want '$rest' got '$got'" >&2; fail=1; fi
36done <"$here/../vectors/state.txt"
37cc -std=c99 -O2 -Wall -Wextra -Werror -o "$tmp/launch" "$here/osc-launch-check.c"
38while read -r kinds args rest; do
39 case $kinds in '#'*|'') continue ;; esac
40 got=$("$tmp/launch" "$kinds" "$args")
41 n=$((n + 1))
42 if [ "$got" != "$rest" ]; then echo "MISMATCH launch $kinds $args: want '$rest' got '$got'" >&2; fail=1; fi
43done <"$here/../vectors/launch.txt"
44[ $fail -eq 0 ] || exit 1
45echo "OSC_UNIT_VECTORS_PASS $n vectors"