interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / tka / test / run.sh

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