automation/qtb: add unit tests for the QTB framework
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/6 Add a QTB container to run the Xen riscv64 tests
QTB (QEMU Test Bench) is a Python framework, developed as part of AMD's Xen safety initiative, that drives a live QEMU instance over qtest and QMP. It gives a test full access to the machine while the emulation runs: read and write the consoles, inspect the registers and the memory, inject interrupts.
For now the riscv64 CI tests only use it to read the Xen console in the smoke test, since DomU is not supported yet. Once it is, the same framework will read and write the DomU consoles and inject IRQs, so the tests can assert an interrupt reaches the expected guest and vCPU.
QTB is not upstream in QEMU yet, though it is planned to be, so get the framework from AMD's fork gitlab.com/xen-project/people/amd/qemu and pip-installs qemu.qtb from it.
--- containerize | 1 + images/debian/13-qtb-riscv64.dockerfile | 45 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 images/debian/13-qtb-riscv64.dockerfile
containerize +1 -0
@@ -31,6 +31,7 @@ case "_${CONTAINER}" in _alpine-3.24-arm64-base) CONTAINER="${BASE}/alpine:3.24-arm64-base" ;; _alpine-3.24-arm64-build) CONTAINER="${BASE}/alpine:3.24-arm64-build" ;; _alpine-3.24-x86_64-base) CONTAINER="${BASE}/alpine:3.24-x86_64-base" ;; + _debian-13-qtb-riscv64) CONTAINER="${BASE}/debian:13-qtb-riscv64" ;; _alpine-3.24-x86_64-build|_) CONTAINER="${BASE}/alpine:3.24-x86_64-build" ;; esac
images/debian/13-qtb-riscv64.dockerfile new file +45 -0
45 lines not on this page · raw message
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 1/6 TEST-ARTIFACTS] Add a QTB container to run the Xen riscv64 tests
Hi everyone,
Apologies for the broken threading, my SMTP relay rewrote the Message-IDs. Cover letter is here:
https://lore.kernel.org/xen-devel/1786377707.8631fc262581453bbf619ec5b2062170.19fec689f7e000e099@vates.tech/T/#u
Kind regards,
Quoted 92 lines · Baptiste Le Duc
QTB (QEMU Test Bench) is a Python framework, developed as part of AMD's Xen safety initiative, that drives a live QEMU instance over qtest and QMP. It gives a test full access to the machine while the emulation runs: read and write the consoles, inspect the registers and the memory, inject interrupts.
For now the riscv64 CI tests only use it to read the Xen console in the smoke test, since DomU is not supported yet. Once it is, the same framework will read and write the DomU consoles and inject IRQs, so the tests can assert an interrupt reaches the expected guest and vCPU.
QTB is not upstream in QEMU yet, though it is planned to be, so get the framework from AMD's fork gitlab.com/xen-project/people/amd/qemu and pip-installs qemu.qtb from it.
Signed-off-by Baptiste Le Duc <[email protected]>--- containerize | 1 + images/debian/13-qtb-riscv64.dockerfile | 45 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 images/debian/13-qtb-riscv64.dockerfilecontainerize +1
-0@@ -31,6 +31,7 @@ case "_${CONTAINER}" in _alpine-3.24-arm64-base) CONTAINER="${BASE}/alpine:3.24-arm64-base" ;; _alpine-3.24-arm64-build) CONTAINER="${BASE}/alpine:3.24-arm64-build" ;; _alpine-3.24-x86_64-base) CONTAINER="${BASE}/alpine:3.24-x86_64-base" ;; + _debian-13-qtb-riscv64) CONTAINER="${BASE}/debian:13-qtb-riscv64" ;; _alpine-3.24-x86_64-build|_) CONTAINER="${BASE}/alpine:3.24-x86_64-build" ;; esacimages/debian/13-qtb-riscv64.dockerfile new file +45
-0@@ -0,0 +1,45 @@ +# syntax=docker/dockerfile:1 +FROM --platform=linux/amd64 debian:trixie-slim +LABEL maintainer.name="The Xen Project" +LABEL maintainer.email="[email protected]" + +ENV DEBIAN_FRONTEND=noninteractive + +ARG QEMU_REPO=https://gitlab.com/xen-project/people/amd/qemu.git +ARG QEMU_COMMIT=24cd7e5c0d7e4db8e651f091d0b9da2e7c58dbab + +RUN <<EOF +#!/bin/bash + set -eu + + useradd --create-home user + + apt-get update + + DEPS=(# Base environment + ca-certificates + device-tree-compiler + git + python3-jinja2 + python3-minimal + python3-pip + python3-yaml + + # Qemu for test phase + qemu-system-riscv64 + ) + + apt-get -y --no-install-recommends install "${DEPS[@]}" + + # QTB framework + git init /tmp/qemu + git -C /tmp/qemu fetch --depth 1 "$QEMU_REPO" "$QEMU_COMMIT" + git -C /tmp/qemu checkout FETCH_HEAD + pip install --break-system-packages /tmp/qemu/python[qtb] + + rm -rf /tmp/qemu + rm -rf /var/lib/apt/lists/* +EOF + +USER user +WORKDIR /buildSignature · 6 lines
-- Baptiste Le Duc | Vates Hypervisor & Kernel Engineer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 2/6 automation/qtb: add jinja2 device trees for riscv64 smoke tests
In reply to a message not in the archiveThe dom0less RISC-V smoke tests need a host device tree describing the platform (CPUs, APLIC/IMSIC, uart). It varies per machine (hart count, MMU type), so a single static .dts cannot cover the test matrix.
Add dts/qemu-host.dts.j2, a template of the QEMU virt platform in aia=aplic-imsic mode: per-hart cpu/cpu-intc nodes, the M- and S-mode APLIC and IMSIC pairs, CLINT and the ns16550a uart. It takes ncpus, mmu_type and xen_bootargs as arguments.
Values QEMU hardcodes are set as named constants matching their source symbols (QEMU_UART0_IRQ, QEMU_IRQCHIP_NUM_SOURCES, ...) rather than open-coded, so a QEMU-side change is easy to trace.
The template is inert on its own: the generated dtb will be used in next patch.
--- .../scripts/qtb/riscv/dts/qemu-host.dts.j2 | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 automation/scripts/qtb/riscv/dts/qemu-host.dts.j2
automation/scripts/qtb/riscv/dts/qemu-host.dts.j2 new file +160 -0
@@ -0,0 +1,160 @@ +/dts-v1/; + +{#- + * Jinja2 QEMU "virt" platform device tree for Xen RISC-V tests. + * + * Interrupt controller: APLIC in MSI mode + IMSIC + * (QEMU -M virt,aia=aplic-imsic). + * + * Rendered by xen_dt.py. + * + * Variables: + * ncpus - number of physical harts (int, >= 1) + * mmu_type - Xen host MMU type, e.g. "sv39" (string) + * xen_bootargs - Xen command line (string) + * + * Per-hart nodes are labelled cpu<i> / cpu<i>_intc and referenced with &label. + * + * No `aia-guests=N`, so no VS-mode guest files: IMSIC reg size is + * ncpus * page size. +-#} +{#- Values QEMU hardcodes, need to be described to Xen -#} +{%- set QEMU_TIMEBASE_FREQUENCY = 10000000 %} {#- RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ -#} +{%- set QEMU_IRQCHIP_NUM_SOURCES = 96 %} {#- VIRT_IRQCHIP_NUM_SOURCES (virt.h) -#} +{%- set QEMU_IRQCHIP_NUM_MSIS = 255 %} {#- VIRT_IRQCHIP_NUM_MSIS -#} +{%- set QEMU_UART_CLOCK_FREQUENCY = 3686400 %} {#- create_fdt_uart() -#} +{%- set QEMU_UART0_IRQ = 10 %} {#- UART0_IRQ -#} +{%- set QEMU_IMSIC_PAGE_SZ = 0x1000 %} {#- IMSIC_MMIO_PAGE_SZ -#} + +{%- set IRQ_TYPE_LEVEL_HIGH = 4 %} +{%- set APLIC_IRQ_CELLS = 2 %} + +{%- set IRQ_M_SOFT = 3 %} +{%- set IRQ_M_TIMER = 7 %} +{%- set IRQ_S_EXT = 9 %} +{%- set IRQ_M_EXT = 11 %} + +/ { + #address-cells = <0x02>; + #size-cells = <0x02>; + compatible = "riscv-virtio"; + model = "riscv-virtio,qemu"; + + memory@80000000 { + device_type = "memory"; + reg = <0x00 0x80000000 0x00 0x80000000>; + }; + + cpus { + #address-cells = <0x01>; + #size-cells = <0x00>; + timebase-frequency = <{{ QEMU_TIMEBASE_FREQUENCY }}>; +{% for i in range(ncpus) %} + cpu{{ i }}: cpu@{{ i }} { + device_type = "cpu"; + reg = <0x{{ '%x' % i }}>; + status = "okay"; + compatible = "riscv"; + riscv,cbop-block-size = <0x40>; + riscv,cboz-block-size = <0x40>; + riscv,cbom-block-size = <0x40>; + riscv,isa = "rv64imafdch_zicntr_zicsr_zifencei_zihintpause_zihpm_zba_zbb_zbs_smstateen_svpbmt_smaia_ssaia"; + mmu-type = "riscv,{{ mmu_type }}"; + + cpu{{ i }}_intc: interrupt-controller@{{ i }} { + #interrupt-cells = <0x01>; + interrupt-controller; + compatible = "riscv,cpu-intc"; + }; + }; +{% endfor %} + cpu-map { + + cluster0 { +{% for i in range(ncpus) %} + core{{ i }} { + cpu = <&cpu{{ i }}>; + }; +{% endfor %} + }; + }; + }; + + soc { + #address-cells = <0x02>; + #size-cells = <0x02>; + compatible = "simple-bus"; + ranges; + + serial@10000000 { + interrupts = <{{ QEMU_UART0_IRQ }} {{ IRQ_TYPE_LEVEL_HIGH }}>; + interrupt-parent = <&aplic_s>; + clock-frequency = <{{ QEMU_UART_CLOCK_FREQUENCY }}>; + reg = <0x00 0x10000000 0x00 0x100>; + compatible = "ns16550a"; + }; + + aplic_s: aplic@d000000 { + riscv,num-sources = <{{ QEMU_IRQCHIP_NUM_SOURCES }}>; + reg = <0x00 0xd000000 0x00 0x8000>; + msi-parent = <&imsic_s>; + interrupt-controller; + #interrupt-cells = <{{ APLIC_IRQ_CELLS }}>; + compatible = "riscv,aplic"; + }; + + aplic@c000000 { + riscv,delegate = <&aplic_s 0x01 {{ QEMU_IRQCHIP_NUM_SOURCES }}>; + riscv,children = <&aplic_s>; + riscv,num-sources = <{{ QEMU_IRQCHIP_NUM_SOURCES }}>; + reg = <0x00 0xc000000 0x00 0x8000>; + msi-parent = <&imsic_m>; + interrupt-controller; + #interrupt-cells = <{{ APLIC_IRQ_CELLS }}>; + compatible = "riscv,aplic"; + }; + + imsic_s: imsics@28000000 { + riscv,num-ids = <{{ QEMU_IRQCHIP_NUM_MSIS }}>; + reg = <0x00 0x28000000 0x00 0x{{ '%x' % (ncpus * QEMU_IMSIC_PAGE_SZ) }}>; + interrupts-extended = < + {%- for i in range(ncpus) %} + &cpu{{ i }}_intc {{ IRQ_S_EXT }} + {%- endfor %} + >; + msi-controller; + interrupt-controller; + #interrupt-cells = <0x00>; + compatible = "riscv,imsics"; + }; + + imsic_m: imsics@24000000 { + riscv,num-ids = <{{ QEMU_IRQCHIP_NUM_MSIS }}>; + reg = <0x00 0x24000000 0x00 0x{{ '%x' % (ncpus * QEMU_IMSIC_PAGE_SZ) }}>; + interrupts-extended = < + {%- for i in range(ncpus) %} + &cpu{{ i }}_intc {{ IRQ_M_EXT }} + {%- endfor %} + >; + msi-controller; + interrupt-controller; + #interrupt-cells = <0x00>; + compatible = "riscv,imsics"; + }; + + clint@2000000 { + interrupts-extended = < + {%- for i in range(ncpus) %} + &cpu{{ i }}_intc {{ IRQ_M_SOFT }} &cpu{{ i }}_intc {{ IRQ_M_TIMER }} + {%- endfor %} + >; + reg = <0x00 0x2000000 0x00 0x10000>; + compatible = "sifive,clint0", "riscv,clint0"; + }; + }; + + chosen { + stdout-path = "/soc/serial@10000000"; + xen,xen-bootargs = "{{ xen_bootargs }}"; + }; +};
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 3/6 automation/qtb: add Python QTB framework with the console-test type
In reply to a message not in the archivePort qemu-smoke-riscv64.sh from shell to a Python QTB framework that drives QEMU over qtest/QMP and the console to run riscv64 smoke tests.
The framework is based on AMD's QTB (QEMU Test Bench) framework, which is not yet upstream in QEMU but is planned to be soon. This is a riscv64 adaptation of it.
The framework:
- parses a test config (config.yaml) into typed machine descriptions (config.py). The host device tree of a machine is compiled on first use of MachineConfig.dt, so a run that never boots (list, or a config error) does not invoke dtc.
- generates the Xen host device tree from a Jinja2 template and compiles it to a DTB with dtc (xen_dt.py, dt.py).
- assembles the QEMU command line in RiscvTestMachine (machine.py), resolving artifact paths via paths.py.
- defines an abstract RiscvQtbTest base shared by every test type
(qtb_test.py).
- wires it together behind a CLI: the test type is a leading positional with list and run subcommands (qemu_smoke_riscv64.py).
console-test test type comes with it. It boots a machine from the shared catalog and asserts every expected string is printed on Xen's own console within the timeout. Its tests live in console-test.yaml, which maps console indices to the expected output strings. This makes it straightforward to add support for a domU console index once Xen provides it.
--- automation/scripts/qemu_smoke_riscv64.py | 122 +++++++++++++++ automation/scripts/qtb/__init__.py | 2 + automation/scripts/qtb/riscv/__init__.py | 9 ++ automation/scripts/qtb/riscv/config.py | 125 +++++++++++++++ automation/scripts/qtb/riscv/config.yaml | 19 +++ .../qtb/riscv/console_test/__init__.py | 4 + .../qtb/riscv/console_test/console-test.yaml | 18 +++ .../qtb/riscv/console_test/console_test.py | 145 ++++++++++++++++++ automation/scripts/qtb/riscv/dt.py | 57 +++++++ automation/scripts/qtb/riscv/machine.py | 56 +++++++ automation/scripts/qtb/riscv/paths.py | 51 ++++++ automation/scripts/qtb/riscv/qtb_test.py | 53 +++++++ automation/scripts/qtb/riscv/xen_dt.py | 58 +++++++ 13 files changed, 719 insertions(+) create mode 100755 automation/scripts/qemu_smoke_riscv64.py create mode 100644 automation/scripts/qtb/__init__.py create mode 100644 automation/scripts/qtb/riscv/__init__.py create mode 100644 automation/scripts/qtb/riscv/config.py create mode 100644 automation/scripts/qtb/riscv/config.yaml create mode 100644 automation/scripts/qtb/riscv/console_test/__init__.py create mode 100644 automation/scripts/qtb/riscv/console_test/console-test.yaml create mode 100644 automation/scripts/qtb/riscv/console_test/console_test.py create mode 100644 automation/scripts/qtb/riscv/dt.py create mode 100644 automation/scripts/qtb/riscv/machine.py create mode 100644 automation/scripts/qtb/riscv/paths.py create mode 100644 automation/scripts/qtb/riscv/qtb_test.py create mode 100644 automation/scripts/qtb/riscv/xen_dt.py
automation/scripts/qemu_smoke_riscv64.py new file +122 -0
@@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""CLI launcher for the qtb riscv64 dom0less tests. + +The test type comes first (e.g. `console-test`), then a command. Each type +reads its own config file, which ships with the type. + +Commands: + list Print every test the type defines in the config, then exit. + run Boot one test's machine under QEMU and drive it to a pass/fail + verdict. + +Usage: + ./qemu_smoke_riscv64.py console-test list + ./qemu_smoke_riscv64.py console-test run dom0less-1smp-0domu-1vcpu-aplic-imsic-null +""" + +from __future__ import annotations + +import argparse +import logging +import sys +from collections.abc import Sequence +from traceback import extract_tb, format_exc + +from qtb.riscv import RiscvQtbTest, TEST_TYPES, RiscvTestMachine, cleanup_temp_dir + +logger = logging.getLogger(__name__) + + +def _run_test(test: RiscvQtbTest, log_dir: str | None) -> int: + """Compile the machine's device trees, boot it, and run the test.""" + vm = RiscvTestMachine(test.machine, timeout=test.timeout, log_dir=log_dir) + try: + with vm: + vm.launch() + test.run(vm) + except Exception as exc: + print( + f"FAIL: {test.name}: {type(exc).__name__}: {exc}", + file=sys.stderr, + flush=True, + ) + return 1 + + print(f"PASS: {test.name}", flush=True) + return 0 + + +def _cmd_list(ns: argparse.Namespace) -> int: + """`<type> list`: print every test the type defines.""" + for name in ns.cls.list_tests(ns.cls.config_file): + print(name) + return 0 + + +def _cmd_run(ns: argparse.Namespace) -> int: + """`<type> run`: build the named test and drive it to a verdict.""" + test = ns.cls.from_config(ns.cls.config_file, ns.test) + return _run_test(test, ns.log_dir) + + +def setup_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser( + description="Launch a qtb riscv64 dom0less test: " + "qemu_smoke_riscv64.py <type> <command>.", + ) + common_args = argparse.ArgumentParser(add_help=False) + common_args.add_argument( + "-v", "--verbose", action="store_true", help="Print debug output" + ) + run_args = argparse.ArgumentParser(add_help=False) + run_args.add_argument("test", help="Name of the test to run.") + run_args.add_argument( + "--log-dir", + default=None, + metavar="DIR", + help="Directory for all logs (QEMU process log, qtest, and the " + "consoles as con<N>.log). When unset, no logs are written.", + ) + + # qemu_smoke_riscv64.py <type> <command> + types = parser.add_subparsers(dest="type", required=True) + for cls in TEST_TYPES: + desc = cls.description + cmds = types.add_parser( + cls.type_id, help=desc, description=desc + ).add_subparsers(dest="command", required=True) + cmds.add_parser( + "list", + parents=[common_args], + description=desc, + help="List the tests for the type and exit.", + ).set_defaults(func=_cmd_list, cls=cls) + cmds.add_parser( + "run", + parents=[common_args, run_args], + description=desc, + help="Run one test.", + ).set_defaults(func=_cmd_run, cls=cls) + + return parser + + +def main(argv: Sequence[str] | None = None) -> int: + ns = setup_parser().parse_args(argv) + logging.basicConfig( + level=logging.DEBUG if ns.verbose else logging.WARNING, format="%(message)s" + ) + try: + return ns.func(ns) + except Exception as exc: + logger.debug(format_exc()) + frame = extract_tb(exc.__traceback__)[-1] + print(f"{frame.filename}:{frame.lineno}: {exc}") + return 2 + finally: + cleanup_temp_dir() + + +if __name__ == "__main__": + sys.exit(main())
automation/scripts/qtb/__init__.py new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""QTB (QEMU Test Bench) test frameworks."""
automation/scripts/qtb/riscv/__init__.py new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""QTB riscv64 test framework package.""" + +from .qtb_test import RiscvQtbTest +from .console_test import ConsoleTest +from .machine import RiscvTestMachine +from .paths import cleanup_temp_dir + +TEST_TYPES: tuple[type[RiscvQtbTest], ...] = (ConsoleTest,)
automation/scripts/qtb/riscv/config.py new file +125 -0
125 lines not on this page · raw message
automation/scripts/qtb/riscv/config.yaml new file +19 -0
@@ -0,0 +1,19 @@ +# Shared config for the qtb riscv64 tests +# +# A machine is the test-agnostic description of what to boot (cpus, Xen command +# line). Test YAMLs (e.g. console-test.yaml) pick a machine by name and layer +# their own parameters on top. +# +# Path resolution (see paths.py): `binaries:` entries resolve against +# $QTB_BINARIES_DIR env var if defined else `binaries`. Absolute paths used +# as-is. + +binaries: + qemu: qemu-system-riscv64 + firmware: opensbi-riscv64-generic-fw_dynamic.bin + xen: xen + +machines: + dom0less-1smp-0domu-1vcpu-aplic-imsic-null: + xen_bootargs: "sched=null" + pcpu: 1
automation/scripts/qtb/riscv/console_test/__init__.py new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""console-test type package.""" + +from .console_test import ConsoleTest
automation/scripts/qtb/riscv/console_test/console-test.yaml new file +18 -0
@@ -0,0 +1,18 @@ +# Console string expectation test (run with: qemu_smoke_riscv64.py console-test run <test>). +# +# Each test uses a machine from config.yaml and maps a console index to the list +# of string(s) expected on that console: 0 is Xen's own console. The runner boots +# the machine and asserts each string is printed within the timeout. Nothing is +# injected. +# +# Test options: +# timeout: int # timeout between each string match (in seconds) +# attempts: int # number of tries for a wait before failing. Default 3 (min = 1) + +machine_catalog: config.yaml + +tests: + dom0less-1smp-0domu-1vcpu-aplic-imsic-null: + machine: dom0less-1smp-0domu-1vcpu-aplic-imsic-null + expect: + 0: ["All set up"]
automation/scripts/qtb/riscv/console_test/console_test.py new file +145 -0
145 lines not on this page · raw message
automation/scripts/qtb/riscv/dt.py new file +57 -0
57 lines not on this page · raw message
automation/scripts/qtb/riscv/machine.py new file +56 -0
56 lines not on this page · raw message
automation/scripts/qtb/riscv/paths.py new file +51 -0
51 lines not on this page · raw message
automation/scripts/qtb/riscv/qtb_test.py new file +53 -0
53 lines not on this page · raw message
automation/scripts/qtb/riscv/xen_dt.py new file +58 -0
58 lines not on this page · raw message
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 4/6 automation/qtb: add unit tests for the QTB framework
In reply to a message not in the archiveThe QTB framework is meant to be extended: new test types, new machines and new device trees aim to be added by other people.
Add pytest coverage of the framework's functions, and of the console-test type's config validation and expect/retry loop, so that such changes get immediate feedback and existing behaviour does not silently regress.
The suite covers 100% of the framework's statements, so a new code path added without a test shows up as a coverage drop.
The tests are meant to be run locally, from the Xen tree root:
python3 -m pytest automation/scripts/qtb/riscv/unit/
and, with pytest-cov installed, the coverage report is:
python3 -m pytest --cov=automation/scripts/qtb \
automation/scripts/qtb/riscv/unit/The tests drive fakes rather than QEMU, so they need no artifacts to run.
--- automation/scripts/qtb/riscv/unit/__init__.py | 2 + automation/scripts/qtb/riscv/unit/conftest.py | 42 ++++ .../scripts/qtb/riscv/unit/test_config.py | 128 +++++++++++ .../qtb/riscv/unit/test_console_test.py | 217 ++++++++++++++++++ automation/scripts/qtb/riscv/unit/test_dt.py | 99 ++++++++ .../scripts/qtb/riscv/unit/test_machine.py | 58 +++++ .../scripts/qtb/riscv/unit/test_temp_dir.py | 42 ++++ .../scripts/qtb/riscv/unit/test_xen_dt.py | 46 ++++ 8 files changed, 634 insertions(+) create mode 100644 automation/scripts/qtb/riscv/unit/__init__.py create mode 100644 automation/scripts/qtb/riscv/unit/conftest.py create mode 100644 automation/scripts/qtb/riscv/unit/test_config.py create mode 100644 automation/scripts/qtb/riscv/unit/test_console_test.py create mode 100644 automation/scripts/qtb/riscv/unit/test_dt.py create mode 100644 automation/scripts/qtb/riscv/unit/test_machine.py create mode 100644 automation/scripts/qtb/riscv/unit/test_temp_dir.py create mode 100644 automation/scripts/qtb/riscv/unit/test_xen_dt.py
automation/scripts/qtb/riscv/unit/__init__.py new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""pytest tests of the framework's own logic."""
automation/scripts/qtb/riscv/unit/conftest.py new file +42 -0
42 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_config.py new file +128 -0
128 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_console_test.py new file +217 -0
217 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_dt.py new file +99 -0
99 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_machine.py new file +58 -0
58 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_temp_dir.py new file +42 -0
42 lines not on this page · raw message
automation/scripts/qtb/riscv/unit/test_xen_dt.py new file +46 -0
46 lines not on this page · raw message
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 5/6 automation/qtb: add QTB framework README
In reply to a message not in the archiveDocument the qtb riscv64 test framework in a README.
It covers:
- the core concepts (machine, test type, test) and how they map to files
- the source files layout
- the CLI: qemu_smoke_riscv64.py <type> <command>, with "console-test" as the type
- the config files: the machine catalog and a type's own <type>.yaml
- the Jinja2 device-tree templates under dts/
- how to add a test (config-only) and how to add a new test type.
--- automation/scripts/qtb/riscv/README.md | 182 +++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 automation/scripts/qtb/riscv/README.md
automation/scripts/qtb/riscv/README.md new file +182 -0
@@ -0,0 +1,182 @@ +qtb riscv64 test framework +========================== + +A small framework that boots Xen under QEMU on riscv64 and drives it to a +pass/fail verdict automatically from its console output. + +It is built on QEMU's qtb (QEMU Test Bench) Python package, which gives +programmatic control of a QEMU process over QMP and qtest, plus access to the +consoles. + +What it does +------------ + +1. Reads a machine description (what to boot: cpus, Xen command line) and a + test description (what to assert). +2. Generates the host device tree. +3. Launches QEMU with Xen and the firmware wired in. +4. Reads the console and checks what Xen printed. + +Core concepts +------------- + +- Machine: test-agnostic description of what to boot. Reusable across test + types. `config.yaml` -> `MachineConfig`. +- Test type: a `RiscvQtbTest` subclass implementing the logic of a kind of test + (e.g. `console-test`). Identified by `type_id`. See `console_test/`. +- Test: one named, runnable instance of a type: a machine plus the type's + parameters. Lives in the type's `<type>.yaml`. + +A test type owns a config file describing its tests, each test names a machine +from the shared catalog (`config.yaml`) and layers its own parameters on top. + +Layout +------ + +``` +qemu_smoke_riscv64.py CLI entry point (<type> run | list) + +qtb/riscv/ This framework + __init__.py Public API + qtb_test.py RiscvQtbTest ABC every test type derives from + config.py Machine catalog parser -> MachineConfig + xen_dt.py Generates the host device tree from its Jinja2 template + dt.py Compile .dts -> .dtb with dtc + paths.py Path resolution (pkg-relative) + machine.py RiscvTestMachine: assembles the QEMU command line + + config.yaml The machine catalog (shared across test types) + dts/ Jinja2 device-tree templates (host, common) + + console_test/ The console-test type + __init__.py + console_test.py ConsoleTest implementation + console-test.yaml Its tests + + unit/ pytest unit tests of the framework logic itself +``` + +How a type is selected +---------------------- + +The test type is the first positional argument (`qemu_smoke_riscv64.py console-test run +...`). The CLI builds one subcommand per entry of `TEST_TYPES` (`__init__.py`), +named after the type's `type_id`. + +Each type declares the `config_file` it reads its tests from. + +Prerequisites +------------- + +- `qemu.qtb`, QEMU's Python package (`python/` in the QEMU tree) +- `jinja2`, `pyyaml`, `pexpect` +- `dtc` (device-tree-compiler) +- the binaries a machine boots: `qemu-system-riscv64`, the firmware + (OpenSBI) and `xen` + +CLI usage +--------- + +Run from `automation/scripts/`, or give the full path from the Xen tree root +(`./automation/scripts/qemu_smoke_riscv64.py ...`), which is what CI does. + +``` +# List every test the type defines in its config: +./qemu_smoke_riscv64.py console-test list + +# Run one test (drives it to PASS/FAIL, exit 0/1): +./qemu_smoke_riscv64.py console-test run dom0less-1smp-0domu-1vcpu-aplic-imsic-null \ + --log-dir qtb-logs +``` + +`--log-dir` (run only) collects the QEMU process log, the qtest log, and each +console as `con<N>.log`: `con0.log` is Xen's own console, the only one wired +up today. Omit it to write no logs. `-v/--verbose` raises the +log level to debug. + +Config files +------------ + +`config.yaml` is the machine catalog. `binaries:` are build artifacts resolved +under `binaries/` (overridable with `$QTB_BINARIES_DIR`); absolute paths pass +through. + +Machine entries omit any optional field left at its default. +Here are the parameters: + +- `pcpu` (required): host physical cpus. +- `mmu_type` (default `sv48`): Xen host MMU type. +- `xen_bootargs` (default `""`): Xen command line. + +`<type>.yaml` describes the tests of that type. + +`console-test` +-------------- + +A test names a machine and maps a console index to the string(s) expected on +that console: index 0 is Xen's own console (`con0`, logged as `con0.log`). + +``` +machine_catalog: config.yaml # the catalog to resolve machine names against +tests: + dom0less-1smp-0domu-1vcpu-aplic-imsic-null: + machine: dom0less-1smp-0domu-1vcpu-aplic-imsic-null # a name in config.yaml + expect: + 0: [All set up] # Xen itself must print "All set up" +``` + +Logic, per console: + +1. read the console +2. wait for each expected string in turn, in the order listed +3. bound each wait by `timeout` seconds, retrying a timed-out wait up to + `attempts` times + +The map itself must not be empty, otherwise the test would pass without +asserting anything. + +Device trees (dts/) +------------------- + +Jinja2 template, generated per machine and compiled with dtc: + +- `qemu-host.dts.j2` - the Xen host tree: the hart count, the host MMU type and + the Xen command line. + +Adding a test +------------- + +To add a test to an existing type (e.g. `console-test`): + +1. Pick a machine from `config.yaml`, or add a new one under `machines:` (set + `pcpu`, and any optional field that differs from its default — see the + field list above). +2. Add a test entry under `tests:` in the type's `<type>.yaml`, naming that + machine and supplying the type's own parameters (for `console-test`, one + `expect` list per console). +3. Run it: `./qemu_smoke_riscv64.py console-test run <your-test-name>`. + +No code change is needed, a test is pure config. + +Adding a new test type +---------------------- + +1. Create `mytype/` with `mytype.py` defining a `RiscvQtbTest` subclass: set + `type_id`, `description`, and `config_file`, and implement `from_config`, + `list_tests`, and `run(vm)`. +2. Add `mytype/__init__.py` that does `from .mytype import MyType`. +3. Add `MyType` to `TEST_TYPES` in `__init__.py` so the CLI exposes it. + +Unit tests +---------- + +The `unit/` directory holds pytest tests of the framework's own logic (config +parsing, device-tree rendering, QEMU arg assembly). They do not boot QEMU and +are independent of the CI smoke tests, but they import the framework, so they +need the prerequisites above plus `pytest`. + +Run from the Xen tree root: + +``` +python3 -m pytest automation/scripts/qtb/riscv/unit/ +```
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 6/6 CI: run the riscv64 smoke test via QTB framework console-test
In reply to a message not in the archiveqemu-smoke-riscv64-gcc drove QEMU through automation/scripts/qemu-smoke-riscv64.sh, an expect wrapper whose machine description (cpus, memory, device tree, console wiring) lived in the script itself. The QTB framework now owns all of that: machines come from the shared catalog, expectations from the test type's own YAML.
Turn .qemu-riscv64 into a template running qemu_smoke_riscv64.py <type> run <test> in the qtb-riscv64 container, machine and test picked per job through QTB_TEST_TYPE/QTB_TEST. The container comes from the test-artifacts registry, hence the new ARTIFACTS_REGISTRY next to the existing ARTIFACTS_REPO/ARTIFACTS_BRANCH. QTB_BINARIES_DIR points at the artifacts of the job in the new .riscv64-test-needs anchor (QEMU and its firmware), and QTB_LOG_DIR collects the per-console logs, kept on failure and on success.
Point qemu-smoke-riscv64-gcc at that template, running the console-test type on dom0less-1smp-0domu-1vcpu-aplic-imsic-null: a Xen-only machine, so the smoke check is Xen's own "All set up" on console 0, the same string the expect script waited for.
Drop automation/scripts/qemu-smoke-riscv64.sh as it has no caller left in the CI after this patch and drop smoke.serial from the .qemu-riscv64 artifacts since no riscv64 job uses it anymore, the logs are now kept under QTB_LOG_DIR.
--- .gitlab-ci.yml | 3 +++ automation/gitlab-ci/test.yaml | 26 ++++++++++++++++++------ automation/scripts/qemu-smoke-riscv64.sh | 19 ----------------- 3 files changed, 23 insertions(+), 25 deletions(-) delete mode 100755 automation/scripts/qemu-smoke-riscv64.sh
.gitlab-ci.yml +3 -0
@@ -11,6 +11,9 @@ variables: ARTIFACTS_BRANCH: description: "Branch in test-artifacts to use" value: master + ARTIFACTS_REGISTRY: + description: "Registry holding the test-artifacts containers" + value: registry.gitlab.com/xen-project/hardware/test-artifacts LINUX_JOB_X86_64: description: "Job name in test-artifacts to use for Linux x86_64" value: linux-6.6.56-x86_64
automation/gitlab-ci/test.yaml +20 -6
@@ -5,6 +5,11 @@ - if: $CI_JOB_NAME =~ $SELECTED_JOBS_ONLY when: on_success +.riscv64-test-needs: &riscv64-test-needs + - project: $ARTIFACTS_REPO + job: qemu-9.0.0-riscv64 + ref: $ARTIFACTS_BRANCH + .arm64-test-needs: &arm64-test-needs - project: $ARTIFACTS_REPO job: $LINUX_JOB_ARM64
@@ -72,14 +77,21 @@ TEST_TIMEOUT_OVERRIDE: 120 .qemu-riscv64: + image: ${ARTIFACTS_REGISTRY}/${CONTAINER} extends: .test-jobs-common variables: - CONTAINER: debian:13-riscv64 - LOGFILE: qemu-smoke-riscv64.log + CONTAINER: debian:13-qtb-riscv64 + QTB_LOG_DIR: qtb-logs + QTB_BINARIES_DIR: ${CI_PROJECT_DIR}/binaries + script: + - ./automation/scripts/qemu_smoke_riscv64.py + ${QTB_TEST_TYPE} + run + ${QTB_TEST} + --log-dir ${QTB_LOG_DIR} artifacts: paths: - - smoke.serial - - '*.log' + - ${QTB_LOG_DIR} when: always tags: - x86_64
@@ -779,9 +791,11 @@ qemu-xtf-argo-x86_64-gcc-debug: qemu-smoke-riscv64-gcc: extends: .qemu-riscv64 - script: - - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE} + variables: + QTB_TEST_TYPE: console-test + QTB_TEST: dom0less-1smp-0domu-1vcpu-aplic-imsic-null needs: + - *riscv64-test-needs - debian-13-riscv64-gcc-debug qemu-smoke-ppc64le-powernv9-gcc:
automation/scripts/qemu-smoke-riscv64.sh deleted +0 -19
@@ -1,19 +0,0 @@ -#!/bin/bash - -set -ex -o pipefail - -# Run the test -rm -f smoke.serial - -export TEST_CMD="qemu-system-riscv64 \ - -M virt,aia=aplic-imsic \ - -cpu rv64,svpbmt=on \ - -smp 1 \ - -nographic \ - -m 2g \ - -kernel binaries/xen" - -export TEST_LOG="smoke.serial" -export PASSED="All set up" - -./automation/scripts/console.exp |& sed 's/\r\+$//'
--
Baptiste Le Duc | Vates Hypervisor & Kernel Engineer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 6/6] CI: run the riscv64 smoke test via QTB framework console-test
On 2026-08-10 18:09 +0200, Baptiste Le Duc wrote:
During an internal review, Zheng Zhang ([email protected]) pointed out that this patch series defines the qemu-9.0.0 in riscv64-test-needs of test.yaml, whereas we should use the QEMU bundled in the 13-qtb-riscv64 container.
I will fix this in v2 by resolving qemu-system-riscv64 from $PATH, since the test runs inside the 13-qtb-riscv64 container.
As a consequence, the OpenSBI path in binaries in config.yaml is no longer needed either: qemu-system-riscv64 uses the firmware bundled with it.
Quoted 137 lines
qemu-smoke-riscv64-gcc drove QEMU through
automation/scripts/qemu-smoke-riscv64.sh, an expect wrapper whose machine description (cpus, memory, device tree, console wiring) lived in the script itself. The QTB framework now owns all of that: machines come from the shared catalog, expectations from the test type's own YAML.Turn .qemu-riscv64 into a template running
qemu_smoke_riscv64.py<type> run <test> in the qtb-riscv64 container, machine and test picked per job through QTB_TEST_TYPE/QTB_TEST. The container comes from the test-artifacts registry, hence the newARTIFACTS_REGISTRYnext to the existing ARTIFACTS_REPO/ARTIFACTS_BRANCH.QTB_BINARIES_DIRpoints at the artifacts of the job in the new .riscv64-test-needs anchor (QEMU and its firmware), andQTB_LOG_DIRcollects the per-console logs, kept on failure and on success.Point qemu-smoke-riscv64-gcc at that template, running the console-test type on dom0less-1smp-0domu-1vcpu-aplic-imsic-null: a Xen-only machine, so the smoke check is Xen's own "All set up" on console 0, the same string the expect script waited for.
Drop
automation/scripts/qemu-smoke-riscv64.shas it has no caller left in the CI after this patch and drop smoke.serial from the .qemu-riscv64 artifacts since no riscv64 job uses it anymore, the logs are now kept underQTB_LOG_DIR.Assisted-by Claude:claude-opus-5Signed-off-by Baptiste Le Duc <[email protected]>--- .gitlab-ci.yml | 3 +++ automation/gitlab-ci/test.yaml | 26 ++++++++++++++++++------ automation/scripts/qemu-smoke-riscv64.sh | 19 ----------------- 3 files changed, 23 insertions(+), 25 deletions(-) delete mode 100755 automation/scripts/qemu-smoke-riscv64.sh.gitlab-ci.yml +3
-0@@ -11,6 +11,9 @@ variables: ARTIFACTS_BRANCH: description: "Branch in test-artifacts to use" value: master + ARTIFACTS_REGISTRY: + description: "Registry holding the test-artifacts containers" + value: registry.gitlab.com/xen-project/hardware/test-artifacts LINUX_JOB_X86_64: description: "Job name in test-artifacts to use for Linux x86_64" value: linux-6.6.56-x86_64automation/gitlab-ci/test.yaml +20
-6@@ -5,6 +5,11 @@ - if: $CI_JOB_NAME =~ $SELECTED_JOBS_ONLY when: on_success +.riscv64-test-needs: &riscv64-test-needs + - project: $ARTIFACTS_REPO + job: qemu-9.0.0-riscv64 + ref: $ARTIFACTS_BRANCH + .arm64-test-needs: &arm64-test-needs - project: $ARTIFACTS_REPO job: $LINUX_JOB_ARM64@@ -72,14 +77,21 @@ TEST_TIMEOUT_OVERRIDE: 120 .qemu-riscv64: + image: ${ARTIFACTS_REGISTRY}/${CONTAINER} extends: .test-jobs-common variables: - CONTAINER: debian:13-riscv64 - LOGFILE: qemu-smoke-riscv64.log + CONTAINER: debian:13-qtb-riscv64 + QTB_LOG_DIR: qtb-logs + QTB_BINARIES_DIR: ${CI_PROJECT_DIR}/binaries + script: + - ./automation/scripts/qemu_smoke_riscv64.py + ${QTB_TEST_TYPE} + run + ${QTB_TEST} + --log-dir ${QTB_LOG_DIR} artifacts: paths: - - smoke.serial - - '*.log' + - ${QTB_LOG_DIR} when: always tags: - x86_64@@ -779,9 +791,11 @@ qemu-xtf-argo-x86_64-gcc-debug: qemu-smoke-riscv64-gcc: extends: .qemu-riscv64 - script: - - ./automation/scripts/qemu-smoke-riscv64.sh 2>&1 | tee ${LOGFILE} + variables: + QTB_TEST_TYPE: console-test + QTB_TEST: dom0less-1smp-0domu-1vcpu-aplic-imsic-null needs: + - *riscv64-test-needs - debian-13-riscv64-gcc-debug qemu-smoke-ppc64le-powernv9-gcc:automation/scripts/qemu-smoke-riscv64.sh deleted +0
-19@@ -1,19 +0,0 @@ -#!/bin/bash - -set -ex -o pipefail - -# Run the test -rm -f smoke.serial - -export TEST_CMD="qemu-system-riscv64 \ - -M virt,aia=aplic-imsic \ - -cpu rv64,svpbmt=on \ - -smp 1 \ - -nographic \ - -m 2g \ - -kernel binaries/xen" - -export TEST_LOG="smoke.serial" -export PASSED="All set up" - -./automation/scripts/console.exp |& sed 's/\r\+$//'Signature · 6 lines
-- Baptiste Le Duc | Vates Hypervisor & Kernel Engineer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech