Skip to contentSkip to conversation

tests/functional: improve robustness of build dir location logic

PATCH In review Daniel P. Berrangé 2 participants 5 messages Mar 10 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover tests/functional: improve robustness of build dir location logic

Changed in v2:

* Fix env var name typos in commit message
* Ensure precaching sets MESON_BUILD_ROOT
* Remove redundant heuristics for finding build dir

Daniel P. Berrangé (2):
tests/functional: fix log placement when run directly tests/functional: remove heuristics for finding build dir

 tests/functional/meson.build         |  3 ++-
 tests/functional/qemu_test/config.py | 13 ++++---------
 2 files changed, 6 insertions(+), 10 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/2 tests/functional: fix log placement when run directly

When running functional tests directly there are some heuristics to figure out where the build directory lives, along with the possibility to override the logic by setting the QEMU_BUILD_DIR env variable. This env var is set as part of the test env when run via Meson but not when run directly.

A particular flaw with the currently logic is that it silently uses the wrong location when the build directory is a sub-dir under "./build", which is a common usage scenario for some devs.

With the recent introduction of the 'run' script, we now have the MESON_BUILD_ROOT env variable set unconditionally, so we can rely on that from the functional tests to get the correct location in all scenarios.

---
 tests/functional/meson.build         | 2 +-
 tests/functional/qemu_test/config.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tests/functional/meson.build +1 -1
index b979cff2b9..d34aefa8b0 100644
@@ -74,7 +74,7 @@ foreach speed : ['quick', 'thorough']
       test_deps += [qemu_img]
     endif
     test_env.set('QEMU_TEST_QEMU_BINARY', test_emulator.full_path())
-    test_env.set('QEMU_BUILD_ROOT', meson.project_build_root())
+    test_env.set('MESON_BUILD_ROOT', meson.project_build_root())
     test_env.set('PYTHONPATH', meson.project_source_root() / 'python:' +
                                meson.current_source_dir())
 
tests/functional/qemu_test/config.py +2 -2
index 6d4c9c3ce1..0192027233 100644
@@ -21,7 +21,7 @@ def _source_dir():
     return Path(__file__).parent.parent.parent.parent
 
 def _build_dir():
-    root = os.getenv('QEMU_BUILD_ROOT')
+    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
@@ -32,7 +32,7 @@ def _build_dir():
     if os.path.exists(root):
         return Path(root)
 
-    raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT")
+    raise Exception("Cannot identify build dir, set MESON_BUILD_ROOT")
 
 BUILD_DIR = _build_dir()
 
Signature · 1 line
2.53.0
#3 lore raw

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

In reply to Daniel P. Berrangé

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.

---
 tests/functional/meson.build         |  1 +
 tests/functional/qemu_test/config.py | 11 +++--------
 2 files changed, 4 insertions(+), 8 deletions(-)
tests/functional/meson.build +1 -0
index d34aefa8b0..1b94c2efb6 100644
@@ -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,
tests/functional/qemu_test/config.py +3 -8
index 0192027233..e0893f630e 100644
@@ -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()
 
Signature · 1 line
2.53.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] tests/functional: fix log placement when run directly

In reply to Daniel P. Berrangé
Quoted 15 lines · Daniel P. Berrangé

When running functional tests directly there are some heuristics to figure out where the build directory lives, along with the possibility to override the logic by setting the QEMU_BUILD_DIR env variable. This env var is set as part of the test env when run via Meson but not when run directly.

A particular flaw with the currently logic is that it silently uses the wrong location when the build directory is a sub-dir under "./build", which is a common usage scenario for some devs.

With the recent introduction of the 'run' script, we now have the MESON_BUILD_ROOT env variable set unconditionally, so we can rely on that from the functional tests to get the correct location in all scenarios.

Quoted 6 lines
---
  tests/functional/meson.build         | 2 +-
  tests/functional/qemu_test/config.py | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)
Reviewed-by on v2 2/2
#4 lore raw

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

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

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.

Quoted 7 lines

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.