[Buildroot] [PATCH v5 7/9] support/testing: add test for kvm-unit-tests

Alex Bennée alex.bennee at linaro.org
Thu Sep 11 21:27:47 UTC 2025


Now we have updated kvm-unit-tests we should defend it with a test. To
support that enable KVM in the qemu kernel config and boot an image
where we can run the basic tests.

Signed-off-by: Alex Bennée <alex.bennee at linaro.org>
---
 board/qemu/aarch64-virt/linux.config      |  2 +
 support/testing/tests/package/test_kvm.py | 47 +++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 support/testing/tests/package/test_kvm.py

diff --git a/board/qemu/aarch64-virt/linux.config b/board/qemu/aarch64-virt/linux.config
index 971b9fcf86..9d1934c648 100644
--- a/board/qemu/aarch64-virt/linux.config
+++ b/board/qemu/aarch64-virt/linux.config
@@ -74,3 +74,5 @@ CONFIG_VIRTIO_FS=y
 CONFIG_OVERLAY_FS=y
 CONFIG_TMPFS=y
 CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_VIRTUALIZATION=y
+CONFIG_KVM=y
diff --git a/support/testing/tests/package/test_kvm.py b/support/testing/tests/package/test_kvm.py
new file mode 100644
index 0000000000..da5ebfb1b7
--- /dev/null
+++ b/support/testing/tests/package/test_kvm.py
@@ -0,0 +1,47 @@
+import os
+import infra.basetest
+
+KVM_TIMEOUT = 120
+
+
+class TestKVM(infra.basetest.BRTest):
+    config = \
+        """
+        BR2_aarch64=y
+        BR2_cortex_a72=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TOOLCHAIN_EXTERNAL_LIBC_UTILS_COPY=y
+        BR2_OPTIMIZE_S=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_LINUX_KERNEL=y
+        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
+        BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
+        BR2_PACKAGE_KVM_UNIT_TESTS=y
+        # BR2_PACKAGE_QEMU_SYSTEM_TCG is not set
+        # BR2_PACKAGE_QEMU_BLOBS is not set
+        BR2_TARGET_ROOTFS_EXT2=y
+        """
+
+    def test_run(self):
+        kern = os.path.join(self.builddir, "images", "Image")
+        img = os.path.join(self.builddir, "images", "rootfs.ext2")
+
+        qemu_opts = ["-M", "virt,gic-version=3,virtualization=on",
+                     "-cpu", "cortex-a72",
+                     "-smp", "2",
+                     "-m", "512M",
+                     "-drive", f"file={img},if=virtio,format=raw", "-snapshot"]
+
+        self.emulator.boot(arch="aarch64",
+                           kernel=kern,
+                           kernel_cmdline=["root=/dev/vda console=ttyAMA0"],
+                           options=qemu_opts)
+
+        self.emulator.login()
+
+        # Run the selftests
+        self.assertRunOk("/usr/share/kvm-unit-tests/selftest-setup")
+        self.assertRunOk("/usr/share/kvm-unit-tests/selftest-smp")
+        self.assertRunOk("/usr/share/kvm-unit-tests/selftest-vectors-kernel")
+        self.assertRunOk("/usr/share/kvm-unit-tests/selftest-vectors-user")
-- 
2.47.3



More information about the buildroot mailing list