Replace custom test harness with "meson test"
Subsystems (2)
cover Replace custom test harness with "meson test"
Hi all,
Starting with Meson 0.57, "meson test" has all features of QEMU's makefile-based harness and more. In particular, some features that were added to reach feature parity are:
* print reproducer command line for each failed test right below the test
* keep the output of multiple (non-TAP) tests together in verbose mode, similar to "make --output-sync target"
* report on TAP subtests as they are encountered
It also includes nicer handling of test interruption, logging of the run in the meson-logs/ subdirectory, and a progress report/spinner. For these reasons it would be nice to adopt it and remove the Perl scripts that we have to present TAP output nicely. While at it, this series also changes qemu-iotests to be described in tests/qemu-iotests/meson.build and it replaces the current "-makecheck" output style with TAP.
This is an RFC just to let people try it out and because I still haven't sorted out timeouts (e.g. OpenBSD is insanely slow on some tests). But in theory, if you want to try it out, the only things you need to know are:
* while "make check" does not timeout tests like it doesn't right now, "meson test" does respect timeouts, so you could get failures because of that. That can and probably will change from RFC to final.
* CTRL+C will only interrupt the longest running test. Pressing CTRL+C repeatedly three times (which you would likely do anyway, that's how things work) interrupts the whole run
* Right now "make check-block" only does a single test run just like "../tests/check-block.sh", but it would be possible to add the thorough suite to "meson test --suite block" as well.
* If you were using make check-report.tap and similar, they are replaced by targets like make check-report.junit.xml. This is because Gitlab is able to parse the resulting XML and include on the website a report of which tests failed.
An example of non-verbose "make check" output is available at
https://gitlab.com/bonzini/qemu/-/jobs/1680980620. A verbose run instead is like https://asciinema.org/a/e5irnEszSnAheOHM30exbo3F6
(does not include check-block).
Paolo
Paolo Bonzini (4):
build: use "meson test" as the test harness
build: make check-block a meson test
check-block: replace -makecheck with TAP output
configure: remove dead EXESUF variable
.gitlab-ci.d/crossbuild-template.yml | 2 +- Makefile | 3 +- configure | 3 - meson.build | 5 +- scripts/mtest2make.py | 111 +++----- scripts/tap-driver.pl | 379 --------------------------- scripts/tap-merge.pl | 111 -------- tests/Makefile.include | 15 +- tests/check-block.sh | 28 +- tests/fp/meson.build | 2 +- tests/meson.build | 1 + tests/qemu-iotests/check | 6 +- tests/qemu-iotests/meson.build | 14 + tests/qemu-iotests/testenv.py | 30 +-- tests/qemu-iotests/testrunner.py | 48 ++-- 15 files changed, 121 insertions(+), 637 deletions(-) delete mode 100755 scripts/tap-driver.pl delete mode 100755 scripts/tap-merge.pl create mode 100644 tests/qemu-iotests/meson.build
Signature · 1 line
2.31.1
PATCH 1/4 build: use "meson test" as the test harness
"meson test" starting with version 0.57 is just as capable and easy to use as QEMU's own TAP driver. All existing options for "make check" work. The only required code change involves how to mark "slow" tests.
scripts/mtest2make.py is changed to invoke "meson test" using a trick similar to how the Makefile already invokes ninja, i.e. turning the MAKECMDGOALS into command line options. Tests and their dependencies are still rebuilt correctly before "meson test" is run.
The rules for .tap output are replaced by JUnit XML; GitLab is able to parse that output and present it in the CI pipeline report.
--- Makefile | 3 +- meson.build | 5 +- scripts/mtest2make.py | 105 ++++-------- scripts/tap-driver.pl | 379 ------------------------------------------ scripts/tap-merge.pl | 111 ------------- tests/fp/meson.build | 2 +- 6 files changed, 42 insertions(+), 563 deletions(-) delete mode 100755 scripts/tap-driver.pl delete mode 100755 scripts/tap-merge.pl
Makefile +2 -1
@@ -145,7 +145,8 @@ NINJAFLAGS = $(if $V,-v) $(if $(MAKE.n), -n) $(if $(MAKE.k), -k0) \ $(filter-out -j, $(lastword -j1 $(filter -l% -j%, $(MAKEFLAGS)))) \ ninja-cmd-goals = $(or $(MAKECMDGOALS), all) -ninja-cmd-goals += $(foreach t, $(.tests), $(.test.deps.$t)) +ninja-cmd-goals += $(foreach t, $(.check.build-suites) $(.check.mtest-suites), $(.check-$t.deps)) +ninja-cmd-goals += $(foreach t, $(.bench.build-suites) $(.check.mtest-suites), $(.bench-$t.deps)) makefile-targets := build.ninja ctags TAGS cscope dist clean uninstall # "ninja -t targets" also lists all prerequisites. If build system
meson.build +4 -1
@@ -1,8 +1,11 @@ project('qemu', ['c'], meson_version: '>=0.58.2', default_options: ['warning_level=1', 'c_std=gnu11', 'cpp_std=gnu++11', 'b_colorout=auto', - 'b_staticpic=false'], + 'b_staticpic=false', 'stdsplit=false'], version: files('VERSION')) +add_test_setup('quick', exclude_suites: 'slow', is_default: true) +add_test_setup('slow', env: ['G_TEST_SLOW=1']) + not_found = dependency('', required: false) keyval = import('keyval') ss = import('sourceset')
scripts/mtest2make.py +35 -70
141 lines not on this page · raw message
scripts/tap-driver.pl deleted +0 -379
379 lines not on this page · raw message
scripts/tap-merge.pl deleted +0 -111
111 lines not on this page · raw message
tests/fp/meson.build +1 -1
@@ -622,7 +622,7 @@ test('fp-test-mulAdd', fptest, # no fptest_rounding_args args: fptest_args + ['f16_mulAdd', 'f32_mulAdd', 'f64_mulAdd', 'f128_mulAdd'], - suite: ['softfloat-slow', 'softfloat-ops-slow'], timeout: 90) + suite: ['softfloat', 'softfloat-ops', 'slow'], timeout: 90) fpbench = executable( 'fp-bench',
Signature · 1 line
2.31.1
PATCH 2/4 build: make check-block a meson test
In reply to Paolo Bonzini"meson test" supports can be asked to run tests verbosely. This makes it usable also for qemu-iotests's own harness.
This lets "make check-block" reuse mtest2make.py's infrastructure to find and build test dependencies. In the future, it will also enable producing TAP output, for consistency with all other "make check" tests.
--- meson.build | 4 ++-- scripts/mtest2make.py | 8 +++++++- tests/Makefile.include | 15 ++------------- tests/check-block.sh | 26 ++++++++++++-------------- tests/meson.build | 1 + tests/qemu-iotests/meson.build | 13 +++++++++++++ 6 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 tests/qemu-iotests/meson.build
meson.build +2 -2
@@ -3,8 +3,8 @@ project('qemu', ['c'], meson_version: '>=0.58.2', 'b_staticpic=false', 'stdsplit=false'], version: files('VERSION')) -add_test_setup('quick', exclude_suites: 'slow', is_default: true) -add_test_setup('slow', env: ['G_TEST_SLOW=1']) +add_test_setup('quick', exclude_suites: ['block', 'slow'], is_default: true) +add_test_setup('slow', exclude_suites: ['block'], env: ['G_TEST_SLOW=1']) not_found = dependency('', required: false) keyval = import('keyval')
scripts/mtest2make.py +7 -1
@@ -64,13 +64,15 @@ def emit_prolog(suites, prefix): print(f'{prefix}-report.junit.xml $(all-{prefix}-xml): {prefix}-report%.junit.xml: run-ninja') print(f'\t$(MAKE) {prefix}$* MTESTARGS="$(MTESTARGS) --logbase {prefix}-report$*" && ln -f meson-logs/$@ .') -def emit_suite(name, suite, prefix): +def emit_suite_deps(name, suite, prefix): deps = ' '.join(suite.deps) print(f'.{prefix}-{name}.deps = {deps}') print(f'ifneq ($(filter {prefix}-build, $(MAKECMDGOALS)),)') print(f'.{prefix}.build-suites += {name}') print(f'endif') +def emit_suite(name, suite, prefix): + emit_suite_deps(name, suite, prefix) targets = f'{prefix}-{name} {prefix}-report-{name}.junit.xml {prefix} {prefix}-report.junit.xml' print(f'ifneq ($(filter {targets}, $(MAKECMDGOALS)),)') print(f'.{prefix}.mtest-suites += {name}')
@@ -82,6 +84,10 @@ def emit_suite(name, suite, prefix): testsuites = defaultdict(Suite) for test in introspect['tests']: process_tests(test, targets, testsuites) +# HACK: check-block is a separate target so that it runs with --verbose; +# only write the dependencies +emit_suite_deps('block', testsuites['block'], 'check') +del testsuites['block'] emit_prolog(testsuites, 'check') for name, suite in testsuites.items(): emit_suite(name, suite, 'check')
tests/Makefile.include +2 -13
@@ -149,19 +149,8 @@ check: ifeq ($(CONFIG_TOOLS)$(CONFIG_POSIX),yy) check: check-block -export PYTHON - -ifneq ($(filter check check-block check-build, $(MAKECMDGOALS)),) -ninja-cmd-goals += \ - qemu-img$(EXESUF) \ - qemu-io$(EXESUF) \ - qemu-nbd$(EXESUF) \ - storage-daemon/qemu-storage-daemon$(EXESUF) \ - $(filter qemu-system-%, $(ninja-targets)) -endif - -check-block: $(SRC_PATH)/tests/check-block.sh run-ninja - @$< +check-block: run-ninja + $(MESON) test --no-rebuild --verbose --num-processes 1 --suite block endif check-build: run-ninja
tests/check-block.sh +12 -14
@@ -16,9 +16,13 @@ if [ "$#" -ne 0 ]; then format_list="$@" fi +skip() { + echo "$*" + exit 77 +} + if grep -q "CONFIG_GPROF=y" config-host.mak 2>/dev/null ; then - echo "GPROF is enabled ==> Not running the qemu-iotests." - exit 0 + skip "GPROF is enabled ==> Not running the qemu-iotests." fi # Disable tests with any sanitizer except for specific ones
@@ -36,36 +40,30 @@ for j in ${ALLOWED_SANITIZE_FLAGS}; do done if echo ${SANITIZE_FLAGS} | grep -q "\-fsanitize" 2>/dev/null; then # Have a sanitize flag that is not allowed, stop - echo "Sanitizers are enabled ==> Not running the qemu-iotests." - exit 0 + skip "Sanitizers are enabled ==> Not running the qemu-iotests." fi if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then - echo "No qemu-system binary available ==> Not running the qemu-iotests." - exit 0 + skip "No qemu-system binary available ==> Not running the qemu-iotests." fi if ! command -v bash >/dev/null 2>&1 ; then - echo "bash not available ==> Not running the qemu-iotests." - exit 0 + skip "bash not available ==> Not running the qemu-iotests." fi if LANG=C bash --version | grep -q 'GNU bash, version [123]' ; then - echo "bash version too old ==> Not running the qemu-iotests." - exit 0 + skip "bash version too old ==> Not running the qemu-iotests." fi if ! (sed --version | grep 'GNU sed') > /dev/null 2>&1 ; then if ! command -v gsed >/dev/null 2>&1; then - echo "GNU sed not available ==> Not running the qemu-iotests." - exit 0 + skip "GNU sed not available ==> Not running the qemu-iotests." fi else # Double-check that we're not using BusyBox' sed which says # that "This is not GNU sed version 4.0" ... if sed --version | grep -q 'not GNU sed' ; then - echo "BusyBox sed not supported ==> Not running the qemu-iotests." - exit 0 + skip "BusyBox sed not supported ==> Not running the qemu-iotests." fi fi
tests/meson.build +1 -0
@@ -1,6 +1,7 @@ py3 = import('python').find_installation() subdir('bench') +subdir('qemu-iotests') test_qapi_outputs = [ 'qapi-builtin-types.c',
tests/qemu-iotests/meson.build new file +13 -0
@@ -0,0 +1,13 @@ +if have_tools + qemu_iotests_binaries = [qemu_img, qemu_io, qemu_nbd, qsd] + foreach k, v : emulators + if k.startswith('qemu-system-') + qemu_iotests_binaries += v + endif + endforeach + test('qemu-iotests', sh, args: [files('../check-block.sh')], + depends: qemu_iotests_binaries, + suite: 'block', + timeout: 0, + is_parallel: false) +endif
Signature · 1 line
2.31.1
PATCH 3/4 check-block: replace -makecheck with TAP output
In reply to Paolo BonziniLet "meson test" take care of showing the results of the individual tests, consistently with other output from "make check V=1". Use TAP comments so that the environment is included in the logs.
--- tests/check-block.sh | 6 ++-- tests/qemu-iotests/check | 6 ++-- tests/qemu-iotests/meson.build | 1 + tests/qemu-iotests/testenv.py | 30 ++++++++++---------- tests/qemu-iotests/testrunner.py | 48 ++++++++++++++++---------------- 5 files changed, 46 insertions(+), 45 deletions(-)
tests/check-block.sh +3 -3
@@ -17,8 +17,8 @@ if [ "$#" -ne 0 ]; then fi skip() { - echo "$*" - exit 77 + echo "1..0 #SKIP $*" + exit 0 } if grep -q "CONFIG_GPROF=y" config-host.mak 2>/dev/null ; then
@@ -75,7 +75,7 @@ export PYTHONUTF8=1 ret=0 for fmt in $format_list ; do - ${PYTHON} ./check -makecheck -$fmt $group || ret=1 + ${PYTHON} ./check -tap -$fmt $group || ret=1 done exit $ret
tests/qemu-iotests/check +3 -3
@@ -32,8 +32,8 @@ def make_argparser() -> argparse.ArgumentParser: p.add_argument('-n', '--dry-run', action='store_true', help='show me, do not run tests') - p.add_argument('-makecheck', action='store_true', - help='pretty print output for make check') + p.add_argument('-tap', action='store_true', + help='produce TAP output') p.add_argument('-d', dest='debug', action='store_true', help='debug') p.add_argument('-p', dest='print', action='store_true',
@@ -161,7 +161,7 @@ if __name__ == '__main__': if args.dry_run: print('\n'.join(tests)) else: - with TestRunner(env, makecheck=args.makecheck, + with TestRunner(env, tap=args.tap, color=args.color) as tr: paths = [os.path.join(env.source_iotests, t) for t in tests] ok = tr.run_tests(paths)
tests/qemu-iotests/meson.build +1 -0
@@ -7,6 +7,7 @@ if have_tools endforeach test('qemu-iotests', sh, args: [files('../check-block.sh')], depends: qemu_iotests_binaries, + protocol: 'tap', suite: 'block', timeout: 0, is_parallel: false)
tests/qemu-iotests/testenv.py +15 -15
@@ -287,21 +287,21 @@ def __enter__(self) -> 'TestEnv': def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: self.close() - def print_env(self) -> None: + def print_env(self, prefix='') -> None: template = """\ -QEMU -- "{QEMU_PROG}" {QEMU_OPTIONS} -QEMU_IMG -- "{QEMU_IMG_PROG}" {QEMU_IMG_OPTIONS} -QEMU_IO -- "{QEMU_IO_PROG}" {QEMU_IO_OPTIONS} -QEMU_NBD -- "{QEMU_NBD_PROG}" {QEMU_NBD_OPTIONS} -IMGFMT -- {IMGFMT}{imgopts} -IMGPROTO -- {IMGPROTO} -PLATFORM -- {platform} -TEST_DIR -- {TEST_DIR} -SOCK_DIR -- {SOCK_DIR} -GDB_OPTIONS -- {GDB_OPTIONS} -VALGRIND_QEMU -- {VALGRIND_QEMU} -PRINT_QEMU_OUTPUT -- {PRINT_QEMU} -""" +{prefix}QEMU -- "{QEMU_PROG}" {QEMU_OPTIONS} +{prefix}QEMU_IMG -- "{QEMU_IMG_PROG}" {QEMU_IMG_OPTIONS} +{prefix}QEMU_IO -- "{QEMU_IO_PROG}" {QEMU_IO_OPTIONS} +{prefix}QEMU_NBD -- "{QEMU_NBD_PROG}" {QEMU_NBD_OPTIONS} +{prefix}IMGFMT -- {IMGFMT}{imgopts} +{prefix}IMGPROTO -- {IMGPROTO} +{prefix}PLATFORM -- {platform} +{prefix}TEST_DIR -- {TEST_DIR} +{prefix}SOCK_DIR -- {SOCK_DIR} +{prefix}GDB_OPTIONS -- {GDB_OPTIONS} +{prefix}VALGRIND_QEMU -- {VALGRIND_QEMU} +{prefix}PRINT_QEMU_OUTPUT -- {PRINT_QEMU} +{prefix}""" args = collections.defaultdict(str, self.get_env())
@@ -310,5 +310,5 @@ def print_env(self) -> None: u = os.uname() args['platform'] = f'{u.sysname}/{u.machine} {u.nodename} {u.release}' - + args['prefix'] = prefix print(template.format_map(args))
tests/qemu-iotests/testrunner.py +24 -24
85 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 4/4 configure: remove dead EXESUF variable
In reply to Paolo Bonzini--- .gitlab-ci.d/crossbuild-template.yml | 2 +- configure | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-)
.gitlab-ci.d/crossbuild-template.yml +1 -1
@@ -12,7 +12,7 @@ mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS" - make -j$(expr $(nproc) + 1) all check-build $MAKE_CHECK_ARGS - - if grep -q "EXESUF=.exe" config-host.mak; + - if test -f qemu-io.exe; then make installer; version="$(git describe --match v[0-9]*)"; mv -v qemu-setup*.exe qemu-setup-${version}.exe;
configure +0 -3
@@ -308,7 +308,6 @@ fortify_source="$default_feature" strip_opt="yes" mingw32="no" gcov="no" -EXESUF="" modules="no" module_upgrades="no" prefix="/usr/local"
@@ -713,7 +712,6 @@ else fi if test "$mingw32" = "yes" ; then - EXESUF=".exe" # MinGW needs -mthreads for TLS and macro _MT. CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS" write_c_skeleton;
@@ -3814,7 +3812,6 @@ echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak echo "GLIB_LIBS=$glib_libs" >> $config_host_mak echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak -echo "EXESUF=$EXESUF" >> $config_host_mak echo "LIBS_QGA=$libs_qga" >> $config_host_mak if test "$rng_none" = "yes"; then
Signature · 1 line
2.31.1
Re: [PATCH 4/4] configure: remove dead EXESUF variable
Quoted 5 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- .gitlab-ci.d/crossbuild-template.yml | 2 +- configure | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-)
Maybe squash in patch #2 or place as #3 mentioning "the previous commit"?
Re: [PATCH 4/4] configure: remove dead EXESUF variable
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- .gitlab-ci.d/crossbuild-template.yml | 2 +- configure | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-)Maybe squash in patch #2 or place as #3 mentioning "the previous commit"?
Anywhere you place it it's wrong. :) Squashing in #2 I dislike because of the functional change in .gilab-ci.d (in truth, the variable is *almost* dead!). Having the change as #4 makes it survive one patch longer than it should, on the other hand having it as #3 separates similar changes to "check-block.sh".
What I will actually do in the final submission is not include the TAP patch and submit it separately. Then for this one I can indeed add that it was used only in the implementation of check-block.
Paolo
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 4/4] configure: remove dead EXESUF variable
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>---
.gitlab-ci.d/crossbuild-template.yml| 2 +-
configure | 3 ---2 files changed, 1 insertion(+), 4 deletions(-)
Quoted 8 lines
Quoted 2 lines
Maybe squash in patch #2 or place as #3 mentioning "the previous commit"?
Anywhere you place it it's wrong. :) Squashing in #2 I dislike because of the functional change in .gilab-ci.d (in truth, the variable is *almost* dead!). Having the change as #4 makes it survive one patch longer than it should, on the other hand having it as #3 separates similar changes to "
check-block.sh".
Indeed.
Quoted 3 lines
What I will actually do in the final submission is not include the TAP patch and submit it separately. Then for this one I can indeed add that it was used only in the implementation of check-block.
OK then,
Quoted 4 lines · Paolo Bonzini
Hi all,
Starting with Meson 0.57, "meson test" has all features of QEMU's makefile-based harness and more.
I just gave it a try, and basically I like this ... but I also encountered two issues:
Quoted 3 lines
* CTRL+C will only interrupt the longest running test. Pressing CTRL+C repeatedly three times (which you would likely do anyway, that's how things work) interrupts the whole run
I tried this, and while hitting CTRL-C multiple times brought me back to the shell prompt, the remaining tests kept getting started in the background instead of getting stopped ... something is still fishy here, I think.
Quoted 3 lines
* Right now "make check-block" only does a single test run just like "
../tests/check-block.sh", but it would be possible to add the thorough suite to "meson test --suite block" as well.
The output of the iotests is also not optimal yet... when running "make check SPEED=slow", the iotests are run multiple times with different target image types, but each run prints the same "▶ 1/1 test 001 OK" etc. to the console, so it's hard to say which target type is currently exercised. Would it be possible to include the target image type here, e.g. something like:
▶ 1/1 test-qcow2 001 OK
?
Thomas
Quoted 5 lines · Thomas Huth
Quoted 3 lines
* CTRL+C will only interrupt the longest running test. Pressing CTRL+C repeatedly three times (which you would likely do anyway, that's how things work) interrupts the whole run
I tried this, and while hitting CTRL-C multiple times brought me back to the shell prompt, the remaining tests kept getting started in the background instead of getting stopped ... something is still fishy here, I think.
Ok, I checked that out. Looks like CTRL+C magic and "make -j" are incompatible. :/ So this will have to wait a bit more, but in the meanwhile people can already use "meson test" if they want.
Quoted 5 lines
Quoted 3 lines
* Right now "make check-block" only does a single test run just like "
../tests/check-block.sh", but it would be possible to add the thorough suite to "meson test --suite block" as well.The output of the iotests is also not optimal yet... when running "make check SPEED=slow", the iotests are run multiple times with different target image types, but each run prints the same "▶ 1/1 test 001 OK" etc. to the console, so it's hard to say which target type is currently exercised. Would it be possible to include the target image type here, e.g. something like:
Yes, that's trivial:
tests/qemu-iotests/testrunner.py +3 -3
@@ -163,11 +163,11 @@ def test_print_one_line(self, test: str, starttime: str, if self.tap: if status == 'pass': - print(f'ok test {test}') + print(f'ok {self.env.imgfmt} {test}') elif status == 'fail': - print(f'not ok test {test}') + print(f'not ok {self.env.imgfmt} {test}') elif status == 'not run': - print(f'ok test {test} # SKIP') + print(f'ok {self.env.imgfmt} {test} # SKIP') return if lasttime:
In fact, that's exactly what was printed in the non-TAP case. Thanks for the feedback, even though it was bad! :)
Paolo