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
omega-mv / tools / effect_cap64_receipt.sh
| 1 | #!/bin/bash |
| 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 | # effect_cap64_receipt.sh -- qualification receipt for the 64-bit effect |
| 18 | # capability generation migration (spec/effect-cap64-migration.md). |
| 19 | # |
| 20 | # tools/effect_cap64_receipt.sh [out-dir] (default: evidence/EFFECT_CAP64) |
| 21 | # |
| 22 | # Runs, on the committed tree only: |
| 23 | # - the pinned Aienux capability library, rebuilt from `git archive` of the |
| 24 | # commit in aienos.lock (AIENOS_REPO, default ~/workspace/aienos-repo) |
| 25 | # - make test-effect-cap64 (4 gates, physics-free) |
| 26 | # - make test-visor-core, test-visor-world, test-visor-authority |
| 27 | # - the non-energy host regression suites CI runs: test (M4 omegatool), |
| 28 | # r3 r7 r8 r9 r10 r11 r12 action-graph state-projection capability-query |
| 29 | # typed-results |
| 30 | # - a grep for 32-bit truncation of an effect capability generation, in the C |
| 31 | # sources and (tools/effect_cap64_om_trunc.sh) the OM-2 sources of omega |
| 32 | # Every make is wrapped in `flock $BENCH_LOCK`. Nothing under evidence/ is |
| 33 | # rewritten: the receipt is a NEW file named by the SHA-256 of its own bytes. |
| 34 | # The receipt says FAIL (and lists why) when any suite fails, the tree is |
| 35 | # dirty or changes during the run, or the pins do not match. |
| 36 | # Shell and coreutils only (git, sha256sum, grep, sed, awk, tar, make). |
| 37 | set -u |
| 38 | |
| 39 | HERE=$(cd "$(dirname "$0")/.." && pwd) |
| 40 | cd "$HERE" || exit 2 |
| 41 | OUTDIR=${1:-evidence/EFFECT_CAP64} |
| 42 | AIENOS_REPO=${AIENOS_REPO:-$HOME/workspace/aienos-repo} |
| 43 | PHYSICS_DIR=${PHYSICS_DIR:-$HOME/workspace/physics-r13} |
| 44 | BENCH_LOCK=${BENCH_LOCK:-$HOME/workspace/.argus-bench.lock} |
| 45 | Q=build/cap64q |
| 46 | LOGS=$Q/logs |
| 47 | REASONS=() |
| 48 | |
| 49 | head0=$(git rev-parse HEAD) |
| 50 | tree0=$(git rev-parse 'HEAD^{tree}') |
| 51 | dirty0=$(git status --porcelain) |
| 52 | [ -z "$dirty0" ] || REASONS+=("tree dirty at start") |
| 53 | run_id=$(date -u +%Y%m%dT%H%M%SZ) |
| 54 | |
| 55 | rm -rf "$Q" && mkdir -p "$LOGS" "$Q/aienos" |
| 56 | |
| 57 | # ---- pins ------------------------------------------------------------------- |
| 58 | aienos_pin=$(awk 'NF && $1 !~ /^#/ {print $1; exit}' aienos.lock) |
| 59 | physics_pin=$(awk 'NF && $1 !~ /^#/ {print $1; exit}' physics.lock) |
| 60 | physics_head=$(git -C "$PHYSICS_DIR" rev-parse HEAD 2>/dev/null || echo missing) |
| 61 | [ "$physics_head" = "$physics_pin" ] || REASONS+=("physics checkout $physics_head != physics.lock $physics_pin") |
| 62 | |
| 63 | aienos_src_tree=$(git -C "$AIENOS_REPO" rev-parse "$aienos_pin:native/capability" 2>/dev/null || echo missing) |
| 64 | if git -C "$AIENOS_REPO" archive "$aienos_pin" native/capability | tar -x -C "$Q/aienos" && |
| 65 | flock "$BENCH_LOCK" make -C "$Q/aienos/native/capability" > "$LOGS/aienos-lib.log" 2>&1; then |
| 66 | lib_ok=1 |
| 67 | else |
| 68 | lib_ok=0 |
| 69 | REASONS+=("AIENOS capability library did not build from $aienos_pin") |
| 70 | fi |
| 71 | LIB=$Q/aienos/native/capability/out/libaienos_capability.a |
| 72 | lib_sha=$( [ -f "$LIB" ] && sha256sum "$LIB" | awk '{print $1}' || echo null) |
| 73 | hdr_sha=$( [ -f "$Q/aienos/native/capability/aienos_capability.h" ] && |
| 74 | sha256sum "$Q/aienos/native/capability/aienos_capability.h" | awk '{print $1}' || echo null) |
| 75 | |
| 76 | # ---- suites ----------------------------------------------------------------- |
| 77 | SUITES_JSON="" |
| 78 | declare -A RC RUN FAILED |
| 79 | |
| 80 | counts() { # -> "run failed source" |
| 81 | local log=$1 r |
| 82 | r=$(awk '/^(PASS|FAIL) [0-9]+\/[0-9]+ *$/ { split($2, x, "/"); r += x[2]; f += x[2] - x[1]; n++ } |
| 83 | /TOTAL GATES: *[0-9]+ *\| *PASSED: *[0-9]+ *\| *FAILED: *[0-9]+/ { |
| 84 | match($0, /TOTAL GATES: *[0-9]+/); t = substr($0, RSTART, RLENGTH); gsub(/[^0-9]/, "", t) |
| 85 | match($0, /FAILED: *[0-9]+/); u = substr($0, RSTART, RLENGTH); gsub(/[^0-9]/, "", u) |
| 86 | r += t; f += u; n++ } |
| 87 | END { if (n) printf "%d %d\n", r, f }' "$log") |
| 88 | if [ -n "$r" ]; then echo "$r output"; return; fi |
| 89 | local rcpt |
| 90 | rcpt=$(grep -oE 'receipt: [^ ]+\.json' "$log" | tail -n 1 | awk '{print $2}') |
| 91 | if [ -n "$rcpt" ] && [ -f "$rcpt" ]; then |
| 92 | local line c f |
| 93 | line=$(grep -m1 '^ "totals":' "$rcpt") |
| 94 | if [ -n "$line" ]; then |
| 95 | c=$(printf '%s' "$line" | grep -oE '"checks": [0-9]+' | grep -oE '[0-9]+') |
| 96 | f=$(printf '%s' "$line" | grep -oE '"failures": [0-9]+' | grep -oE '[0-9]+') |
| 97 | else |
| 98 | c=$(grep -m1 -E '^ "checks": [0-9]+' "$rcpt" | grep -oE '[0-9]+') |
| 99 | f=$(grep -m1 -E '^ "failures": [0-9]+' "$rcpt" | grep -oE '[0-9]+') |
| 100 | fi |
| 101 | if [ -n "$c" ] && [ -n "$f" ]; then echo "$c $f receipt:$rcpt"; return; fi |
| 102 | fi |
| 103 | echo "0 0 exit-status-only" |
| 104 | } |
| 105 | |
| 106 | suite() { # suite <name> <out-dir> <make args...> |
| 107 | local name=$1 out=$2 |
| 108 | shift 2 |
| 109 | local log=$LOGS/$name.log |
| 110 | flock "$BENCH_LOCK" env OMEGA_CANDIDATE_COMMIT="$head0" AIENOS_COMMIT="$aienos_pin" \ |
| 111 | PHYSICS_COMMIT="$physics_pin" make OUT_DIR="$out" "$@" "$name" > "$log" 2>&1 |
| 112 | local rc=$? |
| 113 | local src |
| 114 | read -r n f src < <(counts "$log") |
| 115 | RC[$name]=$rc |
| 116 | RUN[$name]=$n |
| 117 | FAILED[$name]=$f |
| 118 | local status=FAIL |
| 119 | [ "$rc" -eq 0 ] && [ "$f" -eq 0 ] && status=PASS |
| 120 | [ "$status" = PASS ] || REASONS+=("$name $status (rc=$rc, $f of $n failed)") |
| 121 | SUITES_JSON+="${SUITES_JSON:+,} |
| 122 | {\"target\": \"$name\", \"rc\": $rc, \"tests_run\": $n, \"tests_failed\": $f, \"count_source\": \"$src\", \"status\": \"$status\", \"log_sha256\": \"$(sha256sum "$log" | awk '{print $1}')\"}" |
| 123 | echo "suite $name: $status (rc=$rc run=$n failed=$f)" >&2 |
| 124 | } |
| 125 | |
| 126 | PF=(PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 AIENOS_R7_DIR="$Q/aienos") |
| 127 | RT=(PHYSICS_DIR="$PHYSICS_DIR" AIENOS_R7_DIR="$Q/aienos" VISOR_AUTH_CAP_LIB="$LIB") |
| 128 | |
| 129 | suite test-effect-cap64 "$Q/pf" "${PF[@]}" |
| 130 | suite test-visor-core "$Q/pf" "${PF[@]}" |
| 131 | suite test-visor-world "$Q/pf" "${RT[@]}" |
| 132 | suite test-visor-authority "$Q/pf" "${RT[@]}" |
| 133 | REGRESSION=(test test-r3 test-r7 test-r8 test-r9 test-r10 test-r11 test-r12 test-action-graph |
| 134 | test-state-projection test-capability-query test-typed-results) |
| 135 | for t in "${REGRESSION[@]}"; do suite "$t" "$Q/reg" "${RT[@]}"; done |
| 136 | |
| 137 | # ---- truncation grep -------------------------------------------------------- |
| 138 | trunc_hits=$(grep -rnE '\(uint32_t\)[^;]*capability_generation|capability_generation[^;]*[^0-9]%u|uint32_t +(cap_gen|capability_generation)\b' \ |
| 139 | src tests --include='*.c' --include='*.h' | grep -v 'src/omega_accelerator' || true) |
| 140 | # The console wiring tools/omega.c held is OM-2 now; its truncation forms are grepped |
| 141 | # by effect_cap64_om_trunc.sh (with bite controls; exit 2 means the control failed). |
| 142 | om_trunc=$(sh tools/effect_cap64_om_trunc.sh "$HERE"); om_rc=$? |
| 143 | [ "$om_rc" -le 1 ] || om_trunc="effect_cap64_om_trunc.sh: bite control or file list failed (exit $om_rc)" |
| 144 | trunc_hits=$(printf '%s\n%s\n' "$trunc_hits" "$om_trunc" | grep . || true) |
| 145 | trunc_n=$(printf '%s' "$trunc_hits" | grep -c . || true) |
| 146 | [ "$trunc_n" -eq 0 ] || REASONS+=("effect generation truncation grep: $trunc_n hit(s)") |
| 147 | |
| 148 | # ---- gates ------------------------------------------------------------------ |
| 149 | eff_log=$LOGS/test-effect-cap64.log |
| 150 | gate_from_effect() { # -> "STATUS passed total" |
| 151 | local line |
| 152 | line=$(grep -E "^GATE $1 (PASS|FAIL) [0-9]+/[0-9]+$" "$eff_log" | tail -n 1) |
| 153 | [ -n "$line" ] || { echo "NOT_RUN 0 0"; return; } |
| 154 | local st=${line#GATE $1 } |
| 155 | local status=${st%% *} frac=${st#* } |
| 156 | echo "$status ${frac%/*} ${frac#*/}" |
| 157 | } |
| 158 | GATES_JSON="" |
| 159 | all_pass=1 |
| 160 | add_gate() { # add_gate <name> <status> <run> <failed> <sources> |
| 161 | GATES_JSON+="${GATES_JSON:+,} |
| 162 | \"$1\": {\"status\": \"$2\", \"tests_run\": $3, \"tests_failed\": $4, \"sources\": \"$5\"}" |
| 163 | [ "$2" = PASS ] || { all_pass=0; REASONS+=("$1 $2"); } |
| 164 | } |
| 165 | for g in ROUNDTRIP IDENTITY STALE_REJECT; do |
| 166 | read -r st p t < <(gate_from_effect "OMEGA_EFFECT_CAP64_${g}_PASS") |
| 167 | extra="" |
| 168 | if [ "$g" = ROUNDTRIP ]; then |
| 169 | t=$((t + 1)); [ "$trunc_n" -eq 0 ] && p=$((p + 1)) || st=FAIL |
| 170 | extra=" + truncation grep" |
| 171 | fi |
| 172 | [ "${RC[test-effect-cap64]}" -eq 0 ] || st=FAIL |
| 173 | add_gate "OMEGA_EFFECT_CAP64_${g}_PASS" "$st" "$t" "$((t - p))" "make test-effect-cap64$extra" |
| 174 | done |
| 175 | read -r st p t < <(gate_from_effect OMEGA_EFFECT_CAP64_AUTHORITY_PASS) |
| 176 | va_run=${RUN[test-visor-authority]}; va_f=${FAILED[test-visor-authority]} |
| 177 | link_ok=0; grep -q '^OMEGA_VISOR_AUTHORITY_ISOLATION_PASS$' "$LOGS/test-visor-core.log" && link_ok=1 |
| 178 | a_run=$((t + va_run + 1)); a_fail=$((t - p + va_f + 1 - link_ok)) |
| 179 | a_st=PASS |
| 180 | { [ "$st" = PASS ] && [ "${RC[test-visor-authority]}" -eq 0 ] && [ "$va_f" -eq 0 ] && [ "$va_run" -gt 0 ] && |
| 181 | [ "$link_ok" -eq 1 ]; } || a_st=FAIL |
| 182 | add_gate OMEGA_EFFECT_CAP64_AUTHORITY_PASS "$a_st" "$a_run" "$a_fail" \ |
| 183 | "make test-effect-cap64 (authority, real AIENOS lib) + make test-visor-authority + visor-authority-check (in test-visor-core)" |
| 184 | r_run=0; r_fail=0; r_st=PASS |
| 185 | for t in test-visor-core test-visor-world "${REGRESSION[@]}"; do |
| 186 | r_run=$((r_run + RUN[$t])); r_fail=$((r_fail + FAILED[$t])) |
| 187 | [ "${RC[$t]}" -eq 0 ] && [ "${FAILED[$t]}" -eq 0 ] || { r_st=FAIL; [ "${FAILED[$t]}" -eq 0 ] && r_fail=$((r_fail + 1)); } |
| 188 | done |
| 189 | add_gate OMEGA_EFFECT_CAP64_REGRESSION_PASS "$r_st" "$r_run" "$r_fail" \ |
| 190 | "make test-visor-core test-visor-world ${REGRESSION[*]} (tests_run = PASS n/m lines, omegatool TOTAL GATES, or the suite's own receipt checks/failures; exit status always required)" |
| 191 | |
| 192 | # ---- tree stability --------------------------------------------------------- |
| 193 | head1=$(git rev-parse HEAD) |
| 194 | dirty1=$(git status --porcelain) |
| 195 | stable=true |
| 196 | { [ "$head1" = "$head0" ] && [ "$dirty1" = "$dirty0" ]; } || { stable=false; REASONS+=("tree changed during the run"); } |
| 197 | tree_dirty=false; [ -z "$dirty0" ] || tree_dirty=true |
| 198 | verdict=OMEGA_EFFECT_CAP64_PASS |
| 199 | { [ "$all_pass" -eq 1 ] && [ "$stable" = true ] && [ "$tree_dirty" = false ] && [ "$lib_ok" -eq 1 ] && |
| 200 | [ "$physics_head" = "$physics_pin" ]; } || verdict=OMEGA_EFFECT_CAP64_FAIL |
| 201 | |
| 202 | json_str() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | awk 'BEGIN{ORS=""} {if (NR>1) print "\\n"; print}'; } |
| 203 | reasons_json="" |
| 204 | for r in "${REASONS[@]}"; do reasons_json+="${reasons_json:+, }\"$(json_str "$r")\""; done |
| 205 | |
| 206 | body=$(cat <<EOF |
| 207 | { |
| 208 | "schema": "omega-effect-cap64-qualification/1", |
| 209 | "spec": "spec/effect-cap64-migration.md", |
| 210 | "run_id": "$run_id", |
| 211 | "candidate_commit": "$head0", |
| 212 | "candidate_tree": "$tree0", |
| 213 | "tree_dirty": $tree_dirty, |
| 214 | "tree_stable_during_run": $stable, |
| 215 | "host": {"uname_m": "$(uname -m)", "uname_r": "$(uname -r)", "product_name": "$(json_str "$(cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null)")"}, |
| 216 | "hardware_scope": "host-only (CPU); no GPU, no silicon, no energy measurement", |
| 217 | "aienos": {"lock": "$aienos_pin", "source": "git archive $aienos_pin native/capability (tree $aienos_src_tree)", "header_sha256": "$hdr_sha", "lib_sha256": "$lib_sha", "lib_built": $([ "$lib_ok" -eq 1 ] && echo true || echo false)}, |
| 218 | "physics": {"lock": "$physics_pin", "checkout_head": "$physics_head"}, |
| 219 | "gates": {$GATES_JSON |
| 220 | }, |
| 221 | "suites": [$SUITES_JSON |
| 222 | ], |
| 223 | "truncation_grep": {"hits": $trunc_n, "detail": "$(json_str "$trunc_hits")"}, |
| 224 | "not_run": [ |
| 225 | "GPU / silicon targets (test-m12, test-m15, test-m17, test-m18, test-m19, r12 silicon seat, r13/r14 living runs, R15)", |
| 226 | "suites CI runs that read the package energy counter (test-semantic-comm, test-cognitive-routing, test-sem-incremental, test-workflow-fusion, test-plan-reuse): not run here (no energy measurements); CI runs them" |
| 227 | ], |
| 228 | "non_claims": [ |
| 229 | "The accelerator OmegaEffectIntent / OmegaEffectReceipt (src/omega_accelerator.h) still carry a 32-bit capability_generation; they belong to the physics accelerator port model, not AIENOS, and are unchanged.", |
| 230 | "Visor JSON prints the generation as an exact decimal integer; consumers parsing JSON numbers as doubles lose precision above 2^53.", |
| 231 | "No effect is executed; operation_code/resource_class -> AIENOS rights/resource is still a test convention.", |
| 232 | "Old (version 0x01) effect objects are refused, not migrated; none exist in this repository." |
| 233 | ], |
| 234 | "verdict": "$verdict", |
| 235 | "verdict_reasons": [$reasons_json] |
| 236 | } |
| 237 | EOF |
| 238 | ) |
| 239 | mkdir -p "$OUTDIR" |
| 240 | tmp=$(mktemp "$OUTDIR/.tmp-XXXXXX") |
| 241 | printf '%s\n' "$body" > "$tmp" |
| 242 | digest=$(sha256sum "$tmp" | awk '{print $1}') |
| 243 | final=$OUTDIR/$digest.json |
| 244 | if [ -e "$final" ]; then rm -f "$tmp"; else mv "$tmp" "$final"; fi |
| 245 | chmod 0644 "$final" |
| 246 | grep -E '"OMEGA_EFFECT_CAP64_[A-Z_]+_PASS"' "$final" | sed 's/^ *//' |
| 247 | echo "RECEIPT $final" |
| 248 | echo "VERDICT $verdict" |
| 249 | [ "$verdict" = OMEGA_EFFECT_CAP64_PASS ] |