[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] avocado_qemu: add AVOCADO_DEFAULT_ARCH for cross-arch tests
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH 2/3] avocado_qemu: add AVOCADO_DEFAULT_ARCH for cross-arch tests |
Date: |
Wed, 18 Jan 2023 09:43:47 -0300 |
All avocado tests that are arch agnostic (i.e. does not set an 'arch'
tag) are run with arch=None in pick_default_qemu_bin(), and then 'arch'
is set to os.uname()[4], meaning that it will take the arch of the
running host.
This means that if one compiles QEMU binaries for non-x86 targets on an
x86 machine, and then run 'make check-avocado', all arch agnostic tests
will be cancelled because there's no qemu-system-x86_64 to be found.
There is no particular reason to not allow these tests to be run with
other arch binaries in a x86_64 host. Allow the developer to do it by
adding a a new env variable called AVOCADO_DEFAULT_ARCH. Any 'arch' that
is set by this variable will take precedence of setting it via
os.uname()[4]. We can then run non-x86 binaries tests in a x86_64 host
as follows:
$ AVOCADO_DEFAULT_ARCH=riscv64 make check-avocado
(...)
RESULTS: PASS 11 | ERROR 0 | FAIL 0 | SKIP 1 | WARN 0 | INTERRUPT 0 | CANCEL 0
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
docs/devel/testing.rst | 7 +++++++
tests/avocado/avocado_qemu/__init__.py | 9 ++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index e10c47b5a7..95d0a3e626 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -1144,6 +1144,13 @@ the framework or by the test itself. At the framework
level, it will
currently influence the selection of a QEMU binary (when one is not
explicitly given).
+When ``arch`` is not set, an env variable AVOCADO_DEFAULT_ARCH can
+be used as default value if set. This allows hosts of different
+architectures to run arch-agnostic tests using binaries from other
+archs (i.e. a x86_64 host can use aarch64/riscv64 binaries as
+default). If this variable isn't set, ``arch`` defaults to the
+host system arch given by ``os.uname``.
+
Tests are also free to use this attribute value, for their own needs.
A test may, for instance, use the same value when selecting the
architecture of a kernel or disk image to boot a VM with.
diff --git a/tests/avocado/avocado_qemu/__init__.py
b/tests/avocado/avocado_qemu/__init__.py
index 8614ac3978..bc42985cbb 100644
--- a/tests/avocado/avocado_qemu/__init__.py
+++ b/tests/avocado/avocado_qemu/__init__.py
@@ -107,14 +107,17 @@ def pick_default_qemu_bin(bin_prefix='qemu-system-',
arch=None):
directory or in the source tree root directory.
:param arch: the arch to use when looking for a QEMU binary (the target
- will match the arch given). If None (the default), arch
- will be the current host system arch (as given by
- :func:`os.uname`).
+ will match the arch given). If None (the default), check
+ if the AVOCADO_DEFAULT_ARCH env var is set and use it as
+ arch. If it's not set, arch will be the current host
+ system arch (as given by :func:`os.uname`).
:type arch: str
:returns: the path to the default QEMU binary or None if one could not
be found
:rtype: str or None
"""
+ if arch is None:
+ arch = os.getenv('AVOCADO_DEFAULT_ARCH')
if arch is None:
arch = os.uname()[4]
# qemu binary path does not match arch for powerpc, handle it
--
2.39.0