interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tests / omegallm / efi-check.sh

82 lines · 3336 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: AGPL-3.0-only
3# Compare a UEFI run's \OLLM\OUT.TXT with a Linux reference made by efi-ref.sh (CONTRACT section 9).
4# Usage: sh tests/omegallm/efi-check.sh OUT.TXT REF JOBS BYTES
5# Order required:
6# 1. first line is exactly `OLLM efi BYTES` (BYTES is the JOB.TXT size)
7# 2. second line is the identity line `ID cpu=... fw=... fwrev=XXXXXXXX smbios=.../.../...`
8# (8 lowercase hex digits; its text depends on the machine, so only its shape is checked)
9# 3. each reference job, in order, then exactly one `J <ms>` line; a `> ` line holding only
10# spaces and tabs (a JOB.TXT line with no tokens: eio.om main echoes it and runs nothing) has
11# no J line and is not counted in JOBS
12# 4. last line is `OLLM DONE JOBS <ms>`
13# A reference job is the lines from one `> ` line up to the next. Those lines are compared with
14# REF as they stand. A line shaped like `J n` or `OLLM DONE a b` inside a job is part of that
15# comparison: it is not removed. Prints EQUAL (exit 0) or the first problems (exit 1).
16set -u
17[ $# -eq 4 ] || { echo "usage: efi-check.sh OUT.TXT REF JOBS BYTES" >&2; exit 2; }
18OUT=$1 REF=$2 JOBS=$3 BYTES=$4
19case $JOBS in *[!0-9]*|'') echo "JOBS must be a decimal number" >&2; exit 2 ;; esac
20case $BYTES in *[!0-9]*|'') echo "BYTES must be a decimal number" >&2; exit 2 ;; esac
21body=$(mktemp)
22trap 'rm -f "$body"' EXIT HUP INT TERM
23# awk exits 0 when the walk finished (body is the job lines only), 1 when it did not.
24awk -v jobs="$JOBS" -v bytes="$BYTES" -v body="$body" '
25function note(msg) { print msg; struct = 1 }
26NR == FNR { ref[++rn] = $0; next }
27{ out[++on] = $0 }
28END {
29 if (on < 1) { note("empty OUT.TXT"); exit 1 }
30 banner = "OLLM efi " bytes
31 if (out[1] != banner) note("banner is not " banner)
32 if (on < 2 || out[2] !~ /^ID cpu=.* fw=.* fwrev=([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]|-) smbios=[^\/]*\/[^\/]*\/.*$/) note("second line is not the ID identity line")
33 if (out[on] !~ ("^OLLM DONE " jobs " [0-9]+$")) note("last line is not OLLM DONE " jobs " ms")
34 ri = 1
35 oi = 3
36 nj = 0
37 while (ri <= rn) {
38 if (ref[ri] !~ /^> /) { note("reference line " ri " does not start a job"); exit 1 }
39 blank = (ref[ri] ~ /^> [ \t]*$/)
40 if (!blank) nj++
41 while (ri <= rn) {
42 if (oi >= on) { note("OUT ended during job " nj); exit 1 }
43 if (out[oi] != ref[ri]) {
44 note("job " nj " line mismatch")
45 print " out: " out[oi]
46 print " ref: " ref[ri]
47 exit 1
48 }
49 print out[oi] >> body
50 oi++
51 ri++
52 if (ri <= rn && ref[ri] ~ /^> /) break
53 }
54 if (blank) continue
55 if (oi >= on) { note("missing J line after job " nj); exit 1 }
56 if (out[oi] !~ /^J [0-9]+$/) {
57 note("expected one J line after job " nj)
58 print " out: " out[oi]
59 exit 1
60 }
61 oi++
62 if (oi < on && out[oi] ~ /^J [0-9]+$/) {
63 note("extra J line after job " nj)
64 exit 1
65 }
66 }
67 close(body)
68 if (nj + 0 != jobs + 0) note("jobs " nj ", want " jobs)
69 if (oi != on) note("extra line before DONE")
70 exit (struct ? 2 : 0)
71}
72' "$REF" "$OUT"
73arc=$?
74bad=0
75if [ "$arc" -eq 0 ] || [ "$arc" -eq 2 ]; then
76 if cmp "$body" "$REF"; then echo "body EQUAL"; else bad=1; fi
77else
78 bad=1
79fi
80[ "$arc" -eq 0 ] && [ "$bad" -eq 0 ] && echo EQUAL && exit 0
81echo DIFFERENT
82exit 1