omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / run.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # run.sh: compile every tasks/<name>/<name>.om with the pinned omc, run it, and compare its stdout |
| 4 | # byte for byte with tasks/<name>/expected.txt (written by an independent oracle, never by omc). |
| 5 | # |
| 6 | # sh run.sh birth omc from the 408-byte seed at the omega-mv commit in omega.ref |
| 7 | # sh run.sh --prebuilt use omega-mv's committed seed/out/omc at that commit instead |
| 8 | # sh run.sh --omc PATH use an omc you already have (its sha256 must still match omega.ref) |
| 9 | # sh run.sh --tasks DIR check another task tree (the CI negative control uses this) |
| 10 | # |
| 11 | # stdout: one "PASS <task>" or "FAIL <task> <reason>" line per task, then "TASKS PASS <n>/<total>". |
| 12 | # stderr: diagnostics. Exit 0 when every task passes, 1 when any fails, 2 when setup fails. |
| 13 | # Linux AArch64 only: omc writes static AArch64 Linux ELF files (x86_64 hosts need qemu-user). |
| 14 | set -u |
| 15 | here=$(cd "$(dirname "$0")" && pwd) |
| 16 | tasks="$here/tasks" |
| 17 | omc="" |
| 18 | mode=seed |
| 19 | work="${WORK:-$here/build}" |
| 20 | while [ $# -gt 0 ]; do |
| 21 | case "$1" in |
| 22 | --prebuilt) mode=prebuilt ;; |
| 23 | --omc) omc="$2"; mode=given; shift ;; |
| 24 | --tasks) tasks="$2"; shift ;; |
| 25 | --work) work="$2"; shift ;; |
| 26 | *) echo "run.sh: unknown argument $1" >&2; exit 2 ;; |
| 27 | esac |
| 28 | shift |
| 29 | done |
| 30 | die() { echo "run.sh: $*" >&2; exit 2; } |
| 31 | ref=$(awk '$1=="commit"{print $2}' "$here/omega.ref") |
| 32 | pin=$(awk '$1=="omc_sha256"{print $2}' "$here/omega.ref") |
| 33 | [ -n "$ref" ] && [ -n "$pin" ] || die "omega.ref needs commit and omc_sha256 lines" |
| 34 | mkdir -p "$work" || die "cannot create $work" |
| 35 | |
| 36 | if [ "$mode" != given ]; then |
| 37 | src="$work/omega-mv" |
| 38 | if [ ! -d "$src/.git" ]; then |
| 39 | git clone -q --no-checkout https://github.com/aien-dev/omega-mv "$src" >&2 || die "clone failed" |
| 40 | fi |
| 41 | git -C "$src" checkout -q --detach "$ref" >&2 || die "omega-mv commit $ref not found" |
| 42 | if [ "$mode" = seed ]; then |
| 43 | echo "run.sh: birthing omc from seed at omega-mv $ref" >&2 |
| 44 | (cd "$src" && sh seed/omega-from-seed.sh) > "$work/seed.log" 2>&1 \ |
| 45 | || { tail -n 20 "$work/seed.log" >&2; die "seed/omega-from-seed.sh failed"; } |
| 46 | fi |
| 47 | omc="$src/seed/out/omc" |
| 48 | fi |
| 49 | [ -f "$omc" ] || die "no omc at $omc" |
| 50 | got=$(sha256sum "$omc" | awk '{print $1}') |
| 51 | [ "$got" = "$pin" ] || die "omc sha256 $got does not match the pin $pin" |
| 52 | echo "run.sh: omc sha256 $got (pin ok, mode $mode)" >&2 |
| 53 | |
| 54 | n=0; ok=0 |
| 55 | for d in "$tasks"/*/; do |
| 56 | name=$(basename "$d") |
| 57 | [ -f "$d/$name.om" ] || continue |
| 58 | n=$((n + 1)) |
| 59 | out="$work/out/$name"; mkdir -p "$out" |
| 60 | "$omc" < "$d/$name.om" > "$out/prog" 2> "$out/compile.err"; crc=$? |
| 61 | if [ "$crc" != 0 ] || [ -s "$out/compile.err" ]; then |
| 62 | echo "FAIL $name compile rc=$crc $(head -c 200 "$out/compile.err" | tr '\n' ' ')" |
| 63 | continue |
| 64 | fi |
| 65 | chmod +x "$out/prog" |
| 66 | timeout 120 "$out/prog" > "$out/stdout" 2> "$out/stderr"; rrc=$? |
| 67 | if [ "$rrc" != 0 ]; then echo "FAIL $name run rc=$rrc"; continue; fi |
| 68 | if ! cmp -s "$out/stdout" "$d/expected.txt"; then |
| 69 | echo "FAIL $name stdout differs from expected.txt" |
| 70 | diff "$d/expected.txt" "$out/stdout" | head -n 10 >&2 |
| 71 | continue |
| 72 | fi |
| 73 | ok=$((ok + 1)); echo "PASS $name" |
| 74 | done |
| 75 | [ "$n" -gt 0 ] || die "no tasks under $tasks" |
| 76 | echo "TASKS PASS $ok/$n" |
| 77 | [ "$ok" = "$n" ] |