From 2bd4834d9ead30f17e5bcacca08ee896546b109a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Stehl=C3=A9?= Date: Tue, 22 Jul 2025 15:39:53 +0200 Subject: [PATCH] support/testing: test_xen: add a base class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In preparation of adding a test for Xen on 32-bit Arm v7: - Introduce an architecture-agnostic TestXenBase class where we move most of the Xen test scenario and bits of the configuration. - Re-organise the test_xen/ folder with the architecture-agnostic files under common/ and the 64-bit Arm specific files under aarch64/. Make the 64-bit Arm TestXen class inherit from the base class and leave in there only the architecture-specific parts: - The 64-bit Arm configuration bits. - The test function, which passes the proper 64-bit Arm simulator options to the generic test function. No functional change intended. Signed-off-by: Vincent Stehlé Signed-off-by: Julien Olivain (cherry picked from commit a6f0d33c878b33b4706032381e3c24521e7fd0d4) Signed-off-by: Thomas Perale --- support/testing/tests/package/test_xen.py | 85 ++++++++++++------- .../test_xen/{ => aarch64}/genimage.cfg | 0 .../test_xen/{ => aarch64}/linux.config | 0 .../{ => aarch64}/overlay/etc/xen/dom1.cfg | 0 .../test_xen/{ => aarch64}/post-image.sh | 0 .../package/test_xen/{ => aarch64}/xen.cfg | 0 .../{ => common}/overlay/etc/init.d/S99custom | 0 .../overlay/etc/profile.d/stty-raw.sh | 0 .../test_xen/{ => common}/post-build.sh | 0 9 files changed, 52 insertions(+), 33 deletions(-) rename support/testing/tests/package/test_xen/{ => aarch64}/genimage.cfg (100%) rename support/testing/tests/package/test_xen/{ => aarch64}/linux.config (100%) rename support/testing/tests/package/test_xen/{ => aarch64}/overlay/etc/xen/dom1.cfg (100%) rename support/testing/tests/package/test_xen/{ => aarch64}/post-image.sh (100%) rename support/testing/tests/package/test_xen/{ => aarch64}/xen.cfg (100%) rename support/testing/tests/package/test_xen/{ => common}/overlay/etc/init.d/S99custom (100%) rename support/testing/tests/package/test_xen/{ => common}/overlay/etc/profile.d/stty-raw.sh (100%) rename support/testing/tests/package/test_xen/{ => common}/post-build.sh (100%) diff --git a/support/testing/tests/package/test_xen.py b/support/testing/tests/package/test_xen.py index e5eaf3c115..44425a1f26 100644 --- a/support/testing/tests/package/test_xen.py +++ b/support/testing/tests/package/test_xen.py @@ -3,25 +3,19 @@ import pexpect import infra.basetest -class TestXen(infra.basetest.BRTest): - # We have a custom kernel config to reduce build time. - # Our genimage.cfg is inspired from qemu_aarch64_ebbr_defconfig as we boot - # Xen with UEFI. We run only in the initramfs; this allows to use a single - # ramdisk image for both the host and the guest. - # The Xen startup scripts need bash. - config = \ +class TestXenBase(infra.basetest.BRTest): + """A class to test Xen for multiple architectures.""" + + # We run only in the initramfs; this allows to use a single ramdisk image + # for both the host and the guest. + base_config = \ """ - BR2_aarch64=y BR2_TOOLCHAIN_EXTERNAL=y - BR2_ROOTFS_OVERLAY="support/testing/tests/package/test_xen/overlay" - BR2_ROOTFS_POST_BUILD_SCRIPT="support/testing/tests/package/test_xen/post-build.sh" - BR2_ROOTFS_POST_IMAGE_SCRIPT="support/testing/tests/package/test_xen/post-image.sh support/scripts/genimage.sh" - BR2_ROOTFS_POST_SCRIPT_ARGS="-c support/testing/tests/package/test_xen/genimage.cfg" + BR2_ROOTFS_POST_BUILD_SCRIPT="support/testing/tests/package/test_xen/common/post-build.sh" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.9" BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y - BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="support/testing/tests/package/test_xen/linux.config" BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y BR2_PACKAGE_XEN=y BR2_PACKAGE_XEN_HYPERVISOR=y @@ -32,7 +26,6 @@ class TestXen(infra.basetest.BRTest): BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y BR2_TARGET_UBOOT_CUSTOM_VERSION=y BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2025.01" - BR2_TARGET_UBOOT_BOARD_DEFCONFIG="qemu_arm64" BR2_TARGET_UBOOT_NEEDS_OPENSSL=y BR2_TARGET_UBOOT_NEEDS_GNUTLS=y BR2_PACKAGE_HOST_DOSFSTOOLS=y @@ -51,26 +44,14 @@ class TestXen(infra.basetest.BRTest): num_vm = len(out) - 1 self.assertEqual(num_vm, x, f"Expected {x} VM(s) but found {num_vm}") - def test_run(self): - uboot_bin = os.path.join(self.builddir, "images", "u-boot.bin") - disk_img = os.path.join(self.builddir, "images", "disk.img") + def run_xen_test(self, arch: str, options: list[str]) -> None: + """This functions tests Xen for multiple architectures. + The arch and options parameters are passed to the emulator. + """ - # We need to run Qemu with virtualization to run Xen. - qemu_opts = [ - "-bios", uboot_bin, - "-cpu", "cortex-a53", - "-device", "virtio-blk-device,drive=hd0", - "-drive", f"file={disk_img},if=none,format=raw,id=hd0", - "-m", "1G", - "-machine", "virt,gic-version=3,virtualization=on,acpi=off", - "-smp", "2" - ] - - # Boot the emulator: - # Qemu Devicetree -> U-Boot -> Xen UEFI -> Linux - # We need to boot Xen in UEFI to read xen.cfg; we use U-Boot as our - # UEFI firmware. - self.emulator.boot(arch="aarch64", options=qemu_opts) + # Boot the emulator. + # The system should automatically boot Xen and a Dom0. + self.emulator.boot(arch=arch, options=options) self.emulator.login() # Verify that we are indeed running under Xen. @@ -106,3 +87,41 @@ class TestXen(infra.basetest.BRTest): # Check that we have two VMs running. self.assertNumVM(2) + + +class TestXen(TestXenBase): + # Test Xen on 64b Arm. + # Boot flow: Qemu Devicetree -> U-Boot -> Xen UEFI -> Linux + # We need to boot Xen in UEFI to read xen.cfg. + # We use U-Boot as our UEFI firmware. + # We have a custom kernel config to reduce build time. + # Our genimage.cfg is inspired from qemu_aarch64_ebbr_defconfig as we boot + # Xen with UEFI. + config = TestXenBase.base_config + \ + """ + BR2_aarch64=y + BR2_ROOTFS_OVERLAY="support/testing/tests/package/test_xen/common/overlay \ + support/testing/tests/package/test_xen/aarch64/overlay" + BR2_ROOTFS_POST_IMAGE_SCRIPT="support/testing/tests/package/test_xen/aarch64/post-image.sh support/scripts/genimage.sh" + BR2_ROOTFS_POST_SCRIPT_ARGS="-c support/testing/tests/package/test_xen/aarch64/genimage.cfg" + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="support/testing/tests/package/test_xen/aarch64/linux.config" + BR2_TARGET_UBOOT_BOARD_DEFCONFIG="qemu_arm64" + """ + + def test_run(self): + uboot_bin = os.path.join(self.builddir, "images", "u-boot.bin") + disk_img = os.path.join(self.builddir, "images", "disk.img") + + # We need to run Qemu with virtualization to run Xen. + qemu_opts = [ + "-bios", uboot_bin, + "-cpu", "cortex-a53", + "-device", "virtio-blk-device,drive=hd0", + "-drive", f"file={disk_img},if=none,format=raw,id=hd0", + "-m", "1G", + "-machine", "virt,gic-version=3,virtualization=on,acpi=off", + "-smp", "2" + ] + + # Run Xen test. + self.run_xen_test(arch="aarch64", options=qemu_opts) diff --git a/support/testing/tests/package/test_xen/genimage.cfg b/support/testing/tests/package/test_xen/aarch64/genimage.cfg similarity index 100% rename from support/testing/tests/package/test_xen/genimage.cfg rename to support/testing/tests/package/test_xen/aarch64/genimage.cfg diff --git a/support/testing/tests/package/test_xen/linux.config b/support/testing/tests/package/test_xen/aarch64/linux.config similarity index 100% rename from support/testing/tests/package/test_xen/linux.config rename to support/testing/tests/package/test_xen/aarch64/linux.config diff --git a/support/testing/tests/package/test_xen/overlay/etc/xen/dom1.cfg b/support/testing/tests/package/test_xen/aarch64/overlay/etc/xen/dom1.cfg similarity index 100% rename from support/testing/tests/package/test_xen/overlay/etc/xen/dom1.cfg rename to support/testing/tests/package/test_xen/aarch64/overlay/etc/xen/dom1.cfg diff --git a/support/testing/tests/package/test_xen/post-image.sh b/support/testing/tests/package/test_xen/aarch64/post-image.sh similarity index 100% rename from support/testing/tests/package/test_xen/post-image.sh rename to support/testing/tests/package/test_xen/aarch64/post-image.sh diff --git a/support/testing/tests/package/test_xen/xen.cfg b/support/testing/tests/package/test_xen/aarch64/xen.cfg similarity index 100% rename from support/testing/tests/package/test_xen/xen.cfg rename to support/testing/tests/package/test_xen/aarch64/xen.cfg diff --git a/support/testing/tests/package/test_xen/overlay/etc/init.d/S99custom b/support/testing/tests/package/test_xen/common/overlay/etc/init.d/S99custom similarity index 100% rename from support/testing/tests/package/test_xen/overlay/etc/init.d/S99custom rename to support/testing/tests/package/test_xen/common/overlay/etc/init.d/S99custom diff --git a/support/testing/tests/package/test_xen/overlay/etc/profile.d/stty-raw.sh b/support/testing/tests/package/test_xen/common/overlay/etc/profile.d/stty-raw.sh similarity index 100% rename from support/testing/tests/package/test_xen/overlay/etc/profile.d/stty-raw.sh rename to support/testing/tests/package/test_xen/common/overlay/etc/profile.d/stty-raw.sh diff --git a/support/testing/tests/package/test_xen/post-build.sh b/support/testing/tests/package/test_xen/common/post-build.sh similarity index 100% rename from support/testing/tests/package/test_xen/post-build.sh rename to support/testing/tests/package/test_xen/common/post-build.sh