From: Cleber Rosa <crosa@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Beraldo Leal" <bleal@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Willian Rampazzo" <willianr@redhat.com>,
"Willian Rampazzo" <wrampazz@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>, "John Snow" <jsnow@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>
Subject: [PULL 7/9] Acceptance Tests: introduce method for requiring an accelerator
Date: Mon, 15 Feb 2021 23:57:03 -0500 [thread overview]
Message-ID: <20210216045705.9590-8-crosa@redhat.com> (raw)
In-Reply-To: <20210216045705.9590-1-crosa@redhat.com>
Some tests explicitly require a QEMU accelerator to be available.
Given that this depends on some runtime aspects not known before
the test is started, such as the currently set QEMU binary, it's
left to be checked also at runtime.
Signed-off-by: Cleber Rosa <crosa@redhat.com>
Message-Id: <20210203172357.1422425-17-crosa@redhat.com>
Reviewed-by: Beraldo Leal <bleal@redhat.com>
Reviewed-by: Willian Rampazzo <willianr@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
tests/acceptance/avocado_qemu/__init__.py | 24 ++++++++++++++++
tests/acceptance/boot_linux.py | 34 ++++++-----------------
tests/acceptance/virtiofs_submounts.py | 5 +---
3 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index b06692a59df..687c5dc0cf6 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -39,6 +39,8 @@
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):
@@ -162,6 +164,28 @@ def _get_unique_tag_val(self, tag_name):
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 = {}
diff --git a/tests/acceptance/boot_linux.py b/tests/acceptance/boot_linux.py
index 14e89d020d1..0d178038a09 100644
--- a/tests/acceptance/boot_linux.py
+++ b/tests/acceptance/boot_linux.py
@@ -12,15 +12,8 @@
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):
"""
@@ -34,8 +27,7 @@ def test_pc_i440fx_tcg(self):
: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()
@@ -44,8 +36,7 @@ def test_pc_i440fx_kvm(self):
: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()
@@ -54,8 +45,7 @@ def test_pc_q35_tcg(self):
: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()
@@ -64,8 +54,7 @@ def test_pc_q35_kvm(self):
: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()
@@ -91,8 +80,7 @@ def test_virt_tcg(self):
: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")
@@ -105,8 +93,7 @@ def test_virt_kvm_gicv2(self):
: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")
@@ -119,8 +106,7 @@ def test_virt_kvm_gicv3(self):
: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")
@@ -140,8 +126,7 @@ def test_pseries_tcg(self):
: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()
@@ -159,7 +144,6 @@ def test_s390_ccw_virtio_tcg(self):
: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()
diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
index fc2b4fd6669..46fa65392a1 100644
--- a/tests/acceptance/virtiofs_submounts.py
+++ b/tests/acceptance/virtiofs_submounts.py
@@ -9,8 +9,6 @@
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,
@@ -260,8 +258,7 @@ def setUp(self):
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):
--
2.26.2
next prev parent reply other threads:[~2021-02-16 5:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-16 4:56 [PULL 0/9] Acceptance Tests and Python libs patches for 2021-02-15 Cleber Rosa
2021-02-16 4:56 ` [PULL 1/9] Acceptance Tests: bump Avocado version requirement to 85.0 Cleber Rosa
2021-02-16 4:56 ` [PULL 2/9] virtiofs_submounts.py test: Note on vmlinuz param Cleber Rosa
2021-02-16 4:56 ` [PULL 3/9] Python: close the log file kept by QEMUMachine before reading it Cleber Rosa
2021-02-16 4:57 ` [PULL 4/9] tests/acceptance/virtio-gpu.py: preserve virtio-user-gpu log Cleber Rosa
2021-02-16 4:57 ` [PULL 5/9] maint: Tell git that *.py files should use python diff hunks Cleber Rosa
2021-02-16 4:57 ` [PULL 6/9] Acceptance Tests: introduce LinuxTest base class Cleber Rosa
2021-02-16 4:57 ` Cleber Rosa [this message]
2021-02-16 4:57 ` [PULL 8/9] Acceptance Tests: fix population of public key in cloudinit image Cleber Rosa
2021-02-16 4:57 ` [PULL 9/9] Acceptance Tests: set up existing ssh keys by default Cleber Rosa
2021-02-16 16:46 ` [PULL 0/9] Acceptance Tests and Python libs patches for 2021-02-15 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210216045705.9590-8-crosa@redhat.com \
--to=crosa@redhat.com \
--cc=bleal@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wainersm@redhat.com \
--cc=willianr@redhat.com \
--cc=wrampazz@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).