#!/usr/bin/env bash # SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James # test_nightly_post_count.sh -- the tests of `scripts/nightly.sh post-count` (#173): every boot of the # acceptance reports POST with at least the floor's tests (v4/system/POST_FLOOR), all passed. No # QEMU: each case is a scratch NIGHTLY_OUT with accept-.txt files and serial logs, and a # scratch POST_FLOOR. # # Prints PASS:/FAIL: per check and RESULT:; exits 0 only if every check passes. set -uo pipefail NIGHTLY="$(cd "$(dirname "$0")" && pwd)/nightly.sh" T=$(mktemp -d) trap 'rm -rf "$T"' EXIT ok=1 boot() { # boot | boot none local b=$1 log="$T/logs/$1.log" mkdir -p "$T/out" "$T/logs" printf 'LOG: %s\nRESULT: PASS\n' "$log" > "$T/out/accept-$b.txt" if [ "$2" = none ]; then printf 'POST: PASSED\n' > "$log" else printf 'PARITY:V4_POST tests=%s pass=%s fail=%s\nPOST: PASSED\n' "$2" "$3" "$4" > "$log"; fi } all() { for b in amd64 aarch64 riscv64 stick-high; do boot "$b" "$@"; done; } expect() { # expect "what" local want=$1 what=$2 out rc out=$(NIGHTLY_OUT="$T/out" POST_FLOOR_FILE="$T/floor" bash "$NIGHTLY" post-count 2>&1); rc=$? if { [ "$want" = pass ] && [ $rc -eq 0 ]; } || { [ "$want" = refuse ] && [ $rc -eq 1 ] && grep -q "POST" <<<"$out"; }; then echo "PASS: $what" else echo "FAIL: $what (exit $rc)"; printf ' %s\n' "$out" | head -4; ok=0 fi } echo 538 > "$T/floor" all 538 538 0; expect pass "four boots, 538 of 538, floor 538: pass" all 600 600 0; expect pass "POST grew past the floor: pass" boot riscv64 537 537 0; expect refuse "one boot ran fewer tests than the floor (537 < 538): refused" all 538 538 0; boot aarch64 538 537 1; expect refuse "one boot with a failure: refused" all 538 538 0; boot stick-high none; expect refuse "one boot with no PARITY:V4_POST line: refused" all 538 538 0; rm -f "$T/out/accept-amd64.txt"; expect refuse "one boot not run: refused" all 538 538 0; rm -f "$T/floor"; expect refuse "no floor in the tree: refused, not skipped" echo "RESULT: $([ $ok = 1 ] && echo PASS || echo FAIL)" [ $ok = 1 ]