interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / allen_exam_card.sh

40 lines · 2107 bytes Raw Blame History
1#!/usr/bin/env bash
2# allen_exam_card.sh -- build the pi5-allen exam card file (\EFI\AIENOS\ALLEN.EXM, crates/allen-reflex-kernel/src/card.rs)
3# from exam case files. Only the case id and the turns go into the card file; expected answers stay on the host
4# (scripts/allen_pi_results.sh joins them back by id).
5#
6# allen_exam_card.sh <out file> <case file>...
7#
8# A case file is an exam .psv (id|category|action|text|turns) or, for the bounds cases, a .cases file (id|turns).
9# Refuses the held-out file and any path under ~/sealed: this tool is for train/dev rehearsal and bounds tests;
10# a sealed set is staged only by the declared final scoring procedure.
11set -euo pipefail
12out="${1:?out file}"; shift
13[[ $# -ge 1 ]] || { echo "usage: $0 <out file> <case file>..." >&2; exit 2; }
14for f in "$@"; do
15 case "$(readlink -f "$f")" in
16 */sealed/*|*heldout*) echo "REFUSE: ${f} is a held-out or sealed case file (rehearsal uses train/dev only)" >&2; exit 2 ;;
17 esac
18 [[ -r "$f" ]] || { echo "no case file ${f}" >&2; exit 2; }
19done
20tmp="$(mktemp)"
21trap 'rm -f "${tmp}"' EXIT
22printf 'AIENALX1 QUALIF-ALLEN-EXAM\n' > "${tmp}"
23for f in "$@"; do
24 if [[ "$f" == *.psv ]]; then
25 # id|category|action|text|turns -> id|turns (turns may itself hold '|': keep everything after the 4th bar)
26 awk '!/^#/ && NF { i = index($0, "|"); id = substr($0, 1, i - 1); r = $0;
27 for (k = 0; k < 4; k++) { j = index(r, "|"); r = substr(r, j + 1) } print id "|" r }' "$f" >> "${tmp}"
28 else
29 grep -v '^#' "$f" | grep -v '^$' >> "${tmp}"
30 fi
31done
32n=$(( $(wc -l < "${tmp}") - 1 ))
33bytes=$(stat -c %s "${tmp}")
34[[ ${bytes} -le 131072 ]] || { echo "card file ${bytes} bytes > 131072" >&2; exit 1; }
35[[ ${n} -ge 1 && ${n} -le 512 ]] || { echo "card file has ${n} cases (1..512)" >&2; exit 1; }
36dups=$(tail -n +2 "${tmp}" | cut -d'|' -f1 | sort | uniq -d | head -3 | tr '\n' ' ')
37[[ -z "${dups}" ]] || { echo "duplicate case ids: ${dups}" >&2; exit 1; }
38mv "${tmp}" "${out}"
39trap - EXIT
40echo "card file ${out}: ${n} cases, ${bytes} bytes, sha256 $(sha256sum "${out}" | cut -d' ' -f1)"