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 / seed / qualification / om2 / every.sh

130 lines · 8349 bytes Raw Blame History
1#!/bin/sh
2# every.sh -- run seed/qualification/om2/gate.om over EVERY seed/omc/om2/*/*.cases file (ROADMAP-1.0 RM1)
3# and the error-site fixtures seed/omc/sites/*.cases (RM8), plus the qualification files listed below,
4# so a regression in any OM-2 stage is visible to seed/host/check.sh, not only s5.
5# A case file must PASS with fail=0 invalid=0 not_run=0. A mutant file (*mutants.cases) must make the
6# gate exit 1 with every ctl-* case PASS, every other case FAIL (the mutant was caught) and none
7# INVALID or NOT_RUN. Two negative controls prove this script itself fails: a case with a wrong expected
8# exit, a mutant file whose substitutions are removed (its mutants then survive), and a wrong compiler
9# identity (every case NOT_RUN, none declared).
10# Run from the repository root. Prints OM2EVERY PASS files=F cases=C skipped_declared=K mutants=M
11# (C counts cases that ran; K counts declared notrun cases).
12set -eu
13R=$(pwd)
14B=$R/build/seed/om2every
15rm -rf "$B"; mkdir -p "$B"
16"$R/seed/out/omc" < "$R/seed/qualification/om2/gate.om" > "$B/gate"
17chmod +x "$B/gate"
18pin=$(sha256sum "$R/seed/out/omc" | cut -d' ' -f1)
19bad() { printf 'OM2EVERY FAIL %s\n' "$*" >&2; exit 1; }
20n=0
21# anchors FILE: every "subst FROM TO" row of FILE must find FROM exactly once in the source the next case
22# compiles (the gate's own rule, INVALID otherwise). Checked here for all files at once, before any case
23# runs, so one stale mutation recipe cannot hide the others and names its file, line and match count.
24# Sources joined with + or given as pack:/cyc: segments are left to the gate, which enforces the same rule.
25anchors() {
26 awk -v cf="$1" '
27 function whole(p, x, r) { r = RS; RS = "\001"; x = ""; if ((getline x < p) < 0) x = "\001unreadable"; close(p); RS = r; return x }
28 NF == 0 || $1 ~ /^#/ { next }
29 $1 == "subst" { from = $2; at = NR; next }
30 from == "" || $1 == "deadline" { next }
31 {
32 src = ($1 == "cc") ? $2 : $3
33 if (src != "pinned" && src !~ /[:+]/) {
34 h = whole(src); n = whole(from); c = 0
35 if (n != "" && h != "\001unreadable" && n != "\001unreadable") {
36 while ((i = index(h, n)) > 0) { c++; h = substr(h, i + 1) }
37 } else c = -1
38 if (c != 1) { printf "%s:%d: %s matches %d times in %s (need exactly 1)\n", cf, at, from, c, src; bad++ }
39 }
40 from = ""
41 }
42 END { exit bad > 0 }' "$1"
43}
44stale=0
45for c in seed/omc/om2/*/*.cases seed/omc/sites/*.cases; do
46 anchors "$c" >> "$B/anchors.log" || stale=1
47done
48[ "$stale" = 0 ] || { cat "$B/anchors.log" >&2; bad "stale mutation anchors (list above)"; }
49# judge FILE LOG STATUS: 0 when the run is what FILE's kind requires, else prints why and returns 1.
50# A case file may skip only the cases it declares with a notrun line (a planned case whose prerequisite,
51# such as the omega-bridge ABI generator, is absent): the NOT_RUN count must equal those lines and every
52# NOT_RUN verdict must be the declared kind ("NOT_RUN not run:"), never an identity or build failure.
53judge() {
54 sum=$(grep '^OM2GATE ' "$2" | tail -1)
55 dn=$(grep -c '^[^ #]* notrun ' "$1") || true
56 vn=$(grep -c '^VERDICT [^ ]* NOT_RUN not run:' "$2") || true
57 an=$(grep -c '^VERDICT [^ ]* NOT_RUN' "$2") || true
58 [ "$dn" = "$vn" ] && [ "$vn" = "$an" ] || { echo "declared notrun $dn, declared NOT_RUN verdicts $vn, all NOT_RUN $an"; return 1; }
59 case "$sum" in *" invalid=0 not_run=$dn") ;; *) echo "summary: $sum"; return 1 ;; esac
60 case "$1" in
61 *mutants.cases)
62 [ "$3" = 1 ] || { echo "mutant file exit $3, expected 1"; return 1; }
63 k=$(grep -c '^VERDICT ' "$2") || true
64 cp=$(grep -c '^VERDICT ctl-[^ ]* PASS' "$2") || true
65 mf=$(grep '^VERDICT ' "$2" | grep -v '^VERDICT ctl-' | grep -c '^VERDICT [^ ]* FAIL') || true
66 mt=$(grep '^VERDICT ' "$2" | grep -vc '^VERDICT ctl-') || true
67 [ "$mt" -gt 0 ] || { echo "no mutant cases"; return 1; }
68 [ "$mf" = "$mt" ] || { echo "mutant survived: caught $mf of $mt"; return 1; }
69 [ "$cp" = $((k - mt)) ] || { echo "control failed: $cp of $((k - mt)) PASS"; return 1; }
70 n=$mt ;;
71 *)
72 if [ "$dn" = 0 ]; then w=0 v=PASS; else w=2 v=NOT_RUN; fi
73 [ "$3" = "$w" ] || { echo "exit $3, expected $w"; return 1; }
74 case "$sum" in "OM2GATE $v cases="*" fail=0 "*) ;; *) echo "summary: $sum"; return 1 ;; esac
75 n=$(echo "$sum" | sed 's/.* cases=\([0-9]*\) .*/\1/'); n=$((n - dn)) ;;
76 esac
77}
78# run FILE TAG: gate FILE and judge it; prints its case count, or the reason and returns 1.
79run() {
80 st=0
81 "$B/gate" "$R/seed/out/omc" "${PIN:-$pin}" "$1" "$B/s-$2" > "$B/$2.log" 2>&1 || st=$?
82 judge "$1" "$B/$2.log" "$st" && echo "$n"
83}
84files=0 cases=0 muts=0
85for c in seed/omc/om2/*/*.cases seed/omc/sites/*.cases; do
86 t=$(echo "$c" | tr / _)
87 n=$(run "$c" "$t") || bad "$c: $n (log $B/$t.log)"
88 case "$c" in *mutants.cases) muts=$((muts + n)) ;; *) cases=$((cases + n)) ;; esac
89 files=$((files + 1))
90 printf 'PASS %s (%s)\n' "$c" "$n"
91done
92# Qualification files that pass on the committed compiler (the four sec/leak candidate files skip only
93# their declared notrun cases). The other files under
94# seed/qualification are left out on purpose: pinned.cases run against the OM-1 reference omc 734f0a39,
95# and mutant and selftest fail/controls files are designed failures run by their own drivers.
96for c in seed/qualification/om2/baseline/guard.cases seed/qualification/om2/baseline/language.cases \
97 seed/qualification/om2/baseline/sha256.cases seed/qualification/om2/baseline/transform.cases \
98 seed/qualification/om2/sec/s4fuel/candidate.cases seed/qualification/om2/selftest/pass.cases \
99 seed/qualification/security673/relational/bindings.cases \
100 seed/qualification/security673/relational/consumer.cases \
101 seed/qualification/security673/relational/l4-tripwire.cases \
102 seed/qualification/security673/relational/qualification.cases \
103 seed/qualification/om2/sec/s0s2/candidate.cases seed/qualification/om2/sec/s3s4/candidate.cases \
104 seed/qualification/om2/sec/s5s7/candidate.cases seed/qualification/om2/leak/candidate.cases; do
105 t=$(echo "$c" | tr / _)
106 n=$(run "$c" "$t") || bad "$c: $n (log $B/$t.log)"
107 cases=$((cases + n)); files=$((files + 1))
108 printf 'PASS %s (%s)\n' "$c" "$n"
109done
110[ "$files" -gt 0 ] || bad "no case files"
111# negative control 1: the first run case of s1 with its expected exit changed must be refused.
112awk '!d && $2 == "run" { $NF = $NF + 1; d = 1 } { print }' seed/omc/om2/s1/s1.cases > "$B/neg1.cases"
113cmp -s seed/omc/om2/s1/s1.cases "$B/neg1.cases" && bad "negative control 1 did not change the file"
114run "$B/neg1.cases" neg1 > /dev/null && bad "negative control 1 (wrong expected exit) was accepted"
115printf 'PASS negative control: a wrong expected exit is refused\n'
116# negative control 2: s4's mutants without their substitutions (mutants survive) must be refused.
117grep -v '^subst ' seed/omc/om2/s4/s4-mutants.cases > "$B/neg2-mutants.cases"
118run "$B/neg2-mutants.cases" neg2 > /dev/null && bad "negative control 2 (surviving mutants) was accepted"
119printf 'PASS negative control: surviving mutants are refused\n'
120# negative control 3: an undeclared NOT_RUN (wrong compiler identity: every case NOT_RUN) must be refused.
121PIN=0000000000000000000000000000000000000000000000000000000000000000 run seed/qualification/om2/sec/s0s2/candidate.cases neg3 > /dev/null && bad "negative control 3 (undeclared NOT_RUN) was accepted"
122printf 'PASS negative control: an undeclared NOT_RUN is refused\n'
123# negative control 4: a substitution whose FROM text is absent from its source must be refused by the preflight.
124printf 'no such text in omc.om\n' > "$B/neg4.from"
125printf 'subst %s/neg4.from seed/omc/om2/bnd/mutants/bnd-extra.to\ncc seed/omc/omc.om\n' "$B" > "$B/neg4.cases"
126anchors "$B/neg4.cases" > /dev/null && bad "negative control 4 (stale mutation anchor) was accepted"
127printf 'PASS negative control: a stale mutation anchor is refused\n'
128sk=$(cat seed/qualification/om2/sec/s0s2/candidate.cases seed/qualification/om2/sec/s3s4/candidate.cases \
129 seed/qualification/om2/sec/s5s7/candidate.cases seed/qualification/om2/leak/candidate.cases | grep -c '^[^ #]* notrun ') || true
130printf 'OM2EVERY PASS files=%s cases=%s skipped_declared=%s mutants=%s\n' "$files" "$cases" "$sk" "$muts"