omnet
aien-dev/omnet
Brought by drakestapleton
omnet / om / codec / test / gen / check-tailscale.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # One-time cross-check of gen/oracle's transcription of tailscale.com v1.102.0 tka.AUMHash and |
| 4 | # key.NodePublic text methods against the real package. Not run by run.sh: it needs network access |
| 5 | # for the tailscale.com module and a Go toolchain >= 1.26.5 (that module's minimum), while |
| 6 | # gen/oracle is built with go1.26.0. |
| 7 | # Usage: sh om/codec/test/gen/check-tailscale.sh [SEED...] (default seeds 1 2 3) |
| 8 | # Environment: GO (default go). Exit 0 only when both referees agree on every case. |
| 9 | set -eu |
| 10 | here=$(cd "$(dirname "$0")" && pwd) |
| 11 | root=$(cd "$here/../../../.." && pwd) |
| 12 | out="$root/build/test/codec/tscheck" |
| 13 | go=${GO:-go} |
| 14 | mkdir -p "$out" |
| 15 | (cd "$here/oracle" && GOTOOLCHAIN=go1.26.0 "$go" build -o "$out/oracle" .) |
| 16 | (cd "$here/tsoracle" && GOTOOLCHAIN=local "$go" build -o "$out/tsoracle" .) |
| 17 | echo "codec: oracle $(GOTOOLCHAIN=go1.26.0 "$go" version)" |
| 18 | echo "codec: tsoracle $(GOTOOLCHAIN=local "$go" version)" |
| 19 | fail=0 |
| 20 | check() { # check NAME CASEFILE |
| 21 | grep -E '^(aume|aumd|nkye|nkyd) ' "$2" > "$out/$1.in" || true |
| 22 | "$out/oracle" < "$out/$1.in" > "$out/$1.oracle" |
| 23 | "$out/tsoracle" < "$out/$1.in" > "$out/$1.ts" |
| 24 | n=$(wc -l < "$out/$1.in" | tr -d ' ') |
| 25 | if cmp -s "$out/$1.oracle" "$out/$1.ts"; then |
| 26 | echo "codec: tailscale cross-check $1 $n/$n PASS" |
| 27 | else |
| 28 | echo "codec: tailscale cross-check $1 FAIL ($(cmp "$out/$1.oracle" "$out/$1.ts" 2>&1 || true))" |
| 29 | fail=1 |
| 30 | fi |
| 31 | } |
| 32 | "$out/oracle" corpus | grep -v '^#' > "$out/corpus.cases" |
| 33 | check corpus "$out/corpus.cases" |
| 34 | [ $# -gt 0 ] || set -- 1 2 3 |
| 35 | for s in "$@"; do |
| 36 | "$out/oracle" rand "$s" > "$out/rand-$s.cases" |
| 37 | check "rand-$s" "$out/rand-$s.cases" |
| 38 | done |
| 39 | exit "$fail" |