sys.path.append(os.path.join(SOURCE_DIR, 'python'))
+from qemu.accel import kvm_available
+from qemu.accel import tcg_available
from qemu.machine import QEMUMachine
def is_readable_executable_file(path):
return vals.pop()
return None
+ def require_accelerator(self, accelerator):
+ """
+ Requires an accelerator to be available for the test to continue
+
+ It takes into account the currently set qemu binary.
+
+ If the check fails, the test is canceled. If the check itself
+ for the given accelerator is not available, the test is also
+ canceled.
+
+ :param accelerator: name of the accelerator, such as "kvm" or "tcg"
+ :type accelerator: str
+ """
+ checker = {'tcg': tcg_available,
+ 'kvm': kvm_available}.get(accelerator)
+ if checker is None:
+ self.cancel("Don't know how to check for the presence "
+ "of accelerator %s" % accelerator)
+ if not checker(qemu_bin=self.qemu_bin):
+ self.cancel("%s accelerator does not seem to be "
+ "available" % accelerator)
+
def setUp(self):
self._vms = {}
from avocado_qemu import LinuxTest, BUILD_DIR
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
-
from avocado import skipIf
-ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"
-KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM"
-TCG_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "TCG"
-
class BootLinuxX8664(LinuxTest):
"""
:avocado: tags=machine:pc
:avocado: tags=accel:tcg
"""
- if not tcg_available(self.qemu_bin):
- self.cancel(TCG_NOT_AVAILABLE)
+ self.require_accelerator("tcg")
self.vm.add_args("-accel", "tcg")
self.launch_and_wait()
:avocado: tags=machine:pc
:avocado: tags=accel:kvm
"""
- if not kvm_available(self.arch, self.qemu_bin):
- self.cancel(KVM_NOT_AVAILABLE)
+ self.require_accelerator("kvm")
self.vm.add_args("-accel", "kvm")
self.launch_and_wait()
:avocado: tags=machine:q35
:avocado: tags=accel:tcg
"""
- if not tcg_available(self.qemu_bin):
- self.cancel(TCG_NOT_AVAILABLE)
+ self.require_accelerator("tcg")
self.vm.add_args("-accel", "tcg")
self.launch_and_wait()
:avocado: tags=machine:q35
:avocado: tags=accel:kvm
"""
- if not kvm_available(self.arch, self.qemu_bin):
- self.cancel(KVM_NOT_AVAILABLE)
+ self.require_accelerator("kvm")
self.vm.add_args("-accel", "kvm")
self.launch_and_wait()
:avocado: tags=accel:tcg
:avocado: tags=cpu:max
"""
- if not tcg_available(self.qemu_bin):
- self.cancel(TCG_NOT_AVAILABLE)
+ self.require_accelerator("tcg")
self.vm.add_args("-accel", "tcg")
self.vm.add_args("-cpu", "max")
self.vm.add_args("-machine", "virt,gic-version=2")
:avocado: tags=cpu:host
:avocado: tags=device:gicv2
"""
- if not kvm_available(self.arch, self.qemu_bin):
- self.cancel(KVM_NOT_AVAILABLE)
+ self.require_accelerator("kvm")
self.vm.add_args("-accel", "kvm")
self.vm.add_args("-cpu", "host")
self.vm.add_args("-machine", "virt,gic-version=2")
:avocado: tags=cpu:host
:avocado: tags=device:gicv3
"""
- if not kvm_available(self.arch, self.qemu_bin):
- self.cancel(KVM_NOT_AVAILABLE)
+ self.require_accelerator("kvm")
self.vm.add_args("-accel", "kvm")
self.vm.add_args("-cpu", "host")
self.vm.add_args("-machine", "virt,gic-version=3")
:avocado: tags=machine:pseries
:avocado: tags=accel:tcg
"""
- if not tcg_available(self.qemu_bin):
- self.cancel(TCG_NOT_AVAILABLE)
+ self.require_accelerator("tcg")
self.vm.add_args("-accel", "tcg")
self.launch_and_wait()
:avocado: tags=machine:s390-ccw-virtio
:avocado: tags=accel:tcg
"""
- if not tcg_available(self.qemu_bin):
- self.cancel(TCG_NOT_AVAILABLE)
+ self.require_accelerator("tcg")
self.vm.add_args("-accel", "tcg")
self.launch_and_wait()
from avocado_qemu import wait_for_console_pattern
from avocado.utils import ssh
-from qemu.accel import kvm_available
-
def run_cmd(args):
subp = subprocess.Popen(args,
self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
'-device', 'virtio-net,netdev=vnet')
- if not kvm_available(self.arch, self.qemu_bin):
- self.cancel(KVM_NOT_AVAILABLE)
+ self.require_accelerator("kvm")
self.vm.add_args('-accel', 'kvm')
def tearDown(self):