#!/usr/bin/env bash # SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James # test_nightly_run_logs.sh -- the tests of `scripts/nightly.sh run-logs` (#184): what CI uploads is # only what this run wrote -- the files under logs/ and experiments/bare_metal/runs/ newer than the # run's start ($OUT/.started), and the stages' own output in $OUT -- not every log in the tree. # No QEMU: a scratch tree with old and new files. # # 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 check() { if eval "$2"; then echo "PASS: $1"; else echo "FAIL: $1"; ok=0; fi; } cd "$T" mkdir -p logs/old/amd64 experiments/bare_metal/runs out echo old > logs/old/amd64/qemu-amd64-old.log echo old > experiments/bare_metal/runs/doe-old.csv touch -d '2026-01-01' logs/old/amd64/qemu-amd64-old.log experiments/bare_metal/runs/doe-old.csv touch out/.started sleep 1 mkdir -p logs/new/amd64 echo new > logs/new/amd64/qemu-amd64-new.log echo new > experiments/bare_metal/runs/doe-new.csv echo stage > out/accept-amd64.txt NIGHTLY_TREE="$T" NIGHTLY_OUT="$T/out" bash "$NIGHTLY" run-logs > run.txt 2>&1; rc=$? check "the stage succeeds" '[ $rc -eq 0 ]' check "this run's serial log is kept" '[ -f out/run-logs/logs/new/amd64/qemu-amd64-new.log ]' check "this run's DoE CSV is kept" '[ -f out/run-logs/experiments/bare_metal/runs/doe-new.csv ]' check "the stages' own output is kept" '[ -f out/run-logs/out/accept-amd64.txt ]' check "an older log is not" '[ ! -e out/run-logs/logs/old ]' check "an older CSV is not" '[ ! -e out/run-logs/experiments/bare_metal/runs/doe-old.csv ]' check "it says how many files" 'grep -q "run-logs: 3 files" run.txt' rm -rf out/run-logs; rm out/.started NIGHTLY_TREE="$T" NIGHTLY_OUT="$T/out" bash "$NIGHTLY" run-logs > run2.txt 2>&1; rc=$? check "with no run started, it refuses" '[ $rc -ne 0 ]' echo "RESULT: $([ $ok = 1 ] && echo PASS || echo FAIL)" [ $ok = 1 ]