omnet
aien-dev/omnet
Brought by drakestapleton
omnet / om / tka / test / run.sh
| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd) |
| 4 | OMC=${1:-} |
| 5 | if [ -z "$OMC" ]; then OMC=$("$ROOT/tools/omc.sh"); fi |
| 6 | GO=${TKA_GO:-${GO:-go}} |
| 7 | TMP=$(mktemp -d) |
| 8 | trap 'rm -rf "$TMP"' EXIT HUP INT TERM |
| 9 | cd "$ROOT/om/tka/test/oracle" |
| 10 | GOTOOLCHAIN=local "$GO" build -mod=readonly -o "$TMP/oracle" . |
| 11 | "$TMP/oracle" "$TMP/input" "$TMP/expected" "$ROOT/om/cbor/test/vectors" |
| 12 | cat "$ROOT/om/blake2s/blake2s.om" "$ROOT/om/sha512/sha512.om" "$ROOT/om/ed25519/ed25519.om" "$ROOT/om/cbor/cbor.om" > "$TMP/base.om" |
| 13 | cat "$TMP/base.om" "$ROOT/om/tka/tka.om" "$ROOT/om/tka/tkastate.om" "$ROOT/om/tka/tkapool.om" "$ROOT/om/tka/test/driver.om" > "$TMP/driver.om" |
| 14 | "$OMC" < "$TMP/driver.om" > "$TMP/driver" |
| 15 | chmod +x "$TMP/driver" |
| 16 | "$TMP/driver" < "$TMP/input" > "$TMP/actual" |
| 17 | python3 "$ROOT/om/tka/test/check.py" "$TMP/expected" "$TMP/actual" exact |
| 18 | python3 - "$TMP/driver.om" "$TMP/mutant.om" <<'PY' |
| 19 | import pathlib,sys |
| 20 | s=pathlib.Path(sys.argv[1]).read_text() |
| 21 | old='ret edverify pk msg 32 sg 1' |
| 22 | assert s.count(old)==1 |
| 23 | pathlib.Path(sys.argv[2]).write_text(s.replace(old,'ret 1')) |
| 24 | PY |
| 25 | "$OMC" < "$TMP/mutant.om" > "$TMP/mutant" |
| 26 | chmod +x "$TMP/mutant" |
| 27 | "$TMP/mutant" < "$TMP/input" > "$TMP/mutant.actual" |
| 28 | python3 "$ROOT/om/tka/test/check.py" "$TMP/expected" "$TMP/mutant.actual" mutant |
| 29 | "$TMP/oracle" --fixture > "$TMP/fixture.json" |
| 30 | python3 - "$TMP/fixture.json" "$TMP/revocation.input" <<'PY' |
| 31 | import json,pathlib,struct,sys |
| 32 | v=json.loads(pathlib.Path(sys.argv[1]).read_text()) |
| 33 | b=bytearray() |
| 34 | for key in ("genesis","signature","node","removal"): |
| 35 | data=bytes.fromhex(v[key]) |
| 36 | if key != "node": |
| 37 | b.extend(struct.pack("<I",len(data))) |
| 38 | b.extend(data) |
| 39 | pathlib.Path(sys.argv[2]).write_bytes(b) |
| 40 | PY |
| 41 | cat "$TMP/base.om" "$ROOT/om/tka/tka.om" "$ROOT/om/tka/tkastate.om" "$ROOT/om/tka/tkapool.om" "$ROOT/om/tkasig/tkasig.om" "$ROOT/om/tka/test/revocation.om" > "$TMP/revocation.om" |
| 42 | "$OMC" < "$TMP/revocation.om" > "$TMP/revocation" |
| 43 | chmod +x "$TMP/revocation" |
| 44 | "$TMP/revocation" < "$TMP/revocation.input" |
| 45 | printf '%s\n' 'tka: PASS cross-unit node-signature revocation' |
| 46 | printf '%s\n' 'tka: PASS (differential model, authority, sync, signature mutant)' |