#!/usr/bin/env bash # tools/kernel-ab/smoke.sh - STRA-248 acceptance in one command: build, gen, verify, negative tests, poolcheck. # Last line `SMOKE OK` on success; any failure stops with a non-zero exit before it. # # E2E_ROOT run root; build in $E2E_ROOT/build/kernel-ab, runs in $E2E_ROOT/runs/kernel-ab/ # (default $HOME/work/leleka-e2e; on rnr5090 the root file system is full: E2E_ROOT=/data/leleka-e2e) # KAB_RUN_ID run id (default smoke-) KAB_JOBS make -j (default 4) PYTHON (default python3) # GGML_DIR optional llama.cpp checkout at 3cf03257f (default: one shallow fetch of the pin into the build directory) # CPU only, no GPU, no install. Everything runs under nice -n 19 (a build is timing load, SC14). set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" repo="$(cd "${here}/../.." && pwd)" root="${E2E_ROOT:-${HOME}/work/leleka-e2e}" build="${KAB_BUILD:-${root}/build/kernel-ab}" runid="${KAB_RUN_ID:-smoke-$(date -u +%Y%m%dT%H%M%SZ)}" d="${root}/runs/kernel-ab/${runid}" neg="${root}/runs/kernel-ab/${runid}-neg" py="${PYTHON:-python3}" jobs="${KAB_JOBS:-4}" export PYTHONDONTWRITEBYTECODE=1 nice_="nice -n 19" case "${build}/" in "${repo}/"*) echo "smoke: build directory ${build} is inside the repository" >&2; exit 1;; esac case "${d}/" in "${repo}/"*) echo "smoke: run directory ${d} is inside the repository" >&2; exit 1;; esac [ ! -e "${d}" ] || { echo "smoke: ${d} exists; set KAB_RUN_ID" >&2; exit 1; } step() { printf '\n==== %s ====\n' "$*"; } extra=(); [ -z "${GGML_DIR:-}" ] || extra=("GGML_DIR=${GGML_DIR}") step "AC1 build: make BUILD=${build}" ${nice_} make -j"${jobs}" -C "${here}/cpp" BUILD="${build}" ${extra[@]+"${extra[@]}"} all check-pin echo "--- flags (the pin's, as recorded) ---" grep -E '^(compiler_banner|target_triple|CMAKE_BUILD_TYPE|CMAKE_CXX_FLAGS_RELEASE|strata_cxx_flags|ggml_c_flags|ggml_cxx_flags|ggml_cpu_arch_flags|GGML_NATIVE|STRATA_PORTABLE)' "${build}/build-info.txt" step "AC2 gen: kab gen --run-dir ${d} --seed 1 --cases all" ${nice_} "${build}/kab" gen --run-dir "${d}" --seed 1 --cases all idout="$(${py} "${here}/verify_manifest.py" "${d}" --ids)" echo "${idout}" ids="$(echo "${idout}" | head -1)" [ "${ids}" = "{18, 20, 21, 22, 23, 42}" ] || { echo "smoke: unexpected id set ${ids}" >&2; exit 1; } step "AC3 verify" ${py} "${here}/verify_manifest.py" "${d}" newest="$(ls -t "${d}" | head -1)" echo "ls -t D | head -1: ${newest}" [ "${newest}" = "manifest.json" ] || { echo "smoke: manifest.json is not the newest file" >&2; exit 1; } step "AC5 both trees for every case; avx2_ok / avx512_ok recorded" cases="$(ls "${d}" | grep -c '\.in$')" n512="$(ls "${d}" | grep -c 'cpp-avx512.out')" n2="$(ls "${d}" | grep -c 'cpp-avx2.out')" echo "cases=${cases} cpp-avx512.out=${n512} cpp-avx2.out=${n2}" [ "${cases}" = "${n512}" ] && [ "${cases}" = "${n2}" ] && [ "${cases}" -gt 0 ] || { echo "smoke: output counts differ" >&2; exit 1; } for k in avx512_ok avx2_ok; do v="$(${py} -c "import json,sys;print(json.load(open(sys.argv[1]+'/manifest.json'))['provenance'][sys.argv[2]])" "${d}" "${k}")" echo "provenance.${k} = ${v}" case "${v}" in True|False) ;; *) echo "smoke: ${k} is not a boolean" >&2; exit 1;; esac done step "AC4 negative tests on a small separate run (${neg})" ${nice_} "${build}/kab" gen --run-dir "${neg}" --seed 7 --cases 18:20:1,42:42:2 >/dev/null ${py} "${here}/verify_manifest.py" "${neg}" victim="${neg}/case-18-20-r1.in" printf '\xa5' | dd of="${victim}" bs=1 seek=1000 count=1 conv=notrunc 2>/dev/null set +e; out="$(${py} "${here}/verify_manifest.py" "${neg}" 2>&1)"; rc=$?; set -e echo "flipped one byte -> exit ${rc}: ${out}" [ "${rc}" = 1 ] && printf '%s' "${out}" | grep -q 'case-18-20-r1.in' || { echo "smoke: flipped byte not refused / not named" >&2; exit 1; } rm -f "${neg}/manifest.json" set +e; out="$(${py} "${here}/verify_manifest.py" "${neg}" 2>&1)"; rc=$?; set -e echo "manifest.json removed -> exit ${rc}: ${out}" [ "${rc}" = 2 ] && printf '%s' "${out}" | grep -q 'incomplete directory' || { echo "smoke: missing manifest not refused with exit 2" >&2; exit 1; } step "AC6 stage composition evidence" grep -n "native_expert.hpp" "${here}/README.md" | head -5 grep -q "native_expert.hpp" "${here}/README.md" echo "--- stage composition vs the real ExpertPool (bitwise, 1 and 4 workers) ---" ${nice_} "${build}/kab" poolcheck --run-dir "${d}" --workers 1 | tail -2 ${nice_} "${build}/kab" poolcheck --run-dir "${d}" --workers 4 | tail -2 step "no artifact inside the tree" if git -C "${repo}" rev-parse --git-dir >/dev/null 2>&1; then git -C "${repo}" status --porcelain --untracked-files=all | grep -v ' tools/kernel-ab/' || true fi echo "SMOKE OK"