support/testing/infra/emulator.py: add build host dir to qemu search path

The relevant qemu emulator is started with pexpect.spawn() with a
default environment (and PATH). This will always use the qemu available
on the host. When running in the reference Docker image, it is using an
old Qemu v5.2.0. This version is getting too old to run with more
recent components, like EDK2 or ATF.

The main reason to use a qemu version preinstalled in the Docker image
was to save some build time. Also, this behavior is opposite to the
"start-qemu.sh" helper script [1], which tries to execute the
Buildroot host-qemu first (and then fallback the the version on the
host system, if available). An option was added in [2] to let the user
have a better control on which version is used.

Also, updating the Buildroot reference Docker image has a larger
impact on the whole project (i.e. updating the image would bring
a newer qemu version, but might break many other things, at a time
which is not always convenient).

We now need some kind of control in runtime tests, to choose between a
"stock" qemu, and a more recent version with all the bells and
whistles.

This commit adds the Buildroot host build directory in the path. This
will make the runtime test infrastructure to use a host-qemu, if
selected by a runtime test configuration.

For now, most of the test can continue to use the qemu version provided
in the Docker image. Only the problematic tests relying on a recent
version will select BR2_PACKAGE_HOST_QEMU=y. The host-qemu package is
usually maintained to a recent version, so this should be sufficient.

[1] https://gitlab.com/buildroot.org/buildroot/-/blob/master/board/qemu/start-qemu.sh.in
[2] 5de78f181a

Signed-off-by: Julien Olivain <ju.o@free.fr>
Reviewed-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
This commit is contained in:
Julien Olivain 2024-10-29 21:54:35 +01:00 committed by Romain Naour
parent c58a2a9687
commit 0d4177598c

View File

@ -44,6 +44,7 @@ class Emulator(object):
def __init__(self, builddir, downloaddir, logtofile, timeout_multiplier):
self.qemu = None
self.repl = None
self.builddir = builddir
self.downloaddir = downloaddir
self.logfile = infra.open_log_file(builddir, "run", logtofile)
# We use elastic runners on the cloud to runs our tests. Those runners
@ -116,11 +117,14 @@ class Emulator(object):
self.logfile.write(f"> host loadavg: {ldavg_str}\n")
self.logfile.write(f"> timeout multiplier: {self.timeout_multiplier}\n")
self.logfile.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd))
host_bin = os.path.join(self.builddir, "host", "bin")
br_path = host_bin + os.pathsep + os.environ["PATH"]
self.qemu = pexpect.spawn(qemu_cmd[0], qemu_cmd[1:],
timeout=5 * self.timeout_multiplier,
encoding='utf-8',
codec_errors='replace',
env={"QEMU_AUDIO_DRV": "none"})
env={"QEMU_AUDIO_DRV": "none",
"PATH": br_path})
# We want only stdout into the log to avoid double echo
self.qemu.logfile_read = self.logfile