diff mbox series

[v2,06/29] python/qemu: Add binutils::binary_get_arch()

Message ID 20200129212345.20547-7-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series tests/acceptance/virtio_seg_max_adjust: Restrict it to Linux/X86 | expand

Commit Message

Philippe Mathieu-Daudé Jan. 29, 2020, 9:23 p.m. UTC
Add a helper to query the architecture of a QEMU binary.
We simply send the 'query-target' command over a QMP socket.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 python/qemu/binutils.py          | 15 +++++++++++++++
 tests/acceptance/core_scripts.py | 11 +++++++++++
 2 files changed, 26 insertions(+)

Comments

Cornelia Huck Jan. 31, 2020, 9:49 a.m. UTC | #1
On Wed, 29 Jan 2020 22:23:22 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> Add a helper to query the architecture of a QEMU binary.
> We simply send the 'query-target' command over a QMP socket.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  python/qemu/binutils.py          | 15 +++++++++++++++
>  tests/acceptance/core_scripts.py | 11 +++++++++++
>  2 files changed, 26 insertions(+)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff mbox series

Patch

diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
index 96b200eef4..905d393ba5 100644
--- a/python/qemu/binutils.py
+++ b/python/qemu/binutils.py
@@ -36,3 +36,18 @@  def binary_get_version(qemu_bin):
         LOG.info(res)
         vm.shutdown()
         return res['qemu']
+
+def binary_get_arch(qemu_bin):
+    '''
+    Get target architecture for a QEMU binary
+
+    @param qemu_bin (str): path to the QEMU binary
+    @return binary target architecture
+    '''
+    with QEMUMachine(qemu_bin) as vm:
+        vm.set_machine('none')
+        vm.launch()
+        res = vm.command('query-target')
+        LOG.info(res)
+        vm.shutdown()
+        return res['arch']
diff --git a/tests/acceptance/core_scripts.py b/tests/acceptance/core_scripts.py
index 3f253337cd..93dd822368 100644
--- a/tests/acceptance/core_scripts.py
+++ b/tests/acceptance/core_scripts.py
@@ -16,6 +16,7 @@  import logging
 
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
 from avocado_qemu import Test
+from qemu.binutils import binary_get_arch
 from qemu.binutils import binary_get_version
 
 
@@ -29,3 +30,13 @@  class PythonQemuCoreScripts(Test):
         self.assertGreaterEqual(version['major'], 0)
         if version['major'] == 0:
             self.assertGreaterEqual(version['minor'], 14)
+
+    def test_get_arch_x86(self):
+        """
+        :avocado: tags=arch:i386
+        :avocado: tags=arch:x86_64
+        """
+        logger = logging.getLogger('core')
+        a = binary_get_arch(self.qemu_bin)
+        logger.debug('arch: {}'.format(a))
+        self.assertIn(a, ['i386', 'x86_64'])