Files
xen/automation/scripts/qemu-boot-selftest-arm64.sh
Ayan Kumar Halder 24bd190cd9 xen/arm: gic: Add GIC SGI boot/self tests in Xen
Boot self-tests (also referred to as boot-time tests or power-on
self-tests) are intended to check that Xen has configured the hardware
correctly before bringing up any domains.

Introduce tests to confirm that, using a dedicated SGI (GIC_SGI_TEST):
1. A cpu can send the SGI to itself
2. A cpu can send the SGI to another specific CPU (CPU0)
3. A cpu can send the SGI to all the other CPUs

Each CPU counts the test SGIs it takes. A sender samples those counters
before sending and then waits for the count of every CPU it targeted to
change, which is how it tells that the SGI was really delivered. The
counters are never reset, so comparing against a sample rather than an
absolute value keeps concurrent senders from disturbing each other. The
snapshot is allocated rather than kept on the stack, as NR_CPUS can be
large enough for such an array to overflow it.

A test reports a failure by panic(), so Xen never continues on a
platform where SGI delivery is broken. When the tests pass, Xen carries
on booting normally.

Also introduce a config CONFIG_BOOT_SELFTEST which enables these
tests. It depends on DEBUG and is off unless explicitly enabled.

Also introduce a boolean command line parameter "gic-test", so that a
build with CONFIG_BOOT_SELFTEST enabled can be shipped but the tests
selected at boot. It is documented in
docs/misc/xen-command-line.pandoc.

In order to keep all the boot self-tests together in the binary, a
separate section "initcallboottest" is introduced. Tests are registered
using __initcallboottest() and run once on every CPU by
do_init_boottests(), bracketed by begin/end messages. They run before
any domain is created on the primary core, and before the idle loop is
entered on a secondary core.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Julien Grall <julien@xen.org>
2026-09-28 13:11:52 -07:00

73 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -ex -o pipefail
# Boot Xen under QEMU with gic-test in xen,xen-bootargs and check that every
# self-test reported OK and that Xen carried on booting.
XEN=binaries/xen
# qemu-system-aarch64 comes from the debian:13-arm64v8 test container, the
# same way the other qemu-smoke-*-arm64 scripts get it.
QEMU=qemu-system-aarch64
DTB_RAW=binaries/virt.dtb
DTB=binaries/virt-bootselftest.dtb
LOG=smoke.serial
NR_CPUS=4
test -f ${XEN}
${QEMU} \
-machine virt,virtualization=true,gic-version=3,dumpdtb=${DTB_RAW} \
-cpu cortex-a57 -m 1024 -smp ${NR_CPUS} -display none -net none
cp ${DTB_RAW} ${DTB}
fdtput -t s ${DTB} /chosen xen,xen-bootargs \
"gic-test console=dtuart sync_console"
rm -f ${LOG}
timeout 60 ${QEMU} \
-machine virt,virtualization=true,gic-version=3 \
-cpu cortex-a57 -m 1024 -smp ${NR_CPUS} \
-serial file:${LOG} \
-monitor none -display none -no-reboot -net none \
-dtb ${DTB} \
-kernel ${XEN} || true
fail=0
check() {
local what=$1
local expected=$2
local got
got=$(grep -c -- "${what}" ${LOG} || true)
if [ "${got}" -ne "${expected}" ]; then
echo "FAIL: '${what}': expected ${expected}, got ${got}"
fail=1
return
fi
echo "OK: '${what}' x${expected}"
}
# Every CPU sends an SGI to itself...
check "GIC selftest: CPU[0-9]*: SGI to self: OK" ${NR_CPUS}
# ...every secondary CPU sends one to CPU0...
check "GIC selftest: CPU[0-9]*: SGI to CPU0: OK" $((NR_CPUS - 1))
# ...and whichever CPU runs last sends one to all the others.
check "GIC selftest: CPU[0-9]*: SGI to all but self: OK" 1
check "boot self-tests done" ${NR_CPUS}
check "GIC selftest: .*did not receive" 0
# A passing self-test must leave Xen booting normally.
check "LOADING DOMAIN 0\|Xen dom0less mode detected" 1
if [ ${fail} -ne 0 ]; then
echo "FAILED"
exit 1
fi
echo "PASSED"