[PATCH v2 2/2] tests/functional: remove heuristics for finding build dir

Daniel P. Berrangé posted 2 patches 1 month ago
Maintainers: Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH v2 2/2] tests/functional: remove heuristics for finding build dir
Posted by Daniel P. Berrangé 1 month ago
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>
---
 tests/functional/meson.build         |  1 +
 tests/functional/qemu_test/config.py | 11 +++--------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index d34aefa8b0..1b94c2efb6 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -95,6 +95,7 @@ foreach speed : ['quick', 'thorough']
       teststamp = testname + '.tstamp'
       test_precache_env = environment()
       test_precache_env.set('QEMU_TEST_PRECACHE', meson.current_build_dir() / teststamp)
+      test_precache_env.set('MESON_BUILD_ROOT', meson.project_build_root())
       test_precache_env.set('PYTHONPATH', meson.project_source_root() / 'python:' +
                                           meson.current_source_dir())
       precache = custom_target('func-precache-' + testname,
diff --git a/tests/functional/qemu_test/config.py b/tests/functional/qemu_test/config.py
index 0192027233..e0893f630e 100644
--- a/tests/functional/qemu_test/config.py
+++ b/tests/functional/qemu_test/config.py
@@ -24,15 +24,10 @@ def _build_dir():
     root = os.getenv('MESON_BUILD_ROOT')
     if root is not None:
         return Path(root)
-    # Makefile.mtest only exists in build dir, so if it is available, use CWD
-    if os.path.exists('Makefile.mtest'):
-        return Path(os.getcwd())
 
-    root = os.path.join(_source_dir(), 'build')
-    if os.path.exists(root):
-        return Path(root)
-
-    raise Exception("Cannot identify build dir, set MESON_BUILD_ROOT")
+    raise Exception("Missing MESON_BUILD_ROOT environment variable. " +
+                    "Please use the '<BUILD-DIR>/run' script if invoking " +
+                    "directly instead of via make/meson")
 
 BUILD_DIR = _build_dir()
 
-- 
2.53.0


Re: [PATCH v2 2/2] tests/functional: remove heuristics for finding build dir
Posted by Thomas Huth 1 month ago
On 10/03/2026 12.47, Daniel P. Berrangé wrote:
> 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.

Fair point. And in the worst case, it's always possible to set the env 
variable manually if you still want to run a test directly without the "run" 
script.

Reviewed-by: Thomas Huth <thuth@redhat.com>