@samitouri / QOSamiQemu / commits / b86eff44ba

tests/functional: remove heuristics for finding build dir

Currently some heuristics are used to locate the build dir, if the MESON_BUILD_ROOT environment variable is not set. These are not entirely accurate, however, especially if the developer is using nested sub-dirs under $PWD/build/... Since the introduction of the 'run' script, we can ensure any direct execution of the tests will have MESON_BUILD_ROOT set. Meanwhile when meson runs the test it will also have this env set. The only gap is when running pre-caching, and that is easily fixed to set MESON_BUILD_ROOT. It can thus be assumed that MESON_BUILD_ROOT will always be set in any supported execution scenario, which allows the heuristics to be removed. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-ID: <20260310114756.146083-3-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>

Daniel P. Berrangé committed Mar 10, 2026 at 11:47 UTC b86eff44ba09b4baea17d2b002afa221de753cc4
2 files changed +4 -8
tests/functional/meson.build
+1
@@ -96,6 +96,7 @@ foreach speed : ['quick', 'thorough']
96 teststamp = testname + '.tstamp'
97 test_precache_env = environment()
98 test_precache_env.set('QEMU_TEST_PRECACHE', meson.current_build_dir() / teststamp)
99 + test_precache_env.set('MESON_BUILD_ROOT', meson.project_build_root())
100 test_precache_env.set('PYTHONPATH', meson.project_source_root() / 'python:' +
101 meson.current_source_dir())
102 precache = custom_target('func-precache-' + testname,
tests/functional/qemu_test/config.py
+3 -8
@@ -24,15 +24,10 @@ def _build_dir():
24 root = os.getenv('MESON_BUILD_ROOT')
25 if root is not None:
26 return Path(root)
27 - # Makefile.mtest only exists in build dir, so if it is available, use CWD
28 - if os.path.exists('Makefile.mtest'):
29 - return Path(os.getcwd())
27
31 - root = os.path.join(_source_dir(), 'build')
32 - if os.path.exists(root):
33 - return Path(root)
34 -
35 - raise Exception("Cannot identify build dir, set MESON_BUILD_ROOT")
28 + raise Exception("Missing MESON_BUILD_ROOT environment variable. " +
29 + "Please use the '<BUILD-DIR>/run' script if invoking " +
30 + "directly instead of via make/meson")
31
32 BUILD_DIR = _build_dir()
33