diff mbox series

[v2,3/3] tests/avocado: Test Xen guest support under KVM

Message ID 20230308111952.2728440-4-dwmw2@infradead.org
State New
Headers show
Series Enable avocado testing for Xen guests | expand

Commit Message

David Woodhouse March 8, 2023, 11:19 a.m. UTC
From: David Woodhouse <dwmw@amazon.co.uk>

Exercise guests with a few different modes for interrupt delivery. In
particular we want to cover:

 • Xen event channel delivery via GSI to the I/O APIC
 • Xen event channel delivery via GSI to the i8259 PIC
 • MSIs routed to PIRQ event channels
 • GSIs routed to PIRQ event channels

As well as some variants of normal non-Xen stuff like MSI to vAPIC and
PCI INTx going to the I/O APIC and PIC, which ought to still work even
in Xen mode.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 tests/avocado/xen_guest.py | 147 +++++++++++++++++++++++++++++++++++++
 1 file changed, 147 insertions(+)
 create mode 100644 tests/avocado/xen_guest.py

Comments

Alex Bennée March 8, 2023, 5:45 p.m. UTC | #1
David Woodhouse <dwmw2@infradead.org> writes:

> From: David Woodhouse <dwmw@amazon.co.uk>
>
> Exercise guests with a few different modes for interrupt delivery. In
> particular we want to cover:
>
>  • Xen event channel delivery via GSI to the I/O APIC
>  • Xen event channel delivery via GSI to the i8259 PIC
>  • MSIs routed to PIRQ event channels
>  • GSIs routed to PIRQ event channels
>
> As well as some variants of normal non-Xen stuff like MSI to vAPIC and
> PCI INTx going to the I/O APIC and PIC, which ought to still work even
> in Xen mode.
>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>  tests/avocado/xen_guest.py | 147 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 147 insertions(+)
>  create mode 100644 tests/avocado/xen_guest.py
>
> diff --git a/tests/avocado/xen_guest.py b/tests/avocado/xen_guest.py
> new file mode 100644
> index 0000000000..c50b52958f
> --- /dev/null
> +++ b/tests/avocado/xen_guest.py
> @@ -0,0 +1,147 @@
> +# Xen guest functional tests
> +#

Perhaps to avoid confusion we should call the file kvm_xen_guests.py and
make it clearer in the comment this is the mode we are talking about.
c.f. the boot_xen.py tests which boot Xen (under TCG emulation) as a
proper hypervisor.

> +# Copyright © 2021 Red Hat, Inc.
> +# Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
> +#
> +# Author:
> +#  David Woodhouse <dwmw2@infradead.org>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later.  See the COPYING file in the top-level directory.
> +import os
> +
> +from avocado import skipIf
> +from avocado_qemu import LinuxTest
> +
> +@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')

This just means we will never have CI coverage. In theory when running
on the GitLab shared runners the test should skip anyway when it can't
find /dev/kvm and hopefully can run on our custom runners when it can
see /dev/kvm.

> +class XenGuest(LinuxTest):
> +    """
> +    :avocado: tags=arch:x86_64
> +    :avocado: tags=distro:fedora
> +    :avocado: tags=distro_version:34
> +    :avocado: tags=machine:q35
> +    :avocado: tags=accel:kvm
> +    :avocado: tags=xen_guest
> +    """
> +
> +    kernel_path = None
> +    initrd_path = None
> +    kernel_params = None
> +
> +    def set_up_boot(self):
> +        path = self.download_boot()
> +        self.vm.add_args('-drive', 'file=%s,if=none,id=drv0' % path)
> +        self.vm.add_args('-device', 'xen-disk,drive=drv0,vdev=xvda')
> +
> +    def setUp(self):
> +        super(XenGuest, self).setUp(None, 'virtio-net-pci')
> +
> +    def common_vm_setup(self, custom_kernel=None):
> +        self.require_accelerator("kvm")
> +        self.vm.add_args("-accel", "kvm,xen-version=0x4000a,kernel-irqchip=split")
> +        self.vm.add_args("-smp", "4")
> +
> +        if custom_kernel is None:
> +            return
> +
> +        kernel_url = self.distro.pxeboot_url + 'vmlinuz'
> +        initrd_url = self.distro.pxeboot_url + 'initrd.img'
> +        self.kernel_path = self.fetch_asset(kernel_url, algorithm='sha256',
> +                                            asset_hash=self.distro.kernel_hash)
> +        self.initrd_path = self.fetch_asset(initrd_url, algorithm='sha256',
> +                                            asset_hash=self.distro.initrd_hash)
> +
> +    def run_and_check(self):
> +        if self.kernel_path:
> +            self.vm.add_args('-kernel', self.kernel_path,
> +                             '-append', self.kernel_params,
> +                             '-initrd', self.initrd_path)
> +        self.launch_and_wait()
> +        self.ssh_command('cat /proc/cmdline')
> +        self.ssh_command('dmesg | grep -e "Grant table initialized"')
> +
> +    def test_xen_guest(self):
> +        """
> +        :avocado: tags=xen_guest
> +        """
> +
> +        self.common_vm_setup(True)
> +
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-pirq.*msi /proc/interrupts')
> +
> +    def test_xen_guest_nomsi(self):
> +        """
> +        :avocado: tags=xen_guest_nomsi
> +        """
> +
> +        self.common_vm_setup(True)
> +
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks pci=nomsi')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-pirq.* /proc/interrupts')
> +
> +    def test_xen_guest_noapic_nomsi(self):
> +        """
> +        :avocado: tags=xen_guest_noapic_nomsi
> +        """
> +
> +        self.common_vm_setup(True)
> +
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks noapic pci=nomsi')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-pirq /proc/interrupts')
> +
> +    def test_xen_guest_vapic(self):
> +        """
> +        :avocado: tags=xen_guest_vapic
> +        """
> +
> +        self.common_vm_setup(True)
> +        self.vm.add_args('-cpu', 'host,+xen-vapic')
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-pirq /proc/interrupts')
> +        self.ssh_command('grep PCI-MSI /proc/interrupts')
> +
> +    def test_xen_guest_novector(self):
> +        """
> +        :avocado: tags=xen_guest_novector
> +        """
> +
> +        self.common_vm_setup(True)
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks' +
> +                              ' xen_no_vector_callback')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-platform-pci /proc/interrupts')
> +
> +    def test_xen_guest_novector_nomsi(self):
> +        """
> +        :avocado: tags=xen_guest_novector_nomsi
> +        """
> +
> +        self.common_vm_setup(True)
> +
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks pci=nomsi' +
> +                              ' xen_no_vector_callback')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-platform-pci /proc/interrupts')
> +
> +    def test_xen_guest_novector_noapic(self):
> +        """
> +        :avocado: tags=xen_guest_novector_noapic
> +        """
> +
> +        self.common_vm_setup(True)
> +        self.kernel_params = (self.distro.default_kernel_params +
> +                              ' xen_emul_unplug=ide-disks' +
> +                              ' xen_no_vector_callback noapic')
> +        self.run_and_check()
> +        self.ssh_command('grep xen-platform-pci /proc/interrupts')
David Woodhouse March 8, 2023, 7:07 p.m. UTC | #2
On Wed, 2023-03-08 at 17:45 +0000, Alex Bennée wrote:
> 
> David Woodhouse <dwmw2@infradead.org> writes:
> 
> > From: David Woodhouse <dwmw@amazon.co.uk>
> > 
> > Exercise guests with a few different modes for interrupt delivery. In
> > particular we want to cover:
> > 
> >  • Xen event channel delivery via GSI to the I/O APIC
> >  • Xen event channel delivery via GSI to the i8259 PIC
> >  • MSIs routed to PIRQ event channels
> >  • GSIs routed to PIRQ event channels
> > 
> > As well as some variants of normal non-Xen stuff like MSI to vAPIC and
> > PCI INTx going to the I/O APIC and PIC, which ought to still work even
> > in Xen mode.
> > 
> > Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> > ---
> >  tests/avocado/xen_guest.py | 147 +++++++++++++++++++++++++++++++++++++
> >  1 file changed, 147 insertions(+)
> >  create mode 100644 tests/avocado/xen_guest.py
> > 
> > diff --git a/tests/avocado/xen_guest.py b/tests/avocado/xen_guest.py
> > new file mode 100644
> > index 0000000000..c50b52958f
> > --- /dev/null
> > +++ b/tests/avocado/xen_guest.py
> > @@ -0,0 +1,147 @@
> > +# Xen guest functional tests
> > +#
> 
> Perhaps to avoid confusion we should call the file kvm_xen_guests.py and
> make it clearer in the comment this is the mode we are talking about.
> c.f. the boot_xen.py tests which boot Xen (under TCG emulation) as a
> proper hypervisor.

Ack. I'll change it.

> > +# Copyright © 2021 Red Hat, Inc.
> > +# Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
> > +#
> > +# Author:
> > +#  David Woodhouse <dwmw2@infradead.org>
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2 or
> > +# later.  See the COPYING file in the top-level directory.
> > +import os
> > +
> > +from avocado import skipIf
> > +from avocado_qemu import LinuxTest
> > +
> > +@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
> 
> This just means we will never have CI coverage. In theory when running
> on the GitLab shared runners the test should skip anyway when it can't
> find /dev/kvm and hopefully can run on our custom runners when it can
> see /dev/kvm.
> 

That one was just cargo-culted from the Intel IOMMU test which I
started from. Happy to drop that if it's redundant.
diff mbox series

Patch

diff --git a/tests/avocado/xen_guest.py b/tests/avocado/xen_guest.py
new file mode 100644
index 0000000000..c50b52958f
--- /dev/null
+++ b/tests/avocado/xen_guest.py
@@ -0,0 +1,147 @@ 
+# Xen guest functional tests
+#
+# Copyright © 2021 Red Hat, Inc.
+# Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+#
+# Author:
+#  David Woodhouse <dwmw2@infradead.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+import os
+
+from avocado import skipIf
+from avocado_qemu import LinuxTest
+
+@skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
+class XenGuest(LinuxTest):
+    """
+    :avocado: tags=arch:x86_64
+    :avocado: tags=distro:fedora
+    :avocado: tags=distro_version:34
+    :avocado: tags=machine:q35
+    :avocado: tags=accel:kvm
+    :avocado: tags=xen_guest
+    """
+
+    kernel_path = None
+    initrd_path = None
+    kernel_params = None
+
+    def set_up_boot(self):
+        path = self.download_boot()
+        self.vm.add_args('-drive', 'file=%s,if=none,id=drv0' % path)
+        self.vm.add_args('-device', 'xen-disk,drive=drv0,vdev=xvda')
+
+    def setUp(self):
+        super(XenGuest, self).setUp(None, 'virtio-net-pci')
+
+    def common_vm_setup(self, custom_kernel=None):
+        self.require_accelerator("kvm")
+        self.vm.add_args("-accel", "kvm,xen-version=0x4000a,kernel-irqchip=split")
+        self.vm.add_args("-smp", "4")
+
+        if custom_kernel is None:
+            return
+
+        kernel_url = self.distro.pxeboot_url + 'vmlinuz'
+        initrd_url = self.distro.pxeboot_url + 'initrd.img'
+        self.kernel_path = self.fetch_asset(kernel_url, algorithm='sha256',
+                                            asset_hash=self.distro.kernel_hash)
+        self.initrd_path = self.fetch_asset(initrd_url, algorithm='sha256',
+                                            asset_hash=self.distro.initrd_hash)
+
+    def run_and_check(self):
+        if self.kernel_path:
+            self.vm.add_args('-kernel', self.kernel_path,
+                             '-append', self.kernel_params,
+                             '-initrd', self.initrd_path)
+        self.launch_and_wait()
+        self.ssh_command('cat /proc/cmdline')
+        self.ssh_command('dmesg | grep -e "Grant table initialized"')
+
+    def test_xen_guest(self):
+        """
+        :avocado: tags=xen_guest
+        """
+
+        self.common_vm_setup(True)
+
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks')
+        self.run_and_check()
+        self.ssh_command('grep xen-pirq.*msi /proc/interrupts')
+
+    def test_xen_guest_nomsi(self):
+        """
+        :avocado: tags=xen_guest_nomsi
+        """
+
+        self.common_vm_setup(True)
+
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks pci=nomsi')
+        self.run_and_check()
+        self.ssh_command('grep xen-pirq.* /proc/interrupts')
+
+    def test_xen_guest_noapic_nomsi(self):
+        """
+        :avocado: tags=xen_guest_noapic_nomsi
+        """
+
+        self.common_vm_setup(True)
+
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks noapic pci=nomsi')
+        self.run_and_check()
+        self.ssh_command('grep xen-pirq /proc/interrupts')
+
+    def test_xen_guest_vapic(self):
+        """
+        :avocado: tags=xen_guest_vapic
+        """
+
+        self.common_vm_setup(True)
+        self.vm.add_args('-cpu', 'host,+xen-vapic')
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks')
+        self.run_and_check()
+        self.ssh_command('grep xen-pirq /proc/interrupts')
+        self.ssh_command('grep PCI-MSI /proc/interrupts')
+
+    def test_xen_guest_novector(self):
+        """
+        :avocado: tags=xen_guest_novector
+        """
+
+        self.common_vm_setup(True)
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks' +
+                              ' xen_no_vector_callback')
+        self.run_and_check()
+        self.ssh_command('grep xen-platform-pci /proc/interrupts')
+
+    def test_xen_guest_novector_nomsi(self):
+        """
+        :avocado: tags=xen_guest_novector_nomsi
+        """
+
+        self.common_vm_setup(True)
+
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks pci=nomsi' +
+                              ' xen_no_vector_callback')
+        self.run_and_check()
+        self.ssh_command('grep xen-platform-pci /proc/interrupts')
+
+    def test_xen_guest_novector_noapic(self):
+        """
+        :avocado: tags=xen_guest_novector_noapic
+        """
+
+        self.common_vm_setup(True)
+        self.kernel_params = (self.distro.default_kernel_params +
+                              ' xen_emul_unplug=ide-disks' +
+                              ' xen_no_vector_callback noapic')
+        self.run_and_check()
+        self.ssh_command('grep xen-platform-pci /proc/interrupts')