diff mbox series

[3/3] avocado_qemu: add AVOCADO_DEFAULT_MACHINE

Message ID 20230118124348.364771-4-dbarboza@ventanamicro.com (mailing list archive)
State New, archived
Headers show
Series avocado_qemu: allow cross-arch tests | expand

Commit Message

Daniel Henrique Barboza Jan. 18, 2023, 12:43 p.m. UTC
Allow users to control which machine to use in tests where no particular
machine is specified. This is a good way to run tests in a machine
that's not the arch default, e.g. for qemu-system-x86_64 tests can be
run using a machine other than pc-i440fx.

This env var has greater effect when used together with the recently
added AVOCADO_DEFAULT_ARCH, allowing full control of what the tests
should use if no default arch/machine is given. In this example, a
check-avocado run will use the RISC-V 'virt' machine if no default
arch/machine is set:

AVOCADO_DEFAULT_ARCH=riscv64 AVOCADO_DEFAULT_MACHINE=virt make check-avocado

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 docs/devel/testing.rst                 | 8 +++++---
 tests/avocado/avocado_qemu/__init__.py | 3 +++
 2 files changed, 8 insertions(+), 3 deletions(-)

Comments

Fabiano Rosas Jan. 18, 2023, 3:42 p.m. UTC | #1
Daniel Henrique Barboza <dbarboza@ventanamicro.com> writes:

> Allow users to control which machine to use in tests where no particular
> machine is specified. This is a good way to run tests in a machine
> that's not the arch default, e.g. for qemu-system-x86_64 tests can be
> run using a machine other than pc-i440fx.
>
> This env var has greater effect when used together with the recently
> added AVOCADO_DEFAULT_ARCH, allowing full control of what the tests
> should use if no default arch/machine is given. In this example, a
> check-avocado run will use the RISC-V 'virt' machine if no default
> arch/machine is set:
>
> AVOCADO_DEFAULT_ARCH=riscv64 AVOCADO_DEFAULT_MACHINE=virt make check-avocado
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>  docs/devel/testing.rst                 | 8 +++++---
>  tests/avocado/avocado_qemu/__init__.py | 3 +++
>  2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
> index 95d0a3e626..128b6ae964 100644
> --- a/docs/devel/testing.rst
> +++ b/docs/devel/testing.rst
> @@ -1178,9 +1178,11 @@ The machine type that will be set to all QEMUMachine instances created
>  by the test.
>  
>  The ``machine`` attribute will be set to the test parameter of the same
> -name.  If one is not given explicitly, it will either be set to
> -``None``, or, if the test is tagged with one (and only one)
> -``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
> +name.  If one is not given explicitly, an env variable
> +AVOCADO_DEFAULT_MACHINE can be used as default value if set.  Otherwise
> +it will either be set to ``None``, or, if the test is tagged with one
> +(and only one) ``:avocado: tags=machine:VALUE`` tag, it will be set to
> +``VALUE``.
>  
>  qemu_bin
>  ''''''''
> diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
> index bc42985cbb..75eaaa9265 100644
> --- a/tests/avocado/avocado_qemu/__init__.py
> +++ b/tests/avocado/avocado_qemu/__init__.py
> @@ -282,6 +282,9 @@ def setUp(self):
>          self.machine = self.params.get('machine',
>                                         default=self._get_unique_tag_val('machine'))
>  

Would it work for you to replicate the AVOCADO_CMDLINE_TAGS behavior?

In Makefile.include:

ifdef AVOCADO_PARAMS
	AVOCADO_CMDLINE_PARAMS=$(addprefix -p , $(AVOCADO_PARAMS))
endif

make V=1 check-avocado AVOCADO_PARAMS=machine=foo AVOCADO_TESTS=../tests/avocado/migration.py

Results in:

./qemu-system-x86_64 -display none -vga none ... -machine foo
Daniel Henrique Barboza Jan. 18, 2023, 5:21 p.m. UTC | #2
On 1/18/23 12:42, Fabiano Rosas wrote:
> Daniel Henrique Barboza <dbarboza@ventanamicro.com> writes:
>
>> Allow users to control which machine to use in tests where no particular
>> machine is specified. This is a good way to run tests in a machine
>> that's not the arch default, e.g. for qemu-system-x86_64 tests can be
>> run using a machine other than pc-i440fx.
>>
>> This env var has greater effect when used together with the recently
>> added AVOCADO_DEFAULT_ARCH, allowing full control of what the tests
>> should use if no default arch/machine is given. In this example, a
>> check-avocado run will use the RISC-V 'virt' machine if no default
>> arch/machine is set:
>>
>> AVOCADO_DEFAULT_ARCH=riscv64 AVOCADO_DEFAULT_MACHINE=virt make check-avocado
>>
>> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
>> ---
>>   docs/devel/testing.rst                 | 8 +++++---
>>   tests/avocado/avocado_qemu/__init__.py | 3 +++
>>   2 files changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
>> index 95d0a3e626..128b6ae964 100644
>> --- a/docs/devel/testing.rst
>> +++ b/docs/devel/testing.rst
>> @@ -1178,9 +1178,11 @@ The machine type that will be set to all QEMUMachine instances created
>>   by the test.
>>   
>>   The ``machine`` attribute will be set to the test parameter of the same
>> -name.  If one is not given explicitly, it will either be set to
>> -``None``, or, if the test is tagged with one (and only one)
>> -``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
>> +name.  If one is not given explicitly, an env variable
>> +AVOCADO_DEFAULT_MACHINE can be used as default value if set.  Otherwise
>> +it will either be set to ``None``, or, if the test is tagged with one
>> +(and only one) ``:avocado: tags=machine:VALUE`` tag, it will be set to
>> +``VALUE``.
>>   
>>   qemu_bin
>>   ''''''''
>> diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
>> index bc42985cbb..75eaaa9265 100644
>> --- a/tests/avocado/avocado_qemu/__init__.py
>> +++ b/tests/avocado/avocado_qemu/__init__.py
>> @@ -282,6 +282,9 @@ def setUp(self):
>>           self.machine = self.params.get('machine',
>>                                          default=self._get_unique_tag_val('machine'))
>>   
> Would it work for you to replicate the AVOCADO_CMDLINE_TAGS behavior?
>
> In Makefile.include:
>
> ifdef AVOCADO_PARAMS
> 	AVOCADO_CMDLINE_PARAMS=$(addprefix -p , $(AVOCADO_PARAMS))
> endif
>
> make V=1 check-avocado AVOCADO_PARAMS=machine=foo AVOCADO_TESTS=../tests/avocado/migration.py
>
> Results in:
>
> ./qemu-system-x86_64 -display none -vga none ... -machine foo

This doesn't work as is (tested with no patches applied, only added AVOCADO_PARAMS in
Makefile.include).

At this moment it seems that there is no way of changing Avocado internal behavior
by using command line parameters/tags.


Thanks,


Daniel
diff mbox series

Patch

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 95d0a3e626..128b6ae964 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -1178,9 +1178,11 @@  The machine type that will be set to all QEMUMachine instances created
 by the test.
 
 The ``machine`` attribute will be set to the test parameter of the same
-name.  If one is not given explicitly, it will either be set to
-``None``, or, if the test is tagged with one (and only one)
-``:avocado: tags=machine:VALUE`` tag, it will be set to ``VALUE``.
+name.  If one is not given explicitly, an env variable
+AVOCADO_DEFAULT_MACHINE can be used as default value if set.  Otherwise
+it will either be set to ``None``, or, if the test is tagged with one
+(and only one) ``:avocado: tags=machine:VALUE`` tag, it will be set to
+``VALUE``.
 
 qemu_bin
 ''''''''
diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
index bc42985cbb..75eaaa9265 100644
--- a/tests/avocado/avocado_qemu/__init__.py
+++ b/tests/avocado/avocado_qemu/__init__.py
@@ -282,6 +282,9 @@  def setUp(self):
         self.machine = self.params.get('machine',
                                        default=self._get_unique_tag_val('machine'))
 
+        if self.machine is None:
+            self.machine = os.getenv('AVOCADO_DEFAULT_MACHINE')
+
     def require_accelerator(self, accelerator):
         """
         Requires an accelerator to be available for the test to continue