[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 03/29] python/qemu: Add binutils::binary_get_version()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 03/29] python/qemu: Add binutils::binary_get_version() |
Date: |
Wed, 29 Jan 2020 22:23:19 +0100 |
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é <address@hidden>
---
python/qemu/binutils.py | 38 ++++++++++++++++++++++++++++++++
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é <address@hidden>
+#
+# 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
+ @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()
+ 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é <address@hidden>
+#
+# 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)
--
2.21.1
[PATCH v2 05/29] tests/acceptance: Restrict X86CPUModelAliases test to QEMU >= 4.1, Philippe Mathieu-Daudé, 2020/01/29
[PATCH v2 06/29] python/qemu: Add binutils::binary_get_arch(), Philippe Mathieu-Daudé, 2020/01/29
[PATCH v2 07/29] tests/acceptance: Use the 'arch' tag to verify QEMU binary target, Philippe Mathieu-Daudé, 2020/01/29