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 / tests / checker2 / differential.sh
| 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 | # Black-box differential: the producer's checker (oscc, run as a program; its source is not read by |
| 18 | # checker2) against checker2, over every OSC unit in the repo plus the generated valid units. |
| 19 | # oscc accepts -> osc_emit_ir must write the same bytes (same ir_sha256) and checker2 must ACCEPT |
| 20 | # oscc rejects -> the unit never becomes bytes (front-end refusal); osc_emit_ir must agree |
| 21 | # Disagreement fails. Gate (omega#446): at least 100 units accepted by both checkers. |
| 22 | # The accepted IR files are left in <work>/ir for test_c2_ir. |
| 23 | # Usage: sh tests/checker2/differential.sh <oscc> <osc_emit_ir> <checker2> <work-dir> |
| 24 | set -u |
| 25 | OSCC=$1; EMIT=$2; C2=$3; WORK=$4 |
| 26 | rm -rf "$WORK" |
| 27 | mkdir -p "$WORK/ir" "$WORK/gen" |
| 28 | sh tests/checker2/gen_valid.sh "$WORK/gen" 48 || { echo "differential: generator failed"; exit 1; } |
| 29 | |
| 30 | both=0; fe_reject=0; neg=0; bad=0 |
| 31 | check_unit() { # <file.osc> <expect: any|reject> |
| 32 | src=$1; expect=$2 |
| 33 | name=$(echo "$src" | sed 's|^\./||; s|/|_|g; s|\.osc$||') |
| 34 | out=$("$OSCC" "$src" 2>/dev/null); orc=$? |
| 35 | erc=0; eout=$("$EMIT" "$src" "$WORK/ir/$name.ir" 2>/dev/null) || erc=$? |
| 36 | if [ "$orc" -ne 0 ]; then |
| 37 | fe_reject=$((fe_reject + 1)) |
| 38 | [ "$expect" = reject ] && neg=$((neg + 1)) |
| 39 | if [ "$erc" -eq 0 ]; then echo "DISAGREE $src: oscc rejects, producer library accepts"; bad=$((bad + 1)); fi |
| 40 | rm -f "$WORK/ir/$name.ir" |
| 41 | return |
| 42 | fi |
| 43 | if [ "$expect" = reject ]; then echo "DISAGREE $src: known-bad unit accepted by oscc"; bad=$((bad + 1)); return; fi |
| 44 | osha=$(echo "$out" | sed -n 's/^ir_sha256=//p') |
| 45 | esha=$(echo "$eout" | sed -n 's/.*ir_sha256=//p') |
| 46 | if [ "$erc" -ne 0 ] || [ -z "$osha" ] || [ "$osha" != "$esha" ]; then |
| 47 | echo "DISAGREE $src: emitted bytes are not oscc's bytes ($osha vs $esha)"; bad=$((bad + 1)); return |
| 48 | fi |
| 49 | c=$("$C2" check "$WORK/ir/$name.ir") |
| 50 | case "$c" in |
| 51 | "checker2=ACCEPT ir_sha256=$osha") both=$((both + 1)) ;; |
| 52 | *) echo "DISAGREE $src: oscc accepts, $c"; bad=$((bad + 1)) ;; |
| 53 | esac |
| 54 | } |
| 55 | |
| 56 | for f in tests/compiler/progs/*.osc tests/compiler/slices/*.osc src/osh/*.osc tests/physics0/osc/*.osc "$WORK"/gen/*.osc; do |
| 57 | [ -f "$f" ] && check_unit "$f" any |
| 58 | done |
| 59 | for f in tests/compiler/neg/*.osc; do |
| 60 | [ -f "$f" ] && check_unit "$f" reject |
| 61 | done |
| 62 | |
| 63 | # negative control: the comparison must be able to fail. A truncated copy of an accepted unit has |
| 64 | # to be refused by checker2; otherwise this script could never report a disagreement. |
| 65 | first=$(ls "$WORK"/ir/*.ir | head -n 1) |
| 66 | size=$(wc -c < "$first") |
| 67 | head -c $((size - 1)) "$first" > "$WORK/control.ir" |
| 68 | case $("$C2" check "$WORK/control.ir") in |
| 69 | checker2=REJECT*) ;; |
| 70 | *) echo "differential: negative control failed (truncated unit accepted)"; bad=$((bad + 1)) ;; |
| 71 | esac |
| 72 | |
| 73 | echo "differential: accepted by both=$both front-end refusals=$fe_reject (known-bad neg units=$neg) disagreements=$bad" |
| 74 | [ "$bad" -eq 0 ] || exit 1 |
| 75 | [ "$both" -ge 100 ] || { echo "differential: gate needs >= 100 units accepted by both"; exit 1; } |
| 76 | [ "$neg" -ge 100 ] || { echo "differential: expected the known-bad neg units to be refused"; exit 1; } |
| 77 | exit 0 |