interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / run.sh

77 lines · 3314 bytes Raw Blame History
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).
14set -u
15here=$(cd "$(dirname "$0")" && pwd)
16tasks="$here/tasks"
17omc=""
18mode=seed
19work="${WORK:-$here/build}"
20while [ $# -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
29done
30die() { echo "run.sh: $*" >&2; exit 2; }
31ref=$(awk '$1=="commit"{print $2}' "$here/omega.ref")
32pin=$(awk '$1=="omc_sha256"{print $2}' "$here/omega.ref")
33[ -n "$ref" ] && [ -n "$pin" ] || die "omega.ref needs commit and omc_sha256 lines"
34mkdir -p "$work" || die "cannot create $work"
35
36if [ "$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"
48fi
49[ -f "$omc" ] || die "no omc at $omc"
50got=$(sha256sum "$omc" | awk '{print $1}')
51[ "$got" = "$pin" ] || die "omc sha256 $got does not match the pin $pin"
52echo "run.sh: omc sha256 $got (pin ok, mode $mode)" >&2
53
54n=0; ok=0
55for 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"
74done
75[ "$n" -gt 0 ] || die "no tasks under $tasks"
76echo "TASKS PASS $ok/$n"
77[ "$ok" = "$n" ]