aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / ck_shards_verify.sh
| 1 | #!/usr/bin/env bash |
| 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 | # ck_shards_verify.sh: the CK CI final check. Reads the stdout of every sharded |
| 18 | # `ck_gates.sh --only ...` run and proves the shards together are one complete |
| 19 | # gate run: |
| 20 | # - exactly EXPECT shard outputs were found; |
| 21 | # - every gate in the ck_gates.sh table has exactly one real verdict |
| 22 | # (PASS, FAIL or NOT_RUN) across all shards, and NOT_SELECTED in every |
| 23 | # other shard (so nothing was dropped or run twice); |
| 24 | # - no verdict line names a gate that is not in the table; |
| 25 | # - every gate with a C implementation (source not "missing", except FPU and |
| 26 | # INFER, which need the Rust bare-metal target and the model file) is PASS. |
| 27 | # Usage: bash scripts/ck_shards_verify.sh EXPECT DIR (DIR holds *.txt, searched recursively) |
| 28 | # bash scripts/ck_shards_verify.sh --self-test |
| 29 | # Exit: 0 all good, 1 a check failed, 2 usage. |
| 30 | set -uo pipefail |
| 31 | here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 32 | table="$(sed -n "/^CK_GATE_TABLE='/,/^'/p" "${here}/ck_gates.sh" | awk -F'|' 'NF==3 {print $1 "|" $2}')" |
| 33 | [[ -n "${table}" ]] || { echo "could not read the gate table"; exit 2; } |
| 34 | |
| 35 | verify() { # EXPECT DIR |
| 36 | local expect="$1" dir="$2" files=() f g src n real notsel bad=0 line |
| 37 | mapfile -t files < <(find "${dir}" -type f -name '*.txt' | sort) |
| 38 | if [[ ${#files[@]} != "${expect}" ]]; then |
| 39 | echo "FAIL expected ${expect} shard outputs, found ${#files[@]}"; bad=1 |
| 40 | fi |
| 41 | while IFS='|' read -r g src; do |
| 42 | [[ -n "${g}" ]] || continue |
| 43 | real=0; notsel=0 |
| 44 | for f in "${files[@]}"; do |
| 45 | line="$(grep -E "^AIENOS_CK_${g}: (PASS|FAIL|NOT_RUN|NOT_SELECTED)( |\$)" "${f}" | head -5)" |
| 46 | [[ -n "${line}" ]] || { echo "FAIL ${g}: no verdict line at all in ${f}"; bad=1; continue; } |
| 47 | n=$(grep -c . <<<"${line}") |
| 48 | [[ ${n} == 1 ]] || { echo "FAIL ${g}: ${n} verdict lines in ${f}"; bad=1; continue; } |
| 49 | if [[ "${line}" == *": NOT_SELECTED"* ]]; then notsel=$((notsel + 1)) |
| 50 | else |
| 51 | real=$((real + 1)) |
| 52 | case "${g}:${src}" in |
| 53 | FPU:*|INFER:*|*:missing) [[ "${line}" == *": FAIL"* ]] && { echo "FAIL ${g}: ${line}"; bad=1; } ;; |
| 54 | *) [[ "${line}" == "AIENOS_CK_${g}: PASS"* ]] || { echo "FAIL ${g}: ${line}"; bad=1; } ;; |
| 55 | esac |
| 56 | fi |
| 57 | done |
| 58 | if [[ ${real} != 1 ]]; then echo "FAIL ${g}: reported ${real} times across shards (want exactly 1)"; bad=1 |
| 59 | else echo "ok ${g}: reported once, NOT_SELECTED in ${notsel} other shard(s)"; fi |
| 60 | done <<<"${table}" |
| 61 | # No stray gate names. |
| 62 | for f in "${files[@]}"; do |
| 63 | while read -r g; do |
| 64 | grep -q "^${g}|" <<<"${table}" || { echo "FAIL ${f}: verdict line for unknown gate ${g}"; bad=1; } |
| 65 | done < <(sed -nE 's/^AIENOS_CK_([A-Z0-9_]+): (PASS|FAIL|NOT_RUN|NOT_SELECTED)( .*)?$/\1/p' "${f}" | grep -vE '^(GATES|B7B_PROBE|SERVICE_DISK_BUILD)' ) |
| 66 | done |
| 67 | if [[ ${bad} == 0 ]]; then echo "AIENOS_CK_SHARDS: PASS (every gate reported exactly once across ${#files[@]} shards)"; return 0; fi |
| 68 | echo "AIENOS_CK_SHARDS: FAIL"; return 1 |
| 69 | } |
| 70 | |
| 71 | self_test() { |
| 72 | local t rc fails=0 g src |
| 73 | t="$(mktemp -d)"; mkdir -p "${t}/good" |
| 74 | # Two shards: A runs M1, B runs everything else, all PASS (FPU and INFER NOT_RUN). |
| 75 | : >"${t}/good/a.txt"; : >"${t}/good/b.txt" |
| 76 | while IFS='|' read -r g src; do |
| 77 | [[ -n "${g}" ]] || continue |
| 78 | v=PASS; [[ ${g} == FPU || ${g} == INFER ]] && v=NOT_RUN |
| 79 | if [[ ${g} == M1 ]]; then echo "AIENOS_CK_${g}: ${v}" >>"${t}/good/a.txt"; echo "AIENOS_CK_${g}: NOT_SELECTED (x)" >>"${t}/good/b.txt" |
| 80 | else echo "AIENOS_CK_${g}: NOT_SELECTED (x)" >>"${t}/good/a.txt"; echo "AIENOS_CK_${g}: ${v}" >>"${t}/good/b.txt"; fi |
| 81 | done <<<"${table}" |
| 82 | chk() { # NAME WANT_RC DIR EXPECT |
| 83 | verify "$4" "$3" >/dev/null 2>&1; rc=$? |
| 84 | [[ ${rc} == "$2" ]] && echo "PASS $1" || { echo "FAIL $1 (rc ${rc})"; fails=1; } |
| 85 | } |
| 86 | chk "complete shards pass" 0 "${t}/good" 2 |
| 87 | chk "wrong shard count fails" 1 "${t}/good" 3 |
| 88 | cp -r "${t}/good" "${t}/dup"; sed -i 's/^AIENOS_CK_SMP: NOT_SELECTED.*/AIENOS_CK_SMP: PASS/' "${t}/dup/a.txt" |
| 89 | chk "a gate reported twice fails" 1 "${t}/dup" 2 |
| 90 | cp -r "${t}/good" "${t}/drop"; sed -i 's/^AIENOS_CK_SMP: PASS/AIENOS_CK_SMP: NOT_SELECTED (x)/' "${t}/drop/b.txt" |
| 91 | chk "a gate reported by no shard fails" 1 "${t}/drop" 2 |
| 92 | cp -r "${t}/good" "${t}/fail"; sed -i 's/^AIENOS_CK_SMP: PASS/AIENOS_CK_SMP: FAIL (x)/' "${t}/fail/b.txt" |
| 93 | chk "a failing gate fails" 1 "${t}/fail" 2 |
| 94 | cp -r "${t}/good" "${t}/nr"; sed -i 's/^AIENOS_CK_NET: PASS.*/AIENOS_CK_NET: NOT_RUN (tool missing)/' "${t}/nr/b.txt" |
| 95 | chk "a required gate that is NOT_RUN fails" 1 "${t}/nr" 2 |
| 96 | cp -r "${t}/good" "${t}/gone"; sed -i '/^AIENOS_CK_SMP:/d' "${t}/gone/a.txt" |
| 97 | chk "a missing verdict line fails" 1 "${t}/gone" 2 |
| 98 | rm -rf "${t}" |
| 99 | [[ ${fails} == 0 ]] && { echo "AIENOS_CK_SHARDS_VERIFY_SELF_TEST: PASS"; exit 0; } |
| 100 | echo "AIENOS_CK_SHARDS_VERIFY_SELF_TEST: FAIL"; exit 1 |
| 101 | } |
| 102 | |
| 103 | case "${1:-}" in |
| 104 | --self-test) self_test ;; |
| 105 | '') echo "usage: ck_shards_verify.sh EXPECT DIR | --self-test" >&2; exit 2 ;; |
| 106 | *) [[ $# == 2 && "$1" =~ ^[0-9]+$ && -d "$2" ]] || { echo "usage: ck_shards_verify.sh EXPECT DIR | --self-test" >&2; exit 2; } |
| 107 | verify "$1" "$2" ;; |
| 108 | esac |