qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wainer dos Santos Moschetta <wainersm@redhat.com>
To: qemu-devel@nongnu.org
Cc: philmd@redhat.com, thuth@redhat.com, alex.bennee@linaro.org,
	ehabkost@redhat.com, crosa@redhat.com
Subject: [PATCH v3 1/4] tests/acceptance: avocado_qemu: Introduce the 'accel' test parameter
Date: Tue, 21 Jan 2020 22:27:50 -0300	[thread overview]
Message-ID: <20200122012753.9846-2-wainersm@redhat.com> (raw)
In-Reply-To: <20200122012753.9846-1-wainersm@redhat.com>

The test case may need to boot the VM with an accelerator that
isn't actually enabled on the QEMU binary and/or present in the host. In
this case the test behavior is undefined, and the best course of
action is to skip its execution.

This change introduced the 'accel' parameter (and the handler of
tag with same name) used to indicate the test case requires a
given accelerator available. It was implemented a mechanism to
skip the test case if the accelerator is not available. Moreover,
 the QEMU -accel argument is set automatically to any VM
launched if the parameter is present.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 docs/devel/testing.rst                    | 16 ++++++++++++++++
 tests/acceptance/avocado_qemu/__init__.py | 23 +++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index ab5be0c729..d17d0e90aa 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -759,6 +759,17 @@ name.  If one is not given explicitly, it will either be set to
 ``None``, or, if the test is tagged with one (and only one)
 ``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
 
+accel
+~~~~~
+The accelerator that will be set to all QEMUMachine instances created
+by the test.
+
+The ``accel`` attribute will be set to the test parameter of the same
+name.  If one is not given explicitly, it will either be set to
+``None``, or, if the test is tagged with one (and only one)
+``:avocado: tags=accel:VALUE`` tag, it will be set to ``VALUE``. Currently
+``VALUE`` should be either ``kvm`` or ``tcg``.
+
 qemu_bin
 ~~~~~~~~
 
@@ -800,6 +811,11 @@ machine
 The machine type that will be set to all QEMUMachine instances created
 by the test.
 
+accel
+~~~~~
+The accelerator that will be set to all QEMUMachine instances created
+by the test. In case the accelerator is not available (both QEMU
+binary and the host system are checked) then the test is canceled.
 
 qemu_bin
 ~~~~~~~~
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 6618ea67c1..c83a75ccbc 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -20,6 +20,7 @@ SRC_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..')
 sys.path.append(os.path.join(SRC_ROOT_DIR, 'python'))
 
 from qemu.machine import QEMUMachine
+from qemu.accel import kvm_available, tcg_available
 
 def is_readable_executable_file(path):
     return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
@@ -111,6 +112,8 @@ class Test(avocado.Test):
 
     def setUp(self):
         self._vms = {}
+        # VM argumments that are mapped from parameters
+        self._param_to_vm_args = []
 
         self.arch = self.params.get('arch',
                                     default=self._get_unique_tag_val('arch'))
@@ -124,10 +127,30 @@ class Test(avocado.Test):
         if self.qemu_bin is None:
             self.cancel("No QEMU binary defined or found in the source tree")
 
+        self.accel = self.params.get('accel',
+                                     default=self._get_unique_tag_val('accel'))
+        if self.accel:
+            avail = False
+            if self.accel == 'kvm':
+                if kvm_available(self.arch, self.qemu_bin):
+                    avail = True
+            elif self.accel == 'tcg':
+                if tcg_available(self.qemu_bin):
+                    avail = True
+            else:
+                self.cancel("Unknown accelerator: %s" % self.accel)
+
+            if avail:
+                self._param_to_vm_args.extend(['-accel', self.accel])
+            else:
+                self.cancel("%s is not available" % self.accel)
+
     def _new_vm(self, *args):
         vm = QEMUMachine(self.qemu_bin, sock_dir=tempfile.mkdtemp())
         if args:
             vm.add_args(*args)
+        if self._param_to_vm_args:
+            vm.add_args(*self._param_to_vm_args)
         return vm
 
     @property
-- 
2.23.0



  reply	other threads:[~2020-01-22  1:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-22  1:27 [PATCH v3 0/4] Acceptance tests: boot Linux with KVM test Wainer dos Santos Moschetta
2020-01-22  1:27 ` Wainer dos Santos Moschetta [this message]
2020-01-24  9:36   ` [PATCH v3 1/4] tests/acceptance: avocado_qemu: Introduce the 'accel' test parameter Philippe Mathieu-Daudé
2020-01-27 19:28     ` Wainer dos Santos Moschetta
2020-01-30 22:51       ` Philippe Mathieu-Daudé
2020-02-04 21:30         ` Wainer dos Santos Moschetta
2020-01-22  1:27 ` [PATCH v3 2/4] tests/acceptance: boot_linux_console: Add boot Linux with kvm tests Wainer dos Santos Moschetta
2020-01-22  9:02   ` Andrew Jones
2020-01-23 21:47     ` Wainer dos Santos Moschetta
2020-01-24  7:54       ` Andrew Jones
2020-01-24 15:45   ` Philippe Mathieu-Daudé
2020-01-24 15:47     ` Thomas Huth
2020-02-04 21:25     ` Wainer dos Santos Moschetta
2020-01-22  1:27 ` [PATCH v3 3/4] tests/acceptance: avocado_qemu: Refactor the handler of 'machine' parameter Wainer dos Santos Moschetta
2020-01-30 23:23   ` Philippe Mathieu-Daudé
2020-01-22  1:27 ` [PATCH v3 4/4] travis.yml: Enable acceptance KVM tests Wainer dos Santos Moschetta
2020-01-22  9:11   ` Thomas Huth
2020-01-22  9:22   ` Thomas Huth
2020-01-24 21:15     ` Wainer dos Santos Moschetta
2020-01-27  9:34       ` Thomas Huth
2020-01-24  9:38   ` Philippe Mathieu-Daudé
2020-01-24  9:44     ` Thomas Huth
2020-01-24  9:54       ` Philippe Mathieu-Daudé
2020-01-24 19:55         ` Wainer dos Santos Moschetta
2020-01-27  9:51           ` Philippe Mathieu-Daudé

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=20200122012753.9846-2-wainersm@redhat.com \
    --to=wainersm@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@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).