qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Cleber Rosa <crosa@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Caio Carrara" <ccarrara@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <pmathieu@redhat.com>,
	"Laszlo Ersek" <lersek@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>, "Fam Zheng" <famz@redhat.com>
Subject: [Qemu-devel] [PATCH 4/7] scripts/qemu.py: set predefined machine type based on arch
Date: Thu,  4 Oct 2018 11:14:26 -0400	[thread overview]
Message-ID: <20181004151429.7232-5-crosa@redhat.com> (raw)
In-Reply-To: <20181004151429.7232-1-crosa@redhat.com>

Some targets require a machine type to be set, as there's no default
(aarch64 is one example).  To give a consistent interface to users of
this API, this changes set_machine() so that a predefined default can
be used, if one is not given.  The approach used is exactly the same
with the console device type.

Also, even when there's a default machine type, for some purposes,
testing included, it's better if outside code is explicit about the
machine type, instead of relying on whatever is set internally.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 scripts/qemu.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/scripts/qemu.py b/scripts/qemu.py
index d9e24a0c1a..fca9b76990 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -36,6 +36,15 @@ CONSOLE_DEV_TYPES = {
     r'^s390-ccw-virtio.*': 'sclpconsole',
     }
 
+#: Maps archictures to the preferred machine type
+MACHINE_TYPES = {
+    r'^aarch64$': 'virt',
+    r'^ppc$': 'g3beige',
+    r'^ppc64$': 'pseries',
+    r'^s390x$': 's390-ccw-virtio',
+    r'^x86_64$': 'q35',
+    }
+
 
 class QEMUMachineError(Exception):
     """
@@ -413,13 +422,24 @@ class QEMUMachine(object):
         """
         self._arch = arch
 
-    def set_machine(self, machine_type):
+    def set_machine(self, machine_type=None):
         '''
         Sets the machine type
 
         If set, the machine type will be added to the base arguments
         of the resulting QEMU command line.
         '''
+        if machine_type is None:
+            if self._arch is None:
+                raise QEMUMachineError("Can not set a default machine type: "
+                                       "QEMU instance without a defined arch")
+            for regex, machine in MACHINE_TYPES.items():
+                if re.match(regex, self._arch):
+                    machine_type = machine
+                    break
+            if machine_type is None:
+                raise QEMUMachineError("Can not set a machine type: no "
+                                       "matching machine type definition")
         self._machine = machine_type
 
     def set_console(self, device_type=None):
-- 
2.17.1

  parent reply	other threads:[~2018-10-04 15:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 15:14 [Qemu-devel] [PATCH 0/7] Acceptance Tests: basic architecture support Cleber Rosa
2018-10-04 15:14 ` [Qemu-devel] [PATCH 1/7] Acceptance Tests: improve docstring on pick_default_qemu_bin() Cleber Rosa
2018-10-05 15:24   ` Philippe Mathieu-Daudé
2018-10-04 15:14 ` [Qemu-devel] [PATCH 2/7] Acceptance Tests: introduce arch parameter and attribute Cleber Rosa
2018-10-04 23:56   ` Murilo Opsfelder Araujo
2018-10-10 13:16     ` Cleber Rosa
2018-10-04 15:14 ` [Qemu-devel] [PATCH 3/7] scripts/qemu.py: add method and private attribute for arch Cleber Rosa
2018-10-05 15:28   ` Philippe Mathieu-Daudé
2018-10-04 15:14 ` Cleber Rosa [this message]
2018-10-04 15:14 ` [Qemu-devel] [PATCH 5/7] Acceptance Tests: set machine type Cleber Rosa
2018-10-05 15:42   ` Philippe Mathieu-Daudé
2018-10-09 23:08     ` Cleber Rosa
2018-10-04 15:14 ` [Qemu-devel] [PATCH 6/7] Acceptance Tests: add variants definition for architectures Cleber Rosa
2018-10-04 16:48   ` Laszlo Ersek
2018-10-05 16:24   ` Philippe Mathieu-Daudé
2018-10-05 16:32     ` Eric Blake
2018-10-05 17:07       ` Cleber Rosa
2018-10-05 17:30         ` Philippe Mathieu-Daudé
2018-10-05 17:34           ` Cleber Rosa
2018-10-04 15:14 ` [Qemu-devel] [PATCH 7/7] Acceptance Tests: change the handling of tests for specific archs Cleber Rosa
2018-10-04 15:42   ` Philippe Mathieu-Daudé
2018-10-04 15:48     ` Cleber Rosa

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=20181004151429.7232-5-crosa@redhat.com \
    --to=crosa@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=ccarrara@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=famz@redhat.com \
    --cc=lersek@redhat.com \
    --cc=pmathieu@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).