#!/usr/bin/env bash # SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James # test_nightly_dict_hash.sh -- the tests of `scripts/nightly.sh dict-hash` (#172): the three # architectures' boots agree on one dict_hash only when all three report one, and it is the same. # No QEMU: each case is a scratch NIGHTLY_OUT with accept-.txt files and serial logs, as the # accept stages leave them. # # 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 : what accept leaves local a=$1 h=$2 log="$T/logs/$1.log" mkdir -p "$T/out" "$T/logs" case $h in nofile) rm -f "$T/out/accept-$a.txt"; return ;; nolog) printf 'RESULT: PASS\n' > "$T/out/accept-$a.txt"; return ;; esac printf 'LOG: %s\nRESULT: PASS\n' "$log" > "$T/out/accept-$a.txt" if [ "$h" = none ]; then printf 'POST: PASSED\n' > "$log" else printf 'PARITY:V4_SYSTEM word_count=318 dict_hash=%s\nPOST: PASSED\n' "$h" > "$log"; fi } expect() { # expect "what" local want=$1 what=$2 out rc out=$(NIGHTLY_OUT="$T/out" bash "$NIGHTLY" dict-hash 2>&1); rc=$? if { [ "$want" = pass ] && [ $rc -eq 0 ]; } || { [ "$want" = refuse ] && [ $rc -eq 1 ] && grep -q "do not agree" <<<"$out"; }; then echo "PASS: $what" else echo "FAIL: $what (exit $rc)"; printf ' %s\n' "$out" | head -4; ok=0 fi } H=0x8c92508f748f99cf boot amd64 $H; boot aarch64 $H; boot riscv64 $H expect pass "three boots, one dict_hash: pass" boot riscv64 0x0000000000000001 expect refuse "two hashes differ: refused" boot riscv64 none expect refuse "one log has no PARITY:V4_SYSTEM line (two agree): refused" boot riscv64 nolog expect refuse "one accept-.txt names no LOG: (two agree): refused" boot riscv64 nofile expect refuse "one architecture was not booted (two agree): refused" boot riscv64 $H; rm -f "$T/logs/riscv64.log" expect refuse "one serial log is missing (two agree): refused" rm -f "$T/out/accept-"*.txt expect refuse "no architecture booted at all: refused, and says so" echo "RESULT: $([ $ok = 1 ] && echo PASS || echo FAIL)" [ $ok = 1 ]