Skip to contentSkip to conversation

iotests: make meson aware of individual I/O tests

PATCH Superseded Daniel P. Berrangé 3 participants 24 messages Mar 2, 2023 – Mar 3, 2023 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover iotests: make meson aware of individual I/O tests

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Compare contrast output from a current job:

https://gitlab.com/qemu-project/qemu/-/jobs/3863603546

[quote]
204/224 qemu:block / qemu-iotests qcow2 OK 329.94s 119 subtests passed
[/quote]

Vs what is seen with this series:

https://gitlab.com/berrange/qemu/-/jobs/3865975463

[quote]

204/350 qemu:block / qemu-iotests-qcow2-001   OK    2.16s   1 subtests passed
205/350 qemu:block / qemu-iotests-qcow2-002   OK    2.77s   1 subtests passed

...snip...

329/350 qemu:block / qemu-iotests-qcow2-qemu-img-close-errors OK 6.19s 1 subtests passed
330/350 qemu:block / qemu-iotests-qcow2-qsd-jobs OK 0.55s 1 subtests passed
[/quote]

A few tweaks were needed to the iotests runner because it had a few assumptions about it always running in a tree that has already been built, which is obviously not the case at the time meson does test discovery.

Daniel P. Berrangé (5):
iotests: explicitly pass source/build dir to 'check' command
iotests: allow test discovery before building
iotests: strip subdir path when listing tests
iotests: print TAP protocol version when reporting tests
iotests: register each I/O test separately with meson

 tests/qemu-iotests/check         | 11 +++++++++--
 tests/qemu-iotests/meson.build   | 33 ++++++++++++++++++++++++++------
 tests/qemu-iotests/testenv.py    | 22 +++++++++++++++++----
 tests/qemu-iotests/testrunner.py |  1 +
 4 files changed, 55 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/5 iotests: explicitly pass source/build dir to 'check' command

The 'check' script has some rather dubious logic whereby it assumes that if invoked as a symlink, then it is running from a separate source tree and build tree, otherwise it assumes the current working directory is a combined source and build tree.

This doesn't work if you want to invoke the 'check' script using its full source tree path while still using a split source and build tree layout. This would be a typical situation with meson if you ask it to find the 'check' script path using files('check').

Rather than trying to make the logic more magical, add support for explicitly passing the dirs using --source-dir and --build-dir. If either is omitted the current logic is maintained.

---
 tests/qemu-iotests/check      |  8 +++++++-
 tests/qemu-iotests/testenv.py | 17 +++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
tests/qemu-iotests/check +7 -1
index 9bdda1394e..806abc21d6 100755
@@ -113,6 +113,10 @@ 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=None,
+                       help='Path to iotests build directory')
+    g_sel.add_argument('--source-dir', default=None,
+                       help='Path to iotests build directory')
 
     return p
 
@@ -124,7 +128,9 @@ if __name__ == '__main__':
                   aiomode=args.aiomode, cachemode=args.cachemode,
                   imgopts=args.imgopts, misalign=args.misalign,
                   debug=args.debug, valgrind=args.valgrind,
-                  gdb=args.gdb, qprint=args.print)
+                  gdb=args.gdb, qprint=args.print,
+                  source_dir=args.source_dir,
+                  build_dir=args.build_dir)
 
     if len(sys.argv) > 1 and sys.argv[-len(args.tests)-1] == '--':
         if not args.tests:
tests/qemu-iotests/testenv.py +13 -4
index a864c74b12..9bf37cd381 100644
@@ -177,7 +177,9 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
                  debug: bool = False,
                  valgrind: bool = False,
                  gdb: bool = False,
-                 qprint: bool = False) -> None:
+                 qprint: bool = False,
+                 source_dir: Optional[str] = None,
+                 build_dir: Optional[str] = None) -> None:
         self.imgfmt = imgfmt
         self.imgproto = imgproto
         self.aiomode = aiomode
@@ -213,12 +215,19 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
 
         if os.path.islink(sys.argv[0]):
             # called from the build tree
-            self.source_iotests = os.path.dirname(os.readlink(sys.argv[0]))
-            self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
+            self.source_iotests = os.path.dirname(
+                os.readlink(sys.argv[0]))
+            self.build_iotests = os.path.dirname(
+                os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
             self.source_iotests = os.getcwd()
-            self.build_iotests = self.source_iotests
+            self.build_iotests = os.getcwd()
+
+        if source_dir is not None:
+            self.source_iotests = source_dir
+        if build_dir is not None:
+            self.build_iotests = build_dir
 
         self.build_root = os.path.join(self.build_iotests, '..', '..')
 
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/5] iotests: explicitly pass source/build dir to 'check' command

Quoted 25 lines · Daniel P. Berrangé

The 'check' script has some rather dubious logic whereby it assumes that if invoked as a symlink, then it is running from a separate source tree and build tree, otherwise it assumes the current working directory is a combined source and build tree.

This doesn't work if you want to invoke the 'check' script using its full source tree path while still using a split source and build tree layout. This would be a typical situation with meson if you ask it to find the 'check' script path using files('check').

Rather than trying to make the logic more magical, add support for explicitly passing the dirs using --source-dir and --build-dir. If either is omitted the current logic is maintained.

---
 tests/qemu-iotests/check      |  8 +++++++-
 tests/qemu-iotests/testenv.py | 17 +++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
tests/qemu-iotests/check +0 -0
index 9bdda1394e..806abc21d6 100755

tests/qemu-iotests/check def make_argparser() -> argparse.ArgumentParser: · line 120

Quoted 8 lines
tests/qemu-iotests/check +4 -0
@@ -113,6 +113,10 @@ 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=None,
+                       help='Path to iotests build directory')
+    g_sel.add_argument('--source-dir', default=None,
+                       help='Path to iotests build directory')
 

I'd be tempted to push all the automagic stuff into the options so you have something like:

--8<---------------cut here---------------start------------->8---
modified tests/qemu-iotests/check
@@ -27,8 +27,23 @@ 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]))
+ else:
+ return os.path.dirname(os.path.abspath(sys.argv[0]))
+ else: # or source tree?
+ return os.getcwd()
+
+
def make_argparser() -> argparse.ArgumentParser:
- p = argparse.ArgumentParser(description="Test run options")
+ p = argparse.ArgumentParser(description="Test run options",
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)

p.add_argument('-n', '--dry-run', action='store_true',
help='show me, do not run tests')
@@ -113,9 +128,9 @@ 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=None,
+ g_sel.add_argument('--build-dir', default=get_default_path(),
help='Path to iotests build directory')
- g_sel.add_argument('--source-dir', default=None,
+ g_sel.add_argument('--source-dir', default=get_default_path(follow_link=True),
help='Path to iotests build directory')

return p
modified tests/qemu-iotests/testenv.py
@@ -213,23 +213,8 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
# Initialize generic paths: build_root, build_iotests, source_iotests, # which are needed to initialize some environment variables. They are # used by init_*() functions as well.
-
- if os.path.islink(sys.argv[0]):
- # called from the build tree
- self.source_iotests = os.path.dirname(
- os.readlink(sys.argv[0]))
- self.build_iotests = os.path.dirname(
- os.path.abspath(sys.argv[0]))
- else:

-            # called from the source tree
-            self.source_iotests = os.getcwd()
-            self.build_iotests = os.getcwd()

-
- if source_dir is not None:
- self.source_iotests = source_dir
- if build_dir is not None:
- self.build_iotests = build_dir
-
+ self.source_iotests = source_dir
+ self.build_iotests = build_dir

         self.build_root = os.path.join(self.build_iotests, '..', '..')
 
         self.init_directories()

--8<---------------cut here---------------end--------------->8---

Quoted 50 lines
tests/qemu-iotests/check +3 -1
     return p
 
@@ -124,7 +128,9 @@ if __name__ == '__main__':
                   aiomode=args.aiomode, cachemode=args.cachemode,
                   imgopts=args.imgopts, misalign=args.misalign,
                   debug=args.debug, valgrind=args.valgrind,
-                  gdb=args.gdb, qprint=args.print)
+                  gdb=args.gdb, qprint=args.print,
+                  source_dir=args.source_dir,
+                  build_dir=args.build_dir)
 
     if len(sys.argv) > 1 and sys.argv[-len(args.tests)-1] == '--':
         if not args.tests:
tests/qemu-iotests/testenv.py +13 -4
index a864c74b12..9bf37cd381 100644
@@ -177,7 +177,9 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
                  debug: bool = False,
                  valgrind: bool = False,
                  gdb: bool = False,
-                 qprint: bool = False) -> None:
+                 qprint: bool = False,
+                 source_dir: Optional[str] = None,
+                 build_dir: Optional[str] = None) -> None:
         self.imgfmt = imgfmt
         self.imgproto = imgproto
         self.aiomode = aiomode
@@ -213,12 +215,19 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
 
         if os.path.islink(sys.argv[0]):
             # called from the build tree
-            self.source_iotests = os.path.dirname(os.readlink(sys.argv[0]))
-            self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
+            self.source_iotests = os.path.dirname(
+                os.readlink(sys.argv[0]))
+            self.build_iotests = os.path.dirname(
+                os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
             self.source_iotests = os.getcwd()
-            self.build_iotests = self.source_iotests
+            self.build_iotests = os.getcwd()
+
+        if source_dir is not None:
+            self.source_iotests = source_dir
+        if build_dir is not None:
+            self.build_iotests = build_dir
 
         self.build_root = os.path.join(self.build_iotests, '..', '..')
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#3 lore raw

Re: [PATCH 1/5] iotests: explicitly pass source/build dir to 'check' command

Quoted 23 lines · Alex Bennée
Quoted 20 lines · Daniel P. Berrangé

The 'check' script has some rather dubious logic whereby it assumes that if invoked as a symlink, then it is running from a separate source tree and build tree, otherwise it assumes the current working directory is a combined source and build tree.

This doesn't work if you want to invoke the 'check' script using its full source tree path while still using a split source and build tree layout. This would be a typical situation with meson if you ask it to find the 'check' script path using files('check').

Rather than trying to make the logic more magical, add support for explicitly passing the dirs using --source-dir and --build-dir. If either is omitted the current logic is maintained.

---
 tests/qemu-iotests/check      |  8 +++++++-
 tests/qemu-iotests/testenv.py | 17 +++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
Quoted 16 lines

tests/qemu-iotests/check def make_argparser() -> argparse.ArgumentParser: · line 120

Quoted 13 lines
tests/qemu-iotests/check +4 -0
index 9bdda1394e..806abc21d6 100755
@@ -113,6 +113,10 @@ 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=None,
+                       help='Path to iotests build directory')
+    g_sel.add_argument('--source-dir', default=None,
+                       help='Path to iotests build directory')
 

I'd be tempted to push all the automagic stuff into the options so you have something like:

Hmm, yes, that's a nice idea, will give it a go as you suggest.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

PATCH 2/5 iotests: allow test discovery before building

In reply to Daniel P. Berrangé

The 'check' script can be invoked in "dry run" mode, in which case it merely does test discovery and prints out all their names. Despite only doing test discovery it still validates that the various QEMU binaries can be found. This makes it impossible todo test discovery prior to building QEMU. This is a desirable feature to support, because it will let meson discover tests.

Fortunately the code in the TestEnv constructor is ordered in a way that makes this fairly trivial to achieve. We can just short circuit the constructor after the basic directory paths have been set.

---
 tests/qemu-iotests/check      | 1 +
 tests/qemu-iotests/testenv.py | 5 +++++
 2 files changed, 6 insertions(+)
tests/qemu-iotests/check +1 -0
index 806abc21d6..7e287a79a3 100755
@@ -129,6 +129,7 @@ if __name__ == '__main__':
                   imgopts=args.imgopts, misalign=args.misalign,
                   debug=args.debug, valgrind=args.valgrind,
                   gdb=args.gdb, qprint=args.print,
+                  dry_run=args.dry_run,
                   source_dir=args.source_dir,
                   build_dir=args.build_dir)
 
tests/qemu-iotests/testenv.py +5 -0
index 9bf37cd381..952efa0e63 100644
@@ -178,6 +178,7 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
                  valgrind: bool = False,
                  gdb: bool = False,
                  qprint: bool = False,
+                 dry_run: bool = False,
                  source_dir: Optional[str] = None,
                  build_dir: Optional[str] = None) -> None:
         self.imgfmt = imgfmt
@@ -232,6 +233,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
         self.build_root = os.path.join(self.build_iotests, '..', '..')
 
         self.init_directories()
+
+        if dry_run:
+            return
+
         self.init_binaries()
 
         self.malloc_perturb_ = os.getenv('MALLOC_PERTURB_',
Signature · 1 line
2.39.2
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] iotests: allow test discovery before building

Quoted 42 lines · Daniel P. Berrangé

The 'check' script can be invoked in "dry run" mode, in which case it merely does test discovery and prints out all their names. Despite only doing test discovery it still validates that the various QEMU binaries can be found. This makes it impossible todo test discovery prior to building QEMU. This is a desirable feature to support, because it will let meson discover tests.

Fortunately the code in the TestEnv constructor is ordered in a way that makes this fairly trivial to achieve. We can just short circuit the constructor after the basic directory paths have been set.

---
  tests/qemu-iotests/check      | 1 +
  tests/qemu-iotests/testenv.py | 5 +++++
  2 files changed, 6 insertions(+)
tests/qemu-iotests/check +1 -0
index 806abc21d6..7e287a79a3 100755
@@ -129,6 +129,7 @@ if __name__ == '__main__':
                    imgopts=args.imgopts, misalign=args.misalign,
                    debug=args.debug, valgrind=args.valgrind,
                    gdb=args.gdb, qprint=args.print,
+                  dry_run=args.dry_run,
                    source_dir=args.source_dir,
                    build_dir=args.build_dir)
 
tests/qemu-iotests/testenv.py +1 -0
index 9bf37cd381..952efa0e63 100644
@@ -178,6 +178,7 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
                   valgrind: bool = False,
                   gdb: bool = False,
                   qprint: bool = False,
+                 dry_run: bool = False,
                   source_dir: Optional[str] = None,
                   build_dir: Optional[str] = None) -> None:
          self.imgfmt = imgfmt

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 242

Quoted 10 lines
tests/qemu-iotests/testenv.py +4 -0
@@ -232,6 +233,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
          self.build_root = os.path.join(self.build_iotests, '..', '..')
 
          self.init_directories()
+
+        if dry_run:
+            return
+
          self.init_binaries()
 
          self.malloc_perturb_ = os.getenv('MALLOC_PERTURB_',

This gives me a feeling of Deja-Vu:

https://lore.kernel.org/all/[email protected]/

... to bad that I never got that merged ;-)

Anyway:

Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] iotests: allow test discovery before building

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

The 'check' script can be invoked in "dry run" mode, in which case it merely does test discovery and prints out all their names. Despite only doing test discovery it still validates that the various QEMU binaries can be found. This makes it impossible todo test discovery prior to building QEMU. This is a desirable feature to support, because it will let meson discover tests.

Quoted 5 lines

Fortunately the code in the TestEnv constructor is ordered in a way that makes this fairly trivial to achieve. We can just short circuit the constructor after the basic directory paths have been set.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#7 lore raw

PATCH 3/5 iotests: strip subdir path when listing tests

In reply to Daniel P. Berrangé

When asking 'check' to list individual tests by invoking it in dry run mode, it prints the paths to the tests relative to the base of the I/O test directory.

When asking 'check' to run an individual test, however, it mandates that only the unqualified test name is given, without any path prefix. This inconsistency makes it harder to ask for a list of tests and then invoke each one.

Thus the test listing code is change to flatten the test names, by printing only the base name, which can be directly invoked.

---
 tests/qemu-iotests/check | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/check +1 -1
index 7e287a79a3..3a8744220a 100755
@@ -169,7 +169,7 @@ if __name__ == '__main__':
         sys.exit(str(e))
 
     if args.dry_run:
-        print('\n'.join(tests))
+        print('\n'.join([os.path.basename(t) for t in tests]))
     else:
         with TestRunner(env, tap=args.tap,
                         color=args.color) as tr:
Signature · 1 line
2.39.2
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] iotests: strip subdir path when listing tests

Quoted 9 lines · Daniel P. Berrangé

When asking 'check' to list individual tests by invoking it in dry run mode, it prints the paths to the tests relative to the base of the I/O test directory.

When asking 'check' to run an individual test, however, it mandates that only the unqualified test name is given, without any path prefix. This inconsistency makes it harder to ask for a list of tests and then invoke each one.

Quoted 4 lines

Thus the test listing code is change to flatten the test names, by printing only the base name, which can be directly invoked.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#9 lore raw

PATCH 4/5 iotests: print TAP protocol version when reporting tests

In reply to Daniel P. Berrangé

Recently meson started complaining that TAP test reports don't include the TAP protocol version. While this warning is bogus and has since been removed from Meson, it looks like good practice to include this header going forward. The GLib library test harness has started unconditionally printing the version, so this brings the I/O tests into line.

---
 tests/qemu-iotests/testrunner.py | 1 +
 1 file changed, 1 insertion(+)
tests/qemu-iotests/testrunner.py +1 -0
index 5a771da86e..e734800b3d 100644
@@ -391,6 +391,7 @@ def run_tests(self, tests: List[str], jobs: int = 1) -> bool:
         casenotrun = []
 
         if self.tap:
+            print('TAP version 13')
             self.env.print_env('# ')
             print('1..%d' % len(tests))
         else:
Signature · 1 line
2.39.2
Reviewed-by on v1 4/5
#10 lore raw

Re: [PATCH 4/5] iotests: print TAP protocol version when reporting tests

Quoted 16 lines · Daniel P. Berrangé

Recently meson started complaining that TAP test reports don't include the TAP protocol version. While this warning is bogus and has since been removed from Meson, it looks like good practice to include this header going forward. The GLib library test harness has started unconditionally printing the version, so this brings the I/O tests into line.

---
  tests/qemu-iotests/testrunner.py | 1 +
  1 file changed, 1 insertion(+)
tests/qemu-iotests/testrunner.py +0 -0
index 5a771da86e..e734800b3d 100644

tests/qemu-iotests/testrunner.py def run_tests(self, tests: List[str], jobs: int = 1) -> bool: · line 397

Quoted 7 lines
tests/qemu-iotests/testrunner.py +1 -0
@@ -391,6 +391,7 @@ def run_tests(self, tests: List[str], jobs: int = 1) -> bool:
          casenotrun = []
 
          if self.tap:
+            print('TAP version 13')
              self.env.print_env('# ')
              print('1..%d' % len(tests))
          else:
Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] iotests: print TAP protocol version when reporting tests

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

Recently meson started complaining that TAP test reports don't include the TAP protocol version. While this warning is bogus and has since been removed from Meson, it looks like good practice to include this header going forward. The GLib library test harness has started unconditionally printing the version, so this brings the I/O tests into line.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#12 lore raw

PATCH 5/5 iotests: register each I/O test separately with meson

In reply to Daniel P. Berrangé

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

---
 tests/qemu-iotests/meson.build | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
tests/qemu-iotests/meson.build +27 -6
index 323a4acb6a..48c82085af 100644
@@ -32,16 +32,37 @@ foreach k, v : emulators
   endif
 endforeach
 
+qemu_iotests_check_cmd = files('check')
+
 foreach format, speed: qemu_iotests_formats
   if speed == 'quick'
     suites = 'block'
   else
     suites = ['block-' + speed, speed]
   endif
-  test('qemu-iotests ' + format, sh, args: [files('../check-block.sh'), format],
-       depends: qemu_iotests_binaries, env: qemu_iotests_env,
-       protocol: 'tap',
-       suite: suites,
-       timeout: 0,
-       is_parallel: false)
+
+  args = ['-tap', '-' + format]
+  if speed == 'quick'
+      args += ['-g', 'auto']
+  endif
+
+  rc = run_command(
+      [qemu_iotests_check_cmd] + args + ['-n'],
+      check: true,
+  )
+
+  foreach item: rc.stdout().strip().split()
+      message('Adding test qemu-iotests-' + format + '-' + item)
+      args = ['-tap', '-' + format, item,
+              '--source-dir', meson.current_source_dir(),
+              '--build-dir', meson.current_build_dir()]
+      test('qemu-iotests-' + format + '-' + item,
+           qemu_iotests_check_cmd,
+           args: args,
+           is_parallel: false,
+           depends: qemu_iotests_binaries,
+           env: qemu_iotests_env,
+           protocol: 'tap',
+           suite: suites)
+  endforeach
 endforeach
Signature · 1 line
2.39.2
#13 lore raw

Re: [PATCH 5/5] iotests: register each I/O test separately with meson

Quoted 49 lines · Daniel P. Berrangé

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

---
  tests/qemu-iotests/meson.build | 33 +++++++++++++++++++++++++++------
  1 file changed, 27 insertions(+), 6 deletions(-)
tests/qemu-iotests/meson.build +5 -6
index 323a4acb6a..48c82085af 100644
@@ -32,16 +32,37 @@ foreach k, v : emulators
    endif
  endforeach
 
+qemu_iotests_check_cmd = files('check')
+
  foreach format, speed: qemu_iotests_formats
    if speed == 'quick'
      suites = 'block'
    else
      suites = ['block-' + speed, speed]
    endif
-  test('qemu-iotests ' + format, sh, args: [files('../check-block.sh'), format],
-       depends: qemu_iotests_binaries, env: qemu_iotests_env,
-       protocol: 'tap',
-       suite: suites,
-       timeout: 0,
-       is_parallel: false)
+
+  args = ['-tap', '-' + format]
+  if speed == 'quick'

tests/qemu-iotests/meson.build foreach k, v : emulators · line 55

Quoted 10 lines
tests/qemu-iotests/meson.build +10 -0
+      args += ['-g', 'auto']
+  endif
+
+  rc = run_command(
+      [qemu_iotests_check_cmd] + args + ['-n'],
+      check: true,
+  )
+
+  foreach item: rc.stdout().strip().split()
+      message('Adding test qemu-iotests-' + format + '-' + item)

This message spoils the output during "configure" quite a bit, please remove that line.

Apart from that, patch looks fine to me!

Thomas

Quoted 13 lines
tests/qemu-iotests/meson.build +12 -0
+      args = ['-tap', '-' + format, item,
+              '--source-dir', meson.current_source_dir(),
+              '--build-dir', meson.current_build_dir()]
+      test('qemu-iotests-' + format + '-' + item,
+           qemu_iotests_check_cmd,
+           args: args,
+           is_parallel: false,
+           depends: qemu_iotests_binaries,
+           env: qemu_iotests_env,
+           protocol: 'tap',
+           suite: suites)
+  endforeach
  endforeach
#14 lore raw

Re: [PATCH 5/5] iotests: register each I/O test separately with meson

Quoted 54 lines · Thomas Huth
Quoted 53 lines · Daniel P. Berrangé

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

---
  tests/qemu-iotests/meson.build | 33 +++++++++++++++++++++++++++------
  1 file changed, 27 insertions(+), 6 deletions(-)
tests/qemu-iotests/meson.build +10 -6
index 323a4acb6a..48c82085af 100644
@@ -32,16 +32,37 @@ foreach k, v : emulators
    endif
  endforeach
+qemu_iotests_check_cmd = files('check')
+
  foreach format, speed: qemu_iotests_formats
    if speed == 'quick'
      suites = 'block'
    else
      suites = ['block-' + speed, speed]
    endif
-  test('qemu-iotests ' + format, sh, args: [files('../check-block.sh'), format],
-       depends: qemu_iotests_binaries, env: qemu_iotests_env,
-       protocol: 'tap',
-       suite: suites,
-       timeout: 0,
-       is_parallel: false)
+
+  args = ['-tap', '-' + format]
+  if speed == 'quick'
+      args += ['-g', 'auto']
+  endif
+
+  rc = run_command(
+      [qemu_iotests_check_cmd] + args + ['-n'],
Quoted 8 lines

tests/qemu-iotests/meson.build foreach k, v : emulators · line 55

Quoted 5 lines
tests/qemu-iotests/meson.build +5 -0
+      check: true,
+  )
+
+  foreach item: rc.stdout().strip().split()
+      message('Adding test qemu-iotests-' + format + '-' + item)

This message spoils the output during "configure" quite a bit, please remove that line.

Yes, that wasn't supposed to be left it, it was me debugging :-)

Quoted 20 lines

Apart from that, patch looks fine to me!

Thomas

Quoted 13 lines
tests/qemu-iotests/meson.build +12 -0
+      args = ['-tap', '-' + format, item,
+              '--source-dir', meson.current_source_dir(),
+              '--build-dir', meson.current_build_dir()]
+      test('qemu-iotests-' + format + '-' + item,
+           qemu_iotests_check_cmd,
+           args: args,
+           is_parallel: false,
+           depends: qemu_iotests_binaries,
+           env: qemu_iotests_env,
+           protocol: 'tap',
+           suite: suites)
+  endforeach
  endforeach

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw
In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests

Another big benefit is that we get to see the execution time of every I/O test, so can identify which handful of tests are making it take almost 5 minutes to run in gitlab...

The really big 4 are:

199/314 qemu:block / qemu-iotests-qcow2-040   OK    16.62s   1 subtests passed
200/314 qemu:block / qemu-iotests-qcow2-041   OK    44.51s   1 subtests passed
265/314 qemu:block / qemu-iotests-qcow2-191   OK    17.93s   1 subtests passed
282/314 qemu:block / qemu-iotests-qcow2-271   OK    25.03s   1 subtests passed

there are a bunch in the ~5 second range, and then most are 1 second or less.

Quoted 50 lines

* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Compare contrast output from a current job:

https://gitlab.com/qemu-project/qemu/-/jobs/3863603546

[quote]
204/224 qemu:block / qemu-iotests qcow2 OK 329.94s 119 subtests passed
[/quote]

Vs what is seen with this series:

https://gitlab.com/berrange/qemu/-/jobs/3865975463

[quote]

204/350 qemu:block / qemu-iotests-qcow2-001   OK    2.16s   1 subtests passed
205/350 qemu:block / qemu-iotests-qcow2-002   OK    2.77s   1 subtests passed

...snip...

329/350 qemu:block / qemu-iotests-qcow2-qemu-img-close-errors OK 6.19s 1 subtests passed
330/350 qemu:block / qemu-iotests-qcow2-qsd-jobs OK 0.55s 1 subtests passed
[/quote]

A few tweaks were needed to the iotests runner because it had a few assumptions about it always running in a tree that has already been built, which is obviously not the case at the time meson does test discovery.

Daniel P. Berrangé (5):
iotests: explicitly pass source/build dir to 'check' command
iotests: allow test discovery before building
iotests: strip subdir path when listing tests
iotests: print TAP protocol version when reporting tests
iotests: register each I/O test separately with meson

Quoted 9 lines
 tests/qemu-iotests/check         | 11 +++++++++--
 tests/qemu-iotests/meson.build   | 33 ++++++++++++++++++++++++++------
 tests/qemu-iotests/testenv.py    | 22 +++++++++++++++++----
 tests/qemu-iotests/testrunner.py |  1 +
 4 files changed, 55 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.2

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#16 lore raw
In reply to Daniel P. Berrangé
Quoted 21 lines · Daniel P. Berrangé

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

Quoted 5 lines

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Great to see some movement in this area again!

Some questions/remarks:

1) Could you remove tests/check-block.sh now? See also:
https://lore.kernel.org/all/[email protected]/

2) With regards to parallel execution ... I think it should be possible nowadays - the "check" script is normally also run with the "-j" switch by the tests/check-block.sh script, so if you remove the possibility to run in parallel, it's a regression from the previous behavior!

3) When I tried this last year, I had a weird problem that the terminal sometimes gets messed up ... I wasn't able to track it down back then - could you check by running "make check-block" many times (>10 times) to see whether it happens with your series or not?

Thomas

#17 lore raw
Quoted 28 lines · Thomas Huth
Quoted 21 lines · Daniel P. Berrangé

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

Quoted 5 lines

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Quoted 6 lines

Great to see some movement in this area again!

Some questions/remarks:

1) Could you remove tests/check-block.sh now? See also:

   https://lore.kernel.org/all/[email protected]/

Possibly, I wasn't sure if that was wanted as a general entry point for humans, or was solely for meson ?

Quoted 5 lines

2) With regards to parallel execution ... I think it should be possible nowadays - the "check" script is normally also run with the "-j" switch by the tests/check-block.sh script, so if you remove the possibility to run in parallel, it's a regression from the previous behavior!

Hmmm, I got *masses* of test failures when running in parallel but I'll check again to be sure.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#18 lore raw
Quoted 39 lines · Daniel P. Berrangé
Quoted 28 lines · Thomas Huth
Quoted 21 lines · Daniel P. Berrangé

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

Quoted 5 lines

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Quoted 6 lines

Great to see some movement in this area again!

Some questions/remarks:

1) Could you remove tests/check-block.sh now? See also:

   https://lore.kernel.org/all/[email protected]/

Possibly, I wasn't sure if that was wanted as a general entry point for humans, or was solely for meson ?

Quoted 8 lines
Quoted 5 lines

2) With regards to parallel execution ... I think it should be possible nowadays - the "check" script is normally also run with the "-j" switch by the tests/check-block.sh script, so if you remove the possibility to run in parallel, it's a regression from the previous behavior!

Hmmm, I got *masses* of test failures when running in parallel but I'll check again to be sure.

Ooooh, the 'check' script only uses a unique sub-dir for tests when passing -j with a value >= 2. It also merely appends the test name, so it is still broken for anyone who runs multiple copies of 'check' in parallel for different configurations, even if they passed -j. It needs to just always use an isolated subdir no matter what, with process level uniqueness, not merely test.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#19 lore raw
In reply to Daniel P. Berrangé
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Thomas Huth
Quoted 21 lines · Daniel P. Berrangé

To just repeat the patch 5 description...

Currently meson registers a single test that invokes an entire group of I/O tests, hiding the test granularity from meson. There are various downsides of doing this

* You cannot ask 'meson test' to invoke a single I/O test
* The meson test timeout can't be applied to the individual tests
* Meson only gets a pass/fail for the overall I/O test group not individual tests
* If a CI job gets killed by the GitLab timeout, we don't get visibility into how far through the I/O tests execution got.

This is not really specific to the I/O tests, the problem is common to any case of us running a test which is in fact another test harness which runs many tests. It would be nice to have meson have the full view of all tests run. Adapting the I/O tests is as easy win in this respect.

Quoted 5 lines

This switches meson to perform test discovery by invoking 'check' in dry-run mode. It then registers one meson test case for each I/O test. Parallel execution remains disabled since the I/O tests do not use self contained execution environments and thus conflict with each other.

Great to see some movement in this area again!

Quoted 7 lines
Quoted 4 lines

Some questions/remarks:

1) Could you remove tests/check-block.sh now? See also:

    https://lore.kernel.org/all/[email protected]/

Possibly, I wasn't sure if that was wanted as a general entry point for humans, or was solely for meson ?

I think this script was only ever used for "make check-block", I never heard of anybody really using this script directly in a regular fashion. Humans rather run the tests/qemu-iotests/check script directly. Also see its origins:

https://gitlab.com/qemu-project/qemu/-/commit/b8c6f29eb84cd3ccbbf

HTH,
Thomas

#20 lore raw
In reply to Thomas Huth
Quoted 6 lines · Thomas Huth

On 02/03/2023 19.46, Daniel P. Berrangé wrote:
3) When I tried this last year, I had a weird problem that the terminal sometimes gets messed up ... I wasn't able to track it down back then - could you check by running "make check-block" many times (>10 times) to see whether it happens with your series or not?

I've just seen this - echo got disabled on my terminal.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#21 lore raw
Quoted 9 lines · Daniel P. Berrangé
Quoted 6 lines · Thomas Huth

On 02/03/2023 19.46, Daniel P. Berrangé wrote:
3) When I tried this last year, I had a weird problem that the terminal sometimes gets messed up ... I wasn't able to track it down back then - could you check by running "make check-block" many times (>10 times) to see whether it happens with your series or not?

I've just seen this - echo got disabled on my terminal.

The problem is that testrunner.py script doing

# We want to save current tty settings during test run,

# since an aborting qemu call may leave things screwed up.
@contextmanager
def savetty() -> Iterator[None]:
    isterm = sys.stdin.isatty()
    if isterm:
        fd = sys.stdin.fileno()
        attr = termios.tcgetattr(fd)

try:
yield
finally:
if isterm:
termios.tcsetattr(fd, termios.TCSADRAIN, attr)

When invoking 'check' this wraps around execution of the entire 'check' script. IOW it saves/restores the terminal once.

When we invoke 'check' in parallel it will save/restore the same terminal for each invokation.

If the 'termios.tcgetattr' call runs at the same time as there is a QEMU running which has put the terminal in raw mode, then when 'check' exits it'll "restore" the terminal to raw mode.

IOW, this savetty() logic is fundamentally unsafe when invoking 'check' in parallel.

AFAICT, the more reliable thing todo would be to spawn a new PTY when invoking each test, so there's no cleanup required. If QEMU aborts leaving the TTY messed up it dosn't matter was it was a temporary throwaway PTY.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#22 lore raw
Quoted 35 lines · Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé
Quoted 6 lines · Thomas Huth

On 02/03/2023 19.46, Daniel P. Berrangé wrote:
3) When I tried this last year, I had a weird problem that the terminal sometimes gets messed up ... I wasn't able to track it down back then - could you check by running "make check-block" many times (>10 times) to see whether it happens with your series or not?

I've just seen this - echo got disabled on my terminal.

The problem is that testrunner.py script doing

# We want to save current tty settings during test run,

# since an aborting qemu call may leave things screwed up.
@contextmanager
def savetty() -> Iterator[None]:
     isterm = sys.stdin.isatty()
     if isterm:
         fd = sys.stdin.fileno()
         attr = termios.tcgetattr(fd)

try:
yield
finally:
if isterm:
termios.tcsetattr(fd, termios.TCSADRAIN, attr)

When invoking 'check' this wraps around execution of the entire 'check' script. IOW it saves/restores the terminal once.

When we invoke 'check' in parallel it will save/restore the same terminal for each invokation.

Quoted 6 lines

If the 'termios.tcgetattr' call runs at the same time as there is a QEMU running which has put the terminal in raw mode, then when 'check' exits it'll "restore" the terminal to raw mode.

IOW, this savetty() logic is fundamentally unsafe when invoking 'check' in parallel.

Hmm, couldn't we e.g. also simply skip this termios stuff when running with "--tap" ?

Thomas

#23 lore raw
Quoted 40 lines · Thomas Huth
Quoted 39 lines · Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé
Quoted 6 lines · Thomas Huth

On 02/03/2023 19.46, Daniel P. Berrangé wrote:
3) When I tried this last year, I had a weird problem that the terminal sometimes gets messed up ... I wasn't able to track it down back then - could you check by running "make check-block" many times (>10 times) to see whether it happens with your series or not?

I've just seen this - echo got disabled on my terminal.

The problem is that testrunner.py script doing

# We want to save current tty settings during test run,

# since an aborting qemu call may leave things screwed up.
@contextmanager
def savetty() -> Iterator[None]:
     isterm = sys.stdin.isatty()
     if isterm:
         fd = sys.stdin.fileno()
         attr = termios.tcgetattr(fd)

try:
yield
finally:
if isterm:
termios.tcsetattr(fd, termios.TCSADRAIN, attr)

When invoking 'check' this wraps around execution of the entire 'check' script. IOW it saves/restores the terminal once.

When we invoke 'check' in parallel it will save/restore the same terminal for each invokation.

If the 'termios.tcgetattr' call runs at the same time as there is a QEMU running which has put the terminal in raw mode, then when 'check' exits it'll "restore" the terminal to raw mode.

Quoted 5 lines
Quoted 2 lines

IOW, this savetty() logic is fundamentally unsafe when invoking 'check' in parallel.

Hmm, couldn't we e.g. also simply skip this termios stuff when running with "--tap" ?

It actually turns out to be way simpler. We merely need to set stdin=subprocess.DEVNULL. There is no valid reason for the test cases to be reading for stdin, as that would block execution. By setting stdin==/dev/null, the isatty(0) checks will fail and thus QEMU won't mess with termios, and thus we don't need any save/restore dance either.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|