From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [PATCH 4/7] qapi: Speed up frontend tests
Date: Tue, 1 Oct 2019 15:23:22 -0500 [thread overview]
Message-ID: <9049db38-9698-a4f9-78af-c7b8f5a8a263@redhat.com> (raw)
In-Reply-To: <20191001191514.11208-5-armbru@redhat.com>
On 10/1/19 2:15 PM, Markus Armbruster wrote:
> "make check-qapi-schema" takes around 10s user + system time for me.
> With -j, it takes a bit over 3s real time. We have worse tests. It's
> still annoying when you work on the QAPI generator.
All true :)
> test-qapi.py is designed to be the simplest possible building block
> for a shell script to do the complete job (it's actually a Makefile,
> not a shell script; no real difference). Python is just not meant for
> that. It's for bigger blocks.
>
> Move the post-processing and diffing into test-qapi.py, and make it
> capable of testing multiple schema files.
Sounds reasonable.
>
> Running it once per test case now takes slightly longer than 8s. But
> running it once for all of them takes under 0.2s.
>
> Messing with the Makefile to run it only on the tests that need
> retesting is clearly not worth the bother.
>
> Expected error output changes because the new normalization strips off
> $(SRCDIR)/tests/qapi-schema/ instead of just $(SRCDIR)/.
>
> The .exit files go away, because there is no exit status to test
> anymore.
So the bulk of the patch is the mechanical fallout.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> tests/Makefile.include | 16 +--
> tests/qapi-schema/test-qapi.py | 119 +++++++++++++++---
while these are the interesting parts. (Using git diff -O path/to/file
with a listing that floats those two files to the top of the diff would
ease review slightly)
> 364 files changed, 413 insertions(+), 515 deletions(-)
> delete mode 100644 tests/qapi-schema/struct-member-invalid.exit
> mode change 100644 => 100755 tests/qapi-schema/test-qapi.py
I'm guessing this one is intentional.
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 214fbd941c..1b24b8ba10 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -1102,17 +1102,11 @@ check-tests/check-block.sh: tests/check-block.sh qemu-img$(EXESUF) \
> $(patsubst %,%/all,$(filter %-softmmu,$(TARGET_DIRS)))
> @$<
>
> -.PHONY: $(patsubst %, check-%, $(check-qapi-schema-y))
> -$(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json
> +.PHONY: check-tests/qapi-schema/frontend
> +check-tests/qapi-schema/frontend: $(addprefix $(SRC_PATH)/, $(check-qapi-schema-y))
> $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts \
> - PYTHONIOENCODING=utf-8 $(PYTHON) $(SRC_PATH)/tests/qapi-schema/test-qapi.py \
> - $^ >$*.test.out 2>$*.test.err; \
> - echo $$? >$*.test.exit, \
> - "TEST","$*.out")
> - @# Sanitize error messages (make them independent of build directory)
> - @perl -p -e 's|\Q$(SRC_PATH)\E/||g' $*.test.err | diff -u $(SRC_PATH)/$*.err -
> - @diff -u $(SRC_PATH)/$*.out $*.test.out
> - @diff -u $(SRC_PATH)/$*.exit $*.test.exit
> + PYTHONIOENCODING=utf-8 $(PYTHON) $(SRC_PATH)/tests/qapi-schema/test-qapi.py $^, \
> + TEST, check-qapi-schema)
>
So instead of one $(call $(PYTHON)) per test, it is now one call for all
files at once.
> +++ b/tests/qapi-schema/allow-preconfig-test.err
> @@ -1,2 +1,2 @@
> -tests/qapi-schema/allow-preconfig-test.json: In command 'allow-preconfig-test':
> -tests/qapi-schema/allow-preconfig-test.json:2: flag 'allow-preconfig' may only use true value
> +allow-preconfig-test.json: In command 'allow-preconfig-test':
> +allow-preconfig-test.json:2: flag 'allow-preconfig' may only use true value
Normalization to strip off a longer prefix could have been done in a
separate patch, but it doesn't matter.
> +++ b/tests/qapi-schema/test-qapi.py
> @@ -1,3 +1,4 @@
> +#!/usr/bin/env python
> #
> # QAPI parser test harness
> #
> @@ -11,7 +12,14 @@
> #
>
> from __future__ import print_function
> +import argparse
> +import difflib
> +import os
> import sys
> +if sys.version_info[0] < 3:
> + from cStringIO import StringIO
> +else:
> + from io import StringIO
I guess we can't get rid of Python 2 during 'make check' just yet?
> +
> + print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'),
> + file=sys.stderr)
> + out_diff = difflib.unified_diff(expected_out, actual_out, outfp.name)
> + err_diff = difflib.unified_diff(expected_err, actual_err, errfp.name)
> + sys.stdout.writelines(out_diff)
> + sys.stdout.writelines(err_diff)
> +
> + if not update:
> + return 1
> +
> + try:
> + outfp.truncate(0)
> + outfp.seek(0)
> + outfp.writelines(actual_out)
Handy for mass-rebuilding of the directory after an error message tweak.
> +def main(argv):
> + parser = argparse.ArgumentParser(
> + description='QAPI schema tester')
> + parser.add_argument('-d', '--dir', action='store', default='',
> + help="directory containing tests")
> + parser.add_argument('-u', '--update', action='store_true',
> + help="update expected test results")
> + parser.add_argument('tests', nargs='*', metavar='TEST', action='store')
> + args = parser.parse_args()
> +
No --help mode? Not strictly necessary, but can be useful.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2019-10-01 21:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 19:15 [PATCH 0/7] qapi: Cleanups and test speedup Markus Armbruster
2019-10-01 19:15 ` [PATCH 1/7] qapi: Don't suppress doc generation without pragma doc-required Markus Armbruster
2019-10-01 19:59 ` Eric Blake
2019-10-01 19:15 ` [PATCH 2/7] qapi: Store pragma state in QAPISourceInfo, not global state Markus Armbruster
2019-10-01 20:01 ` Eric Blake
2019-10-01 19:15 ` [PATCH 3/7] qapi: Eliminate accidental global frontend state Markus Armbruster
2019-10-01 20:03 ` Eric Blake
2019-10-01 19:15 ` [PATCH 4/7] qapi: Speed up frontend tests Markus Armbruster
2019-10-01 20:23 ` Eric Blake [this message]
2019-10-02 14:31 ` Markus Armbruster
2019-10-01 19:15 ` [PATCH 5/7] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py Markus Armbruster
2019-10-01 20:26 ` Eric Blake
2019-10-01 19:15 ` [PATCH 6/7] qapi: Split up scripts/qapi/common.py Markus Armbruster
2019-10-01 21:19 ` Eric Blake
2019-10-02 15:16 ` Markus Armbruster
2019-10-02 15:27 ` Eric Blake
2019-10-02 16:13 ` Markus Armbruster
2019-10-16 13:05 ` Kevin Wolf
2019-10-16 14:09 ` Markus Armbruster
2019-10-01 19:15 ` [PATCH 7/7] qapi: Clear scripts/qapi/doc.py executable bits again Markus Armbruster
2019-10-01 20:34 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9049db38-9698-a4f9-78af-c7b8f5a8a263@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).