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 / compiler / determinism.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 | # OSC-1 determinism gate (DESIGN section 8): compile every golden program |
| 18 | # twice in separate processes and compare the printed IR digest, machine-code |
| 19 | # digest and function count byte for byte. |
| 20 | # Usage: tests/compiler/determinism.sh [path/to/oscc] |
| 21 | # Without an argument oscc is built single core under /tmp/l22c. |
| 22 | # Prints OSC1_DETERMINISM_PASS or OSC1_DETERMINISM_FAIL. |
| 23 | # OSC-1 slice; not a general Omega compiler; no self-hosting. |
| 24 | set -u |
| 25 | here=$(cd "$(dirname "$0")" && pwd) |
| 26 | root=$(cd "$here/../.." && pwd) |
| 27 | out=/tmp/l22c/det |
| 28 | mkdir -p "$out" || exit 1 |
| 29 | if [ $# -ge 1 ]; then |
| 30 | oscc=$1 |
| 31 | else |
| 32 | oscc=/tmp/l22c/oscc |
| 33 | srcs="" |
| 34 | for f in "$root"/src/compiler/*.c; do |
| 35 | case "$f" in |
| 36 | */oscc_main.c) ;; |
| 37 | *) srcs="$srcs $f" ;; |
| 38 | esac |
| 39 | done |
| 40 | # shellcheck disable=SC2086 |
| 41 | nice cc -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 \ |
| 42 | -I"$root/src" -I"$root/src/compiler" -I"$root/src/compiler/model" \ |
| 43 | -o "$oscc" "$root/src/compiler/oscc_main.c" $srcs "$root/src/omega_om_units.c" || { |
| 44 | echo "OSC1_DETERMINISM_FAIL build" |
| 45 | exit 1 |
| 46 | } |
| 47 | fi |
| 48 | n=0 |
| 49 | bad=0 |
| 50 | for p in "$root"/tests/compiler/progs/*.osc; do |
| 51 | b=$(basename "$p" .osc) |
| 52 | nice "$oscc" "$p" > "$out/$b.1" 2>&1; r1=$? |
| 53 | nice "$oscc" "$p" > "$out/$b.2" 2>&1; r2=$? |
| 54 | n=$((n + 1)) |
| 55 | if [ "$r1" -ne 0 ] || [ "$r2" -ne 0 ]; then |
| 56 | echo "FAIL $b: exit $r1 / $r2" |
| 57 | bad=$((bad + 1)) |
| 58 | elif ! cmp -s "$out/$b.1" "$out/$b.2"; then |
| 59 | echo "FAIL $b: outputs differ" |
| 60 | bad=$((bad + 1)) |
| 61 | elif ! grep -q '^ir_sha256=' "$out/$b.1" || ! grep -q '^code_sha256=' "$out/$b.1"; then |
| 62 | echo "FAIL $b: digests missing" |
| 63 | bad=$((bad + 1)) |
| 64 | fi |
| 65 | done |
| 66 | if [ "$n" -ge 1 ] && [ "$bad" -eq 0 ]; then |
| 67 | echo "programs=$n identical=$n" |
| 68 | echo "OSC1_DETERMINISM_PASS" |
| 69 | exit 0 |
| 70 | fi |
| 71 | echo "programs=$n failed=$bad" |
| 72 | echo "OSC1_DETERMINISM_FAIL" |
| 73 | exit 1 |