xref: /openbmc/qemu/tests/avocado/smmu.py (revision b447378e)
1# SMMUv3 Functional tests
2#
3# Copyright (c) 2021 Red Hat, Inc.
4#
5# Author:
6#  Eric Auger <eric.auger@redhat.com>
7#
8# This work is licensed under the terms of the GNU GPL, version 2 or
9# later.  See the COPYING file in the top-level directory.
10import os
11
12from avocado import skipUnless
13from avocado_qemu import LinuxTest, BUILD_DIR
14
15@skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
16
17class SMMU(LinuxTest):
18    """
19    :avocado: tags=accel:kvm
20    :avocado: tags=cpu:host
21    :avocado: tags=arch:aarch64
22    :avocado: tags=machine:virt
23    :avocado: tags=distro:fedora
24    :avocado: tags=smmu
25    :avocado: tags=flaky
26    """
27
28    IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on'
29    kernel_path = None
30    initrd_path = None
31    kernel_params = None
32
33    def set_up_boot(self):
34        path = self.download_boot()
35        self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,scsi=off,' +
36                         'drive=drv0,id=virtio-disk0,bootindex=1,'
37                         'werror=stop,rerror=stop' + self.IOMMU_ADDON)
38        self.vm.add_args('-drive',
39                         'file=%s,if=none,cache=writethrough,id=drv0' % path)
40
41    def setUp(self):
42        super(SMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON)
43
44    def common_vm_setup(self, custom_kernel=False):
45        self.require_accelerator("kvm")
46        self.vm.add_args("-accel", "kvm")
47        self.vm.add_args("-cpu", "host")
48        self.vm.add_args("-machine", "iommu=smmuv3")
49        self.vm.add_args("-d", "guest_errors")
50        self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
51                         'edk2-aarch64-code.fd'))
52        self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
53        self.vm.add_args('-object',
54                         'rng-random,id=rng0,filename=/dev/urandom')
55
56        if custom_kernel is False:
57            return
58
59        kernel_url = self.distro.pxeboot_url + 'vmlinuz'
60        initrd_url = self.distro.pxeboot_url + 'initrd.img'
61        self.kernel_path = self.fetch_asset(kernel_url)
62        self.initrd_path = self.fetch_asset(initrd_url)
63
64    def run_and_check(self):
65        if self.kernel_path:
66            self.vm.add_args('-kernel', self.kernel_path,
67                             '-append', self.kernel_params,
68                             '-initrd', self.initrd_path)
69        self.launch_and_wait()
70        self.ssh_command('cat /proc/cmdline')
71        self.ssh_command('dnf -y install numactl-devel')
72
73
74    # 5.3 kernel without RIL #
75
76    def test_smmu_noril(self):
77        """
78        :avocado: tags=smmu_noril
79        :avocado: tags=smmu_noril_tests
80        :avocado: tags=distro_version:31
81        """
82        self.common_vm_setup()
83        self.run_and_check()
84
85    def test_smmu_noril_passthrough(self):
86        """
87        :avocado: tags=smmu_noril_passthrough
88        :avocado: tags=smmu_noril_tests
89        :avocado: tags=distro_version:31
90        """
91        self.common_vm_setup(True)
92        self.kernel_params = (self.distro.default_kernel_params +
93                              ' iommu.passthrough=on')
94        self.run_and_check()
95
96    def test_smmu_noril_nostrict(self):
97        """
98        :avocado: tags=smmu_noril_nostrict
99        :avocado: tags=smmu_noril_tests
100        :avocado: tags=distro_version:31
101        """
102        self.common_vm_setup(True)
103        self.kernel_params = (self.distro.default_kernel_params +
104                              ' iommu.strict=0')
105        self.run_and_check()
106
107    # 5.8 kernel featuring range invalidation
108    # >= v5.7 kernel
109
110    def test_smmu_ril(self):
111        """
112        :avocado: tags=smmu_ril
113        :avocado: tags=smmu_ril_tests
114        :avocado: tags=distro_version:33
115        """
116        self.common_vm_setup()
117        self.run_and_check()
118
119    def test_smmu_ril_passthrough(self):
120        """
121        :avocado: tags=smmu_ril_passthrough
122        :avocado: tags=smmu_ril_tests
123        :avocado: tags=distro_version:33
124        """
125        self.common_vm_setup(True)
126        self.kernel_params = (self.distro.default_kernel_params +
127                              ' iommu.passthrough=on')
128        self.run_and_check()
129
130    def test_smmu_ril_nostrict(self):
131        """
132        :avocado: tags=smmu_ril_nostrict
133        :avocado: tags=smmu_ril_tests
134        :avocado: tags=distro_version:33
135        """
136        self.common_vm_setup(True)
137        self.kernel_params = (self.distro.default_kernel_params +
138                              ' iommu.strict=0')
139        self.run_and_check()
140