joeylib2/scripts/bench-be.sh
2026-10-13 14:01:46 -05:00

64 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# Headless UBER run for a Be API port (haiku, haiku32, beos): UBER in the
# port's VM under QEMU (scripts/lib/beGate.sh), until its joeylog.txt says
# "press any key to exit"; the log is then copied beside the program,
# build/<port>/bin.
#
# The stage is the generic chunky one, so the hashes must equal the DOS
# port's:
# scripts/bench-be.sh && tools/diff-uber-hashes tests/goldens/uber/dos.txt build/haiku/bin/joeylog.txt
# scripts/bench-be.sh haiku32 && tools/diff-uber-hashes tests/goldens/uber/dos.txt build/haiku32/bin/joeylog.txt
# scripts/bench-be.sh beos && tools/diff-uber-hashes tests/goldens/uber/dos.txt build/beos/bin/joeylog.txt
# The ops/sec are this machine's in a VM: compare them only run against run.
#
# scripts/bench-be.sh [haiku|haiku32|beos] # default haiku (x86_64)
# TIMEOUT=600 scripts/bench-be.sh # default 300 s for UBER itself
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/beGate.sh"
port=${1:-haiku}
label="bench-be ($port)"
beNeed "$port"
program=$(joeyExampleProgram uber "$port")
[ -x "$program" ] || { echo "$label: build UBER first (make $port)" >&2; exit 2; }
log=$(dirname "$program")/joeylog.txt
timeoutSeconds=${TIMEOUT:-300}
bootSeconds=120
work=$(mktemp -d -t joeylib-be-bench.XXXXXX)
cleanup() {
beStop
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/job/UBER"
cp "$program" "$work/job/UBER/UBER"
beJobScript UBER UBER "UBER: press any key to exit" "$timeoutSeconds" > "$work/job/job.sh"
beJobDisk "$work/job.img" "$work/job"
rm -f "$log"
beStart "$work" "$work/job.img"
if ! beWaitJob "$work" "$bootSeconds"; then
echo "$label: FAIL - the VM did not start the job within ${bootSeconds} s" >&2
exit 1
fi
if ! beWaitExit "$work" "$timeoutSeconds"; then
echo "$label: FAIL - UBER did not finish within ${timeoutSeconds} s" >&2
exit 1
fi
beJobGet "$work/job.img" UBER/joeylog.txt "$log" || true
if grep -q "press any key to exit" "$log" 2>/dev/null; then
echo "$label: UBER finished; log in ${log#"$repo"/}"
exit 0
fi
echo "$label: FAIL - UBER ended without finishing (job log below)" >&2
beJobGet "$work/job.img" job.log "$work/job.log" && cat "$work/job.log" >&2
exit 1