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 / tests / model / receipt.sh

146 lines · 6454 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# receipt.sh OUT_DIR [quiet] -- build OUT_DIR/LG-receipt.json from the logs
18# the proof targets wrote (model.log, diff.log, tsan.log). Every field is read
19# from a log or from git; nothing is assumed. A missing log is NOT_RUN.
20# Evidence class: host (CPU only; no QEMU, no hardware chip).
21set -u
22out=$1
23mode=${2:-run}
24rcpt=$out/LG-receipt.json
25
26commit=$(git rev-parse HEAD 2>/dev/null || echo unknown)
27if [ -n "$(git status --porcelain 2>/dev/null)" ]; then dirty=true; else dirty=false; fi
28cc_ver=$(${CC:-gcc} --version 2>/dev/null | head -n1)
29host=$(uname -srm)
30now=$(date -u +%Y-%m-%dT%H:%M:%SZ)
31
32# get KEY: value of the last "RESULT KEY=..." line in any log, else empty.
33get() {
34 cat "$out/model.log" "$out/diff.log" "$out/tsan.log" 2>/dev/null |
35 sed -n "s/^RESULT $1=//p" | tail -n1
36}
37# tsan values come only from tsan.log (the tsan build prints the same keys).
38get_tsan() { sed -n "s/^RESULT $1=//p" "$out/tsan.log" 2>/dev/null | tail -n1; }
39get_main() {
40 cat "$out/model.log" "$out/diff.log" 2>/dev/null | sed -n "s/^RESULT $1=//p" | tail -n1
41}
42esc() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'; }
43or_nr() { if [ -z "$1" ]; then echo NOT_RUN; else echo "$1"; fi; }
44
45if [ "$mode" = quiet ]; then
46 cat > "$rcpt" <<EOF
47{
48 "lane": "LG",
49 "evidence": "host",
50 "commit": "$commit",
51 "tree_dirty": $dirty,
52 "generated": "$now",
53 "verdict": "NOT_RUN",
54 "reason": "quiet flag set; nothing was built or run"
55}
56EOF
57 echo "receipt: $rcpt (NOT_RUN)"
58 exit 0
59fi
60
61model_v=$(or_nr "$(get_main model.verdict)")
62diff_v=$(or_nr "$(get_main diff.verdict)")
63wd_v=$(or_nr "$(get_main world_diff.verdict)")
64tsan_v=$(get_tsan tsan)
65case "$tsan_v" in "") tsan_v=NOT_RUN ;; esac
66
67# Per invariant, from the observed results only.
68inv() { # name spec_key asbuilt_key mutant_key real_ok(yes/no/known)
69 s=$(get_main "model.SPEC.$2"); a=$(get_main "model.AS_BUILT.$2"); k=$(get_main "$3")
70 r=$4
71 if [ -z "$s" ] || [ -z "$a" ] || [ -z "$k" ]; then echo NOT_RUN; return; fi
72 if [ "$s" != PASS ] || [ "$k" != KILLED ]; then echo FAIL; return; fi
73 if [ "$a" = PASS ] && [ "$r" = yes ]; then echo PASS; return; fi
74 if [ "$a" = KNOWN_FAIL ] && [ "$r" = known ]; then echo KNOWN_FAIL; return; fi
75 echo FAIL
76}
77z() { [ "$(get_main "$1")" = 0 ]; }
78if [ "$diff_v" = PASS ] && z real.I1.settled_leak_violations && z real.I1.quiescent_leak_violations &&
79 [ "$(get_main diff.DIFF_MUT_LEAK_ON_FAIL)" = KILLED ] && [ "$(get_main shim.real_leak_check)" = KILLED ]; then
80 r1=yes; else r1=no; fi
81if [ "$diff_v" = PASS ] && z real.I3.duplicate_commit_runs &&
82 [ "$(get_main diff.DIFF_MUT_COMMIT_KEEPS_ACTIVATION)" = KILLED ] &&
83 [ "$(get_main shim.commit_unique_check)" = KILLED ]; then r3=yes; else r3=no; fi
84if [ "$(get_main real.I2.directed)" = KNOWN_FAIL ]; then r2=known; else r2=no; fi
85if [ "$(get_main real.I4.directed)" = KNOWN_FAIL ]; then r4=known; else r4=no; fi
86i1=$(inv I1 I1_no_budget_leak model.MUT_LEAK_ON_FAIL.I1_no_budget_leak "$r1")
87i2=$(inv I2 I2_cancel_reaches_children model.MUT_CANCEL_NO_PROPAGATE.I2_cancel_reaches_children "$r2")
88i3=$(inv I3 I3_no_double_commit model.MUT_COMMIT_KEEPS_ACTIVATION.I3_no_double_commit "$r3")
89i4=$(inv I4 I4_deadline_overrun_surfaced model.MUT_DEADLINE_ADMIT_ONLY.I4_deadline_overrun_surfaced "$r4")
90
91overall=PASS
92for v in "$model_v" "$wd_v"; do [ "$v" = PASS ] || overall=FAIL; done
93for v in "$i1" "$i2" "$i3" "$i4"; do case "$v" in PASS|KNOWN_FAIL) ;; *) overall=FAIL ;; esac; done
94case "$tsan_v" in PASS|NOT_RUN*) ;; *) overall=FAIL ;; esac
95if [ "$overall" = PASS ]; then for v in "$i1" "$i2" "$i3" "$i4"; do [ "$v" = KNOWN_FAIL ] && overall=PASS_WITH_KNOWN_FAIL; done; fi
96
97{
98 echo "{"
99 echo " \"lane\": \"LG\","
100 echo " \"evidence\": \"host\","
101 echo " \"commit\": \"$commit\","
102 echo " \"tree_dirty\": $dirty,"
103 echo " \"generated\": \"$now\","
104 echo " \"host\": \"$(esc "$host")\","
105 echo " \"compiler\": \"$(esc "$cc_ver")\","
106 echo " \"verdict\": \"$overall\","
107 echo " \"model_check\": \"$model_v\","
108 echo " \"differential\": \"$diff_v\","
109 echo " \"tsan\": \"$(esc "$tsan_v")\","
110 echo " \"invariants\": {"
111 echo " \"I1_no_budget_leak\": \"$i1\","
112 echo " \"I2_cancel_reaches_children\": \"$i2\","
113 echo " \"I3_no_double_commit\": \"$i3\","
114 echo " \"I4_deadline_overrun_surfaced\": \"$i4\""
115 echo " },"
116 echo " \"findings\": {"
117 echo " \"I2_counterexample\": \"$(esc "$(get_main real.I2.counterexample)")\","
118 echo " \"I2_children_in_flight_after_cancel\": \"$(esc "$(get_main real.I2.children_in_flight_after_cancel)")\","
119 echo " \"I2_child_commit_after_cancel\": \"$(get_main real.I2.child_commit_after_cancel)\","
120 echo " \"I4_counterexample\": \"$(esc "$(get_main real.I4.counterexample)")\","
121 echo " \"I4_spec_overdue\": \"$(get_main real.I4.spec_overdue)\","
122 echo " \"I4_real_deadline_overdue\": \"$(get_main real.I4.real_deadline_overdue)\","
123 echo " \"I4_late_commit_published\": \"$(get_main real.I4.late_commit_published)\""
124 echo " },"
125 echo " \"results\": {"
126 first=1
127 for f in model.log diff.log; do
128 [ -f "$out/$f" ] || continue
129 sed -n 's/^RESULT \([^=]*\)=\(.*\)$/\1\t\2/p' "$out/$f"
130 done | while IFS=" " read -r k v; do
131 if [ $first = 1 ]; then first=0; else printf ',\n'; fi
132 printf ' "%s": "%s"' "$(esc "$k")" "$(esc "$v")"
133 done
134 echo
135 echo " },"
136 echo " \"tsan_results\": {"
137 if [ -f "$out/tsan.log" ]; then
138 sed -n 's/^RESULT \(tsan[^=]*\|stress[^=]*\|world_diff.verdict\)=\(.*\)$/\1\t\2/p' "$out/tsan.log" |
139 awk -F'\t' 'BEGIN{n=0} {gsub(/\\/,"\\\\",$2); gsub(/"/,"\\\"",$2); printf "%s \"%s\": \"%s\"", (n++?",\n":""), $1, $2} END{print ""}'
140 fi
141 echo " }"
142 echo "}"
143} > "$rcpt"
144echo "receipt: $rcpt"
145echo "LG proof: $overall (I1=$i1 I2=$i2 I3=$i3 I4=$i4 model=$model_v diff=$diff_v tsan=$tsan_v)"
146case "$overall" in PASS|PASS_WITH_KNOWN_FAIL) exit 0 ;; *) exit 1 ;; esac