All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iotests: better heuristics to find I/O tests build/source dirs
@ 2026-11-11  9:11 Daniel P. Berrangé
  2026-11-11 12:36 ` Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel P. Berrangé @ 2026-11-11  9:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Pierrick Bouvier, Hanna Reitz, Marc-André Lureau,
	Peter Maydell, Eric Blake, Daniel P. Berrangé, Kevin Wolf,
	qemu-block, Paolo Bonzini

Currently the I/O tests cannot be run if executing directly
from the source directory, even when wrapped by the 'run'
script, due to inadequate heuristics to guess the directories.

If using the 'run' script, meson can tell us exactly where the
top level build and source directories are, so we don't need
to guess. Just read MESON_BUILD_ROOT and MESON_SOURCE_ROOT
env variables if present.

If not using the 'run' script, we can do a bit better at
guessing the path from the 'check' filename. Always resolve
from sys.argv[0], even when it is not a symlink, instead of
falling back to 'cwd()' which doesn't work since we stopped
having in-tree builds. If invoked directly from the source
tree, guess that the build root is the default 'build' name
which often works.

With this change the following all work:

1. From root of build dir, with run script

  cd build
  ./run tests/qemu-iotests/check 5

2. From root of build dir, without run script

  cd build
  tests/qemu-iotests/check 5

3. From I/O tests subdir of build dir, with run script

  cd build/tests/qemu-iotests
  ../../run ./check 5

4. From I/O tests subdir of build dir, without run script

  cd build/tests/qemu-iotests
  ./check 5

5. From root of source dir, with run script

  ./build/run tests/qemu-iotests/check 5

6. From root of source dir, without run script

  tests/qemu-iotests/check 5

7. From I/O tests subdir of source dir, with run script

  cd tests/qemu-iotests
  ../../build/run ./check 5

8. From I/O tests subdir of source dir, without run script

  cd tests/qemu-iotests
  ./check 5

Before this commit, items 5-8 would always fail. Items 6 and
8 will not work if using a build directory with a name other
than the default 'build'. For those scenarios use one of the
other 6 possible variants.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 meson.build              |  1 +
 tests/qemu-iotests/check | 52 +++++++++++++++++++++++++++++-----------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/meson.build b/meson.build
index d7bcb581c18..9d15f2e9551 100644
--- a/meson.build
+++ b/meson.build
@@ -3502,6 +3502,7 @@ genh += config_host_h
 
 devenv = environment()
 devenv.set('MESON_BUILD_ROOT', meson.project_build_root())
+devenv.set('MESON_SOURCE_ROOT', meson.project_source_root())
 devenv.set('VIRTUAL_ENV', meson.project_build_root() / 'pyvenv')
 devenv.prepend('PATH', meson.project_build_root() / 'pyvenv'/ 'bin')
 devenv.prepend('PYTHONPATH', meson.current_source_dir() / 'tests' / 'functional')
diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check
index c8ba536970c..40baa2b4107 100755
--- a/tests/qemu-iotests/check
+++ b/tests/qemu-iotests/check
@@ -28,18 +28,42 @@ from findtests import TestFinder
 from testenv import TestEnv
 from testrunner import TestRunner
 
-def get_default_path(follow_link=False):
-    """
-    Try to automagically figure out the path we are running from.
-    """
-    # called from the build tree?
-    if os.path.islink(sys.argv[0]):
-        if follow_link:
-            return os.path.dirname(os.readlink(sys.argv[0]))
+
+def get_build_dir():
+    if "MESON_BUILD_ROOT" in os.environ:
+        br = os.environ["MESON_BUILD_ROOT"]
+        return os.path.join(br, "tests", "qemu-iotests")
+    else:
+        if os.path.islink(sys.argv[0]):
+            iobr = os.path.dirname(sys.argv[0])
+        else:
+            iobr = os.path.join(os.path.dirname(sys.argv[0]),
+                                "..", "..", "build", "tests", "qemu-iotests")
+        if (not os.path.exists(os.path.join(iobr, "check")) or
+            os.path.exists(os.path.join(iobr, "testenv.py"))):
+            raise Exception(f"MESON_BUILD_ROOT is not set, and guessed "
+                            "I/O tests build root {iobr} does not look "
+                            "valid. Please use the 'run' script to invoke "
+                            "the I/O tests")
+        return os.path.abspath(iobr)
+
+
+def get_source_dir():
+    if "MESON_SOURCE_ROOT" in os.environ:
+        sr = os.environ["MESON_SOURCE_ROOT"]
+        return os.path.join(sr, "tests", "qemu-iotests")
+    else:
+        if os.path.islink(sys.argv[0]):
+            iosr = os.path.dirname(os.readlink(sys.argv[0]))
         else:
-            return os.path.dirname(os.path.abspath(sys.argv[0]))
-    else:  # or source tree?
-        return os.getcwd()
+            iosr = os.path.dirname(sys.argv[0])
+        if not os.path.exists(os.path.join(iosr, "testenv.py")):
+            raise Exception(f"MESON_SOURCE_ROOT is not set, and guessed "
+                            "I/O tests source root {iosr} does not look "
+                            "valid. Please use the 'run' script to invoke "
+                            "the I/O tests")
+        return os.path.abspath(iosr)
+
 
 def make_argparser() -> argparse.ArgumentParser:
     p = argparse.ArgumentParser(
@@ -131,11 +155,11 @@ def make_argparser() -> argparse.ArgumentParser:
                        'middle of the process.')
     g_sel.add_argument('tests', metavar='TEST_FILES', nargs='*',
                        help='tests to run, or "--" followed by a command')
-    g_sel.add_argument('--build-dir', default=get_default_path(),
+    g_sel.add_argument('--build-dir', default=get_build_dir(),
                        help='Path to iotests build directory')
     g_sel.add_argument('--source-dir',
-                       default=get_default_path(follow_link=True),
-                       help='Path to iotests build directory')
+                       default=get_source_dir(),
+                       help='Path to iotests source directory')
 
     return p
 
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-11 12:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  9:11 [PATCH v2] iotests: better heuristics to find I/O tests build/source dirs Daniel P. Berrangé
2026-11-11 12:36 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.