interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / bench / inference_cost / tests / handover / run.sh

132 lines · 5848 bytes Raw Blame History
1#!/bin/sh
2# bench/inference_cost/tests/handover/run.sh [OMC]
3# Builds bench/inference_cost/handover.om with the pinned omc, runs every known-verdict case in
4# cases.txt on the TEST DATA in data/, checks the printed input digests against sha256sum, then
5# applies each mutant in mutants.txt to a temporary copy of handover.om and requires that it fails
6# at least one case. Tracked files are never changed; everything is built under
7# build/inference_cost/handover/.
8# Exit: 0 every case passes and every mutant is killed; 1 a case failed, a mutant survived or did
9# not apply; 3 NOT_RUN (omc is not the pinned compiler, or handover.om does not build).
10set -u
11HERE=$(cd "$(dirname "$0")" && pwd)
12REPO=$(cd "$HERE/../../../.." && pwd)
13OMC=${1:-$REPO/seed/out/omc}
14SRC=$REPO/bench/inference_cost/handover.om
15SCORER=$REPO/bench/inference_cost/scorer.om
16BUILD=$REPO/build/inference_cost/handover
17say() { printf '%s\n' "$*"; }
18not_run() { say "NOT_RUN: $*"; exit 3; }
19
20[ -x "$OMC" ] || not_run "no compiler at $OMC"
21want=$(awk '{print $1}' "$REPO/seed/out/omc.sha256")
22have=$(sha256sum "$OMC" | awk '{print $1}')
23[ "$have" = "$want" ] || not_run "omc sha256 $have is not the pin seed/out/omc.sha256 ($want)"
24# handover.om shares scorer.om's wire reader by leaving out scorer.om's fn main, which must be
25# the last function of the file; refuse to build anything else.
26[ "$(grep -c '^fn main to int$' "$SCORER")" = 1 ] || not_run "scorer.om has no single 'fn main to int' line"
27[ "$(sed -n '/^fn main to int$/,$p' "$SCORER" | grep -c '^fn ')" = 1 ] ||
28 not_run "scorer.om has a function after fn main; the shared-reader build would drop it"
29rm -rf "$BUILD"
30mkdir -p "$BUILD"
31
32build() { # source binary
33 { printf 'om2\n'; cat "$REPO/om/tls/sha2.om"; sed '/^fn main to int$/,$d' "$SCORER"; cat "$1"; } > "$2.om"
34 "$OMC" < "$2.om" > "$2" 2> "$2.err" || return 1
35 chmod +x "$2"
36}
37
38# run_cases BIN QUIET: every case in cases.txt; prints ok/FAIL lines unless QUIET; returns failures
39run_cases() {
40 rc_bin=$1
41 rc_fail=0
42 while IFS='|' read -r c_name c_exit c_first c_line c_args; do
43 case $c_name in ''|'#'*) continue ;; esac
44 # shellcheck disable=SC2086
45 c_out=$(cd "$HERE" && "$rc_bin" $c_args 2> /dev/null)
46 c_rc=$?
47 c_why=""
48 [ "$c_rc" = "$c_exit" ] || c_why="exit $c_rc, expected $c_exit"
49 c_got=$(printf '%s\n' "$c_out" | sed -n 1p)
50 [ -n "$c_why" ] || [ "$c_got" = "$c_first" ] || c_why="first line '$c_got', expected '$c_first'"
51 if [ -z "$c_why" ] && [ -n "$c_line" ]; then
52 printf '%s\n' "$c_out" | grep -Fqx -- "$c_line" || c_why="no line '$c_line'"
53 fi
54 if [ -z "$c_why" ] && [ -n "$c_first" ]; then
55 c_rules=$(printf '%s\n' "$c_out" | sed -n '2,6p' | cut -d' ' -f1 | tr '\n' ' ')
56 [ "$c_rules" = "rule1 rule2 rule3 rule4 rule5 " ] || c_why="rule lines '$c_rules'"
57 fi
58 if [ -z "$c_why" ] && [ -z "$c_first" ] && [ -n "$c_out" ]; then
59 c_why="usage error printed on stdout"
60 fi
61 if [ -n "$c_why" ]; then
62 rc_fail=$((rc_fail + 1))
63 [ "$2" = quiet ] || say "FAIL $c_name: $c_why"
64 else
65 [ "$2" = quiet ] || say "ok $c_name ($c_first exit $c_rc)"
66 fi
67 done < "$HERE/cases.txt"
68 return "$rc_fail"
69}
70
71# digests: every "sha256 <hex> <path>" line of one decision equals sha256sum of that file
72check_digests() {
73 cd_out=$(cd "$HERE" && "$1" om plain data/perm-0102 data/inc19 data/c1 data/c2 data/c3 2> /dev/null)
74 cd_n=0
75 cd_bad=0
76 for cd_p in data/perm-0102 data/inc19/run.txt data/inc19/attempts.txt data/c1/run.txt \
77 data/c1/attempts.txt data/c2/run.txt data/c2/attempts.txt data/c3/run.txt data/c3/attempts.txt; do
78 cd_want="sha256 $(cd "$HERE" && sha256sum "$cd_p" | awk '{print $1}') $cd_p"
79 cd_n=$((cd_n + 1))
80 [ "$(printf '%s\n' "$cd_out" | sed -n "$((cd_n + 6))p")" = "$cd_want" ] || cd_bad=$((cd_bad + 1))
81 done
82 [ "$(printf '%s\n' "$cd_out" | wc -l)" = $((cd_n + 6)) ] || cd_bad=$((cd_bad + 1))
83 return "$cd_bad"
84}
85
86say "== handover: build with omc $have"
87build "$SRC" "$BUILD/handover" || not_run "handover.om does not build: $(cat "$BUILD/handover.err")"
88say "== handover: known-verdict cases (TEST DATA)"
89fails=0
90run_cases "$BUILD/handover" loud || fails=$?
91if check_digests "$BUILD/handover"; then
92 say "ok input digests equal sha256sum of every file read"
93else
94 say "FAIL input digests differ from sha256sum"
95 fails=$((fails + 1))
96fi
97
98say "== handover: mutants (each must fail at least one case)"
99survived=0
100nm=0
101while IFS='|' read -r m_name m_from m_to; do
102 case $m_name in ''|'#'*) continue ;; esac
103 nm=$((nm + 1))
104 m_src=$BUILD/mutant-$m_name.om.src
105 [ "$(grep -cFx -- "$m_from" "$SRC")" = 1 ] || {
106 say "FAIL mutant $m_name: its line is not exactly once in handover.om: $m_from"
107 survived=$((survived + 1))
108 continue
109 }
110 awk -v f="$m_from" -v t="$m_to" '$0 == f { print t; next } { print }' "$SRC" > "$m_src"
111 if ! build "$m_src" "$BUILD/mutant-$m_name"; then
112 say "FAIL mutant $m_name does not compile: $(cat "$BUILD/mutant-$m_name.err")"
113 survived=$((survived + 1))
114 continue
115 fi
116 m_fail=0
117 run_cases "$BUILD/mutant-$m_name" quiet || m_fail=$?
118 if [ "$m_fail" -gt 0 ]; then
119 say "ok mutant $m_name killed by $m_fail case(s)"
120 else
121 say "FAIL mutant $m_name survived every case"
122 survived=$((survived + 1))
123 fi
124done < "$HERE/mutants.txt"
125[ "$nm" -gt 0 ] || { say "FAIL no mutants listed"; survived=$((survived + 1)); }
126
127if [ "$fails" -eq 0 ] && [ "$survived" -eq 0 ]; then
128 say "HANDOVER-TEST PASS cases ok, $nm mutants killed"
129 exit 0
130fi
131say "HANDOVER-TEST FAIL $fails case failure(s), $survived mutant(s) survived or did not apply"
132exit 1