All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wainer dos Santos Moschetta <wainersm@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Denis Plotnikov" <dplotnikov@virtuozzo.com>,
	qemu-devel@nongnu.org
Cc: Cornelia Huck <cohuck@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Cleber Rosa <crosa@redhat.com>
Subject: Re: [PATCH v2 03/29] python/qemu: Add binutils::binary_get_version()
Date: Mon, 3 Feb 2020 17:17:49 -0200	[thread overview]
Message-ID: <cfec25d9-95c4-18e9-f4e1-d087a7bc5a2e@redhat.com> (raw)
In-Reply-To: <20200129212345.20547-4-philmd@redhat.com>


On 1/29/20 7:23 PM, Philippe Mathieu-Daudé wrote:
> Add a helper to query the version of a QEMU binary.
> We simply send the 'query-version' command over a QMP
> socket.
> Introduce the PythonQemuCoreScripts class to test our
> new helper.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   python/qemu/binutils.py          | 38 ++++++++++++++++++++++++++++++++

I'm not sure about creating the file with that name, it reminds me to 
GNU Binutils rather than the QEMU binary. :)

Perhaps it could be named qemu_bin.py?

Another suggestion is to encapsulate the methods you propose in this 
series in an object. For example:

class QEMUBin:
     def __init__(self, bin_path):
         # Check bin exists.
         self.bin_path = bin_path

     def get_version(self):
         # binutils.binary_get_version() goes here.
         pass

     def get_arch(self):
         # binutils.binary_get_arch() goes here.
         pass

     def list_accel(self):
         # move accel.list_accel() method to here.
         pass

     def get_vm(self, args):
         # Return an QEMUMachine object...
         return QEMUMachine(self.bin_path, *args)

     def get_build_config_host(self):
         # Detect if self.bin_path is in a build directory,
         # attempt to read the host-config.mak and return
         # as hash. Or fail...
         pass


>   tests/acceptance/core_scripts.py | 31 ++++++++++++++++++++++++++
>   2 files changed, 69 insertions(+)
>   create mode 100644 python/qemu/binutils.py
>   create mode 100644 tests/acceptance/core_scripts.py
>
> diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
> new file mode 100644
> index 0000000000..96b200eef4
> --- /dev/null
> +++ b/python/qemu/binutils.py
> @@ -0,0 +1,38 @@
> +"""
> +QEMU binary utility module:
> +
> +The binary utility module provides helpers to query QEMU binary for
> +build-dependent configuration options at runtime.
> +"""
> +#
> +# Copyright (c) 2020 Red Hat, Inc.
> +#
> +# Author:
> +#  Philippe Mathieu-Daudé <philmd@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
> +# See the COPYING file in the top-level directory.
> +#
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +import logging
> +
> +from .machine import QEMUMachine
> +
> +LOG = logging.getLogger(__name__)
> +
> +
> +def binary_get_version(qemu_bin):
> +    '''
> +    Get QEMU binary version
> +
> +    @param qemu_bin (str): path to the QEMU binary

It could check that qemu_bin file exists, otherwise raise an exception 
or return None.

> +    @return binary version (dictionary with major/minor/micro keys)
> +    '''
> +    with QEMUMachine(qemu_bin) as vm:
> +        vm.set_machine('none')
> +        vm.launch()
> +        res = vm.command('query-version')
> +        LOG.info(res)
> +        vm.shutdown()

Don't need this, the vm will be shutdown anyway (see QEMUMachine.__exit__())

Thanks!

- Wainer


> +        return res['qemu']
> diff --git a/tests/acceptance/core_scripts.py b/tests/acceptance/core_scripts.py
> new file mode 100644
> index 0000000000..3f253337cd
> --- /dev/null
> +++ b/tests/acceptance/core_scripts.py
> @@ -0,0 +1,31 @@
> +# Tests covering various python/qemu/ scripts
> +#
> +# Copyright (c) 2020 Red Hat, Inc.
> +#
> +# Author:
> +#  Philippe Mathieu-Daudé <philmd@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
> +# See the COPYING file in the top-level directory.
> +#
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +import sys
> +import os
> +import logging
> +
> +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
> +from avocado_qemu import Test
> +from qemu.binutils import binary_get_version
> +
> +
> +class PythonQemuCoreScripts(Test):
> +
> +    def test_get_version(self):
> +        logger = logging.getLogger('core')
> +        version = binary_get_version(self.qemu_bin)
> +        logger.debug('version: {}'.format(version))
> +        # QMP 'query-version' introduced with QEMU v0.14
> +        self.assertGreaterEqual(version['major'], 0)
> +        if version['major'] == 0:
> +            self.assertGreaterEqual(version['minor'], 14)



  reply	other threads:[~2020-02-03 19:19 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 21:23 [PATCH v2 00/29] tests/acceptance/virtio_seg_max_adjust: Restrict it to Linux/X86 Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 01/29] hw/core: Allow setting 'virtio-blk-device.scsi' property on OSX host Philippe Mathieu-Daudé
2020-01-30 12:20   ` Cornelia Huck
2020-01-30 13:23     ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 02/29] accel/accel: Make TYPE_ACCEL abstract Philippe Mathieu-Daudé
2020-01-29 21:31   ` Philippe Mathieu-Daudé
2020-01-30 12:22   ` Cornelia Huck
2020-01-29 21:23 ` [PATCH v2 03/29] python/qemu: Add binutils::binary_get_version() Philippe Mathieu-Daudé
2020-02-03 19:17   ` Wainer dos Santos Moschetta [this message]
2020-02-06 16:39     ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 04/29] tests/acceptance: Use 'version-min' tag to verify QEMU binary version Philippe Mathieu-Daudé
2020-01-30 12:26   ` Cornelia Huck
2020-01-30 13:28     ` Philippe Mathieu-Daudé
2020-01-30 17:08       ` Cornelia Huck
2020-01-30 17:18         ` Philippe Mathieu-Daudé
2020-01-30 20:40           ` Eduardo Habkost
2020-01-29 21:23 ` [PATCH v2 05/29] tests/acceptance: Restrict X86CPUModelAliases test to QEMU >= 4.1 Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 06/29] python/qemu: Add binutils::binary_get_arch() Philippe Mathieu-Daudé
2020-01-31  9:49   ` Cornelia Huck
2020-01-29 21:23 ` [PATCH v2 07/29] tests/acceptance: Use the 'arch' tag to verify QEMU binary target Philippe Mathieu-Daudé
2020-01-31  9:51   ` Cornelia Huck
2020-01-29 21:23 ` [PATCH v2 08/29] python/qemu: Add binutils::binary_get_machines() Philippe Mathieu-Daudé
2020-01-31  9:53   ` Cornelia Huck
2020-01-29 21:23 ` [PATCH v2 09/29] tests/acceptance: Use 'machine' tag to check if available in QEMU binary Philippe Mathieu-Daudé
2020-01-31 10:00   ` Cornelia Huck
2020-02-06 18:17   ` Liam Merwick
2020-02-26 17:34     ` Liam Merwick
2020-01-29 21:23 ` [PATCH v2 10/29] python/qemu: Add binutils::binary_get_qom_implementations() Philippe Mathieu-Daudé
2020-02-07 14:28   ` Liam Merwick
2020-02-07 14:33     ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 11/29] python/qemu: Add binutils::binary_get_accels() Philippe Mathieu-Daudé
2020-02-07 14:35   ` Liam Merwick
2020-01-29 21:23 ` [PATCH v2 12/29] python/qemu/accel: Use binutils::binary_get_accels() Philippe Mathieu-Daudé
2020-02-07 14:37   ` Liam Merwick
2020-01-29 21:23 ` [PATCH v2 13/29] python/qemu: Add binutils::binary_get_devices() Philippe Mathieu-Daudé
2020-02-07 15:02   ` Liam Merwick
2020-01-29 21:23 ` [RFC PATCH v2 14/29] tests/acceptance: Use 'device' tags to check availability in QEMU binary Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 15/29] tests: rename virtio_seg_max_adjust to virtio_check_params Philippe Mathieu-Daudé
2020-01-30 12:32   ` Cornelia Huck
2020-01-31  0:05   ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 16/29] tests/acceptance/virtio_check_params: Only remove listed machines Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 17/29] tests/acceptance/virtio_check_params: Improve exception logging Philippe Mathieu-Daudé
2020-02-06 19:54   ` Eduardo Habkost
2020-02-06 20:36     ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 18/29] tests/acceptance/virtio_check_params: List machine being tested Philippe Mathieu-Daudé
2020-01-30 12:35   ` Cornelia Huck
2020-01-31  0:08   ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 19/29] tests/acceptance/virtio_check_params: Only test Xen as superuser Philippe Mathieu-Daudé
2020-01-30 12:37   ` Cornelia Huck
2020-01-30 13:29     ` Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 20/29] tests/acceptance/virtio_check_params: Skip test if arch is not supported Philippe Mathieu-Daudé
2020-01-29 21:23 ` [RFC PATCH v2 21/29] tests/acceptance/virtio_check_params: Kludge to skip tests on MIPS Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 22/29] tests/acceptance/virtio_check_params: Support the s390x architecture Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 23/29] tests/acceptance/virtio_check_params: Support the ppc architecture Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 24/29] tests/acceptance/virtio_check_params: Default to -nodefaults Philippe Mathieu-Daudé
2020-02-06 16:01   ` Thomas Huth
2020-01-29 21:23 ` [PATCH v2 25/29] tests/acceptance/virtio_check_params: Require a virtio-scsi-pci device Philippe Mathieu-Daudé
2020-01-29 21:23 ` [PATCH v2 26/29] tests/acceptance/boot_linux_console: Do not use VGA on Clipper machine Philippe Mathieu-Daudé
2020-02-06 15:35   ` Thomas Huth
2020-01-29 21:23 ` [PATCH v2 27/29] tests/acceptance/migration: Default to -nodefaults Philippe Mathieu-Daudé
2020-02-06 16:03   ` Thomas Huth
2020-02-07 11:57   ` Wainer dos Santos Moschetta
2020-01-29 21:23 ` [PATCH v2 28/29] tests/acceptance/version: " Philippe Mathieu-Daudé
2020-02-06 15:34   ` Thomas Huth
2020-02-07 12:05   ` Wainer dos Santos Moschetta
2020-01-29 21:23 ` [PATCH v2 29/29] MAINTAINERS: Add Acceptance tests reviewers Philippe Mathieu-Daudé
2020-01-30  8:41   ` Thomas Huth
2020-01-31 13:46     ` Wainer dos Santos Moschetta
2020-01-29 21:28 ` [PATCH v2 00/29] tests/acceptance/virtio_seg_max_adjust: Restrict it to Linux/X86 Philippe Mathieu-Daudé
2020-02-06 16:48 ` Philippe Mathieu-Daudé
2020-06-04  8:19 ` python/qemu: Refactor QemuBinaryInfo 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=cfec25d9-95c4-18e9-f4e1-d087a7bc5a2e@redhat.com \
    --to=wainersm@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=crosa@redhat.com \
    --cc=dplotnikov@virtuozzo.com \
    --cc=ehabkost@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.