diff mbox series

[v2,12/29] python/qemu/accel: Use binutils::binary_get_accels()

Message ID 20200129212345.20547-13-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
Instead of parsing the process help output, use the
binary_get_accels() helper which queries the list of
accelerators over a QMP socket.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 python/qemu/accel.py | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

Comments

Liam Merwick Feb. 7, 2020, 2:37 p.m. UTC | #1
On 29/01/2020 21:23, Philippe Mathieu-Daudé wrote:
> Instead of parsing the process help output, use the
> binary_get_accels() helper which queries the list of
> accelerators over a QMP socket.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Reviewed-by: Liam Merwick <liam.merwick@oracle.com>


> ---
>   python/qemu/accel.py | 26 ++++----------------------
>   1 file changed, 4 insertions(+), 22 deletions(-)
> 
> diff --git a/python/qemu/accel.py b/python/qemu/accel.py
> index 0b38ddf0ab..cde51ae159 100644
> --- a/python/qemu/accel.py
> +++ b/python/qemu/accel.py
> @@ -16,7 +16,8 @@ accelerators.
>   
>   import logging
>   import os
> -import subprocess
> +
> +from .binutils import binary_get_accels
>   
>   LOG = logging.getLogger(__name__)
>   
> @@ -27,25 +28,6 @@ ADDITIONAL_ARCHES = {
>       "aarch64" : "armhf"
>   }
>   
> -def list_accel(qemu_bin):
> -    """
> -    List accelerators enabled in the QEMU binary.
> -
> -    @param qemu_bin (str): path to the QEMU binary.
> -    @raise Exception: if failed to run `qemu -accel help`
> -    @return a list of accelerator names.
> -    """
> -    if not qemu_bin:
> -        return []
> -    try:
> -        out = subprocess.check_output([qemu_bin, '-accel', 'help'],
> -                                      universal_newlines=True)
> -    except:
> -        LOG.debug("Failed to get the list of accelerators in %s", qemu_bin)
> -        raise
> -    # Skip the first line which is the header.
> -    return [acc.strip() for acc in out.splitlines()[1:]]
> -
>   def kvm_available(target_arch=None, qemu_bin=None):
>       """
>       Check if KVM is available using the following heuristic:
> @@ -64,7 +46,7 @@ def kvm_available(target_arch=None, qemu_bin=None):
>           if target_arch != host_arch:
>               if target_arch != ADDITIONAL_ARCHES.get(host_arch):
>                   return False
> -    if qemu_bin and "kvm" not in list_accel(qemu_bin):
> +    if qemu_bin and "kvm" not in binary_get_accels(qemu_bin):
>           return False
>       return True
>   
> @@ -74,4 +56,4 @@ def tcg_available(qemu_bin):
>   
>       @param qemu_bin (str): path to the QEMU binary
>       """
> -    return 'tcg' in list_accel(qemu_bin)
> +    return 'tcg' in binary_get_accels(qemu_bin)
>
diff mbox series

Patch

diff --git a/python/qemu/accel.py b/python/qemu/accel.py
index 0b38ddf0ab..cde51ae159 100644
--- a/python/qemu/accel.py
+++ b/python/qemu/accel.py
@@ -16,7 +16,8 @@  accelerators.
 
 import logging
 import os
-import subprocess
+
+from .binutils import binary_get_accels
 
 LOG = logging.getLogger(__name__)
 
@@ -27,25 +28,6 @@  ADDITIONAL_ARCHES = {
     "aarch64" : "armhf"
 }
 
-def list_accel(qemu_bin):
-    """
-    List accelerators enabled in the QEMU binary.
-
-    @param qemu_bin (str): path to the QEMU binary.
-    @raise Exception: if failed to run `qemu -accel help`
-    @return a list of accelerator names.
-    """
-    if not qemu_bin:
-        return []
-    try:
-        out = subprocess.check_output([qemu_bin, '-accel', 'help'],
-                                      universal_newlines=True)
-    except:
-        LOG.debug("Failed to get the list of accelerators in %s", qemu_bin)
-        raise
-    # Skip the first line which is the header.
-    return [acc.strip() for acc in out.splitlines()[1:]]
-
 def kvm_available(target_arch=None, qemu_bin=None):
     """
     Check if KVM is available using the following heuristic:
@@ -64,7 +46,7 @@  def kvm_available(target_arch=None, qemu_bin=None):
         if target_arch != host_arch:
             if target_arch != ADDITIONAL_ARCHES.get(host_arch):
                 return False
-    if qemu_bin and "kvm" not in list_accel(qemu_bin):
+    if qemu_bin and "kvm" not in binary_get_accels(qemu_bin):
         return False
     return True
 
@@ -74,4 +56,4 @@  def tcg_available(qemu_bin):
 
     @param qemu_bin (str): path to the QEMU binary
     """
-    return 'tcg' in list_accel(qemu_bin)
+    return 'tcg' in binary_get_accels(qemu_bin)