diff mbox series

[v2,10/29] python/qemu: Add binutils::binary_get_qom_implementations()

Message ID 20200129212345.20547-11-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
Since QEMU binaries can be built with various configurations,
the list of QOM objects linked can vary.
Add a helper to query the list of all QOM types implementing a
particular interface.

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

Comments

Liam Merwick Feb. 7, 2020, 2:28 p.m. UTC | #1
On 29/01/2020 21:23, Philippe Mathieu-Daudé wrote:
> Since QEMU binaries can be built with various configurations,
> the list of QOM objects linked can vary.
> Add a helper to query the list of all QOM types implementing a
> particular interface.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   python/qemu/binutils.py          | 20 ++++++++++++++++++++
>   tests/acceptance/core_scripts.py | 10 ++++++++++
>   2 files changed, 30 insertions(+)
> 
> diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
> index 7bb57c521b..76f256f5d2 100644
> --- a/python/qemu/binutils.py
> +++ b/python/qemu/binutils.py
> @@ -66,3 +66,23 @@ def binary_get_machines(qemu_bin):
>           LOG.info(res)
>           vm.shutdown()
>           return [m['name'] for m in res]
> +
> +def binary_get_qom_implementations(qemu_bin, type_name, include_abstract=False):
> +    '''
> +    Get list of QOM types implementing a particular interface
> +
> +    @param qemu_bin (str): path to the QEMU binary
> +    @param type_name (str): QOM interface name
> +    @param include_abstract (bool): if True, abstract interfaces are also
> +                                    returned in the list
> +    @return list of QOM types implementing the interface @type_name
> +    '''
> +    with QEMUMachine(qemu_bin) as vm:
> +        vm.set_machine('none')
> +        vm.launch()
> +        res = vm.command('qom-list-types',
> +                         implements=type_name,
> +                         abstract=include_abstract)
> +        LOG.info(res)
> +        vm.shutdown()


Based on Wainer's comment on patch3 - is this vm.shutdown() needed?

otherwise

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


> +        return [m['name'] for m in res]
> diff --git a/tests/acceptance/core_scripts.py b/tests/acceptance/core_scripts.py
> index a5b112f928..c2fe4acf1d 100644
> --- a/tests/acceptance/core_scripts.py
> +++ b/tests/acceptance/core_scripts.py
> @@ -18,6 +18,7 @@ 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_machines
> +from qemu.binutils import binary_get_qom_implementations
>   from qemu.binutils import binary_get_version
>   
>   
> @@ -49,3 +50,12 @@ class PythonQemuCoreScripts(Test):
>               logger.debug('machine: {}'.format(m))
>           # The 'none' machine is always available
>           self.assertIn('none', machines)
> +
> +    def test_get_qom_implementation(self):
> +        logger = logging.getLogger('core')
> +        type_name = "accel"
> +        type_impl = binary_get_qom_implementations(self.qemu_bin,
> +                                                   type_name, True)
> +        for t in type_impl:
> +            logger.debug('type: {}'.format(t))
> +        self.assertIn(type_name, type_impl)
>
Philippe Mathieu-Daudé Feb. 7, 2020, 2:33 p.m. UTC | #2
On 2/7/20 3:28 PM, Liam Merwick wrote:
> On 29/01/2020 21:23, Philippe Mathieu-Daudé wrote:
>> Since QEMU binaries can be built with various configurations,
>> the list of QOM objects linked can vary.
>> Add a helper to query the list of all QOM types implementing a
>> particular interface.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>   python/qemu/binutils.py          | 20 ++++++++++++++++++++
>>   tests/acceptance/core_scripts.py | 10 ++++++++++
>>   2 files changed, 30 insertions(+)
>>
>> diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
>> index 7bb57c521b..76f256f5d2 100644
>> --- a/python/qemu/binutils.py
>> +++ b/python/qemu/binutils.py
>> @@ -66,3 +66,23 @@ def binary_get_machines(qemu_bin):
>>           LOG.info(res)
>>           vm.shutdown()
>>           return [m['name'] for m in res]
>> +
>> +def binary_get_qom_implementations(qemu_bin, type_name, 
>> include_abstract=False):
>> +    '''
>> +    Get list of QOM types implementing a particular interface
>> +
>> +    @param qemu_bin (str): path to the QEMU binary
>> +    @param type_name (str): QOM interface name
>> +    @param include_abstract (bool): if True, abstract interfaces are 
>> also
>> +                                    returned in the list
>> +    @return list of QOM types implementing the interface @type_name
>> +    '''
>> +    with QEMUMachine(qemu_bin) as vm:
>> +        vm.set_machine('none')
>> +        vm.launch()
>> +        res = vm.command('qom-list-types',
>> +                         implements=type_name,
>> +                         abstract=include_abstract)
>> +        LOG.info(res)
>> +        vm.shutdown()
> 
> 
> Based on Wainer's comment on patch3 - is this vm.shutdown() needed?

Nop.

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

Thanks :)

> 
> 
>> +        return [m['name'] for m in res]
>> diff --git a/tests/acceptance/core_scripts.py 
>> b/tests/acceptance/core_scripts.py
>> index a5b112f928..c2fe4acf1d 100644
>> --- a/tests/acceptance/core_scripts.py
>> +++ b/tests/acceptance/core_scripts.py
>> @@ -18,6 +18,7 @@ 
>> 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_machines
>> +from qemu.binutils import binary_get_qom_implementations
>>   from qemu.binutils import binary_get_version
>> @@ -49,3 +50,12 @@ class PythonQemuCoreScripts(Test):
>>               logger.debug('machine: {}'.format(m))
>>           # The 'none' machine is always available
>>           self.assertIn('none', machines)
>> +
>> +    def test_get_qom_implementation(self):
>> +        logger = logging.getLogger('core')
>> +        type_name = "accel"
>> +        type_impl = binary_get_qom_implementations(self.qemu_bin,
>> +                                                   type_name, True)
>> +        for t in type_impl:
>> +            logger.debug('type: {}'.format(t))
>> +        self.assertIn(type_name, type_impl)
>>
>
diff mbox series

Patch

diff --git a/python/qemu/binutils.py b/python/qemu/binutils.py
index 7bb57c521b..76f256f5d2 100644
--- a/python/qemu/binutils.py
+++ b/python/qemu/binutils.py
@@ -66,3 +66,23 @@  def binary_get_machines(qemu_bin):
         LOG.info(res)
         vm.shutdown()
         return [m['name'] for m in res]
+
+def binary_get_qom_implementations(qemu_bin, type_name, include_abstract=False):
+    '''
+    Get list of QOM types implementing a particular interface
+
+    @param qemu_bin (str): path to the QEMU binary
+    @param type_name (str): QOM interface name
+    @param include_abstract (bool): if True, abstract interfaces are also
+                                    returned in the list
+    @return list of QOM types implementing the interface @type_name
+    '''
+    with QEMUMachine(qemu_bin) as vm:
+        vm.set_machine('none')
+        vm.launch()
+        res = vm.command('qom-list-types',
+                         implements=type_name,
+                         abstract=include_abstract)
+        LOG.info(res)
+        vm.shutdown()
+        return [m['name'] for m in res]
diff --git a/tests/acceptance/core_scripts.py b/tests/acceptance/core_scripts.py
index a5b112f928..c2fe4acf1d 100644
--- a/tests/acceptance/core_scripts.py
+++ b/tests/acceptance/core_scripts.py
@@ -18,6 +18,7 @@  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_machines
+from qemu.binutils import binary_get_qom_implementations
 from qemu.binutils import binary_get_version
 
 
@@ -49,3 +50,12 @@  class PythonQemuCoreScripts(Test):
             logger.debug('machine: {}'.format(m))
         # The 'none' machine is always available
         self.assertIn('none', machines)
+
+    def test_get_qom_implementation(self):
+        logger = logging.getLogger('core')
+        type_name = "accel"
+        type_impl = binary_get_qom_implementations(self.qemu_bin,
+                                                   type_name, True)
+        for t in type_impl:
+            logger.debug('type: {}'.format(t))
+        self.assertIn(type_name, type_impl)