From: Eric Blake <eblake@redhat.com>
To: Sascha Silbe <silbe@linux.vnet.ibm.com>,
Max Reitz <mreitz@redhat.com>,
qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org
Cc: Tu Bo <tubo@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-iotests: add _filter_qmp_events() for filtering out QMP events
Date: Wed, 10 Feb 2016 15:14:35 -0700 [thread overview]
Message-ID: <56BBB64B.7060401@redhat.com> (raw)
In-Reply-To: <87pow4cs8t.fsf@oc4731375738.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 2031 bytes --]
On 02/10/2016 11:52 AM, Sascha Silbe wrote:
> Dear Max,
>
> Max Reitz <mreitz@redhat.com> writes:
>
>>> +# remove QMP events from output
>>> +_filter_qmp_events()
>>> +{
>>> + sed -e '/^{\(.*, \)"event": ".*}$/ d'
>>> +}
>>
>> There is a pretty good reason test 067 uses -qmp-pretty (as you yourself
>> say, the lines get pretty long otherwise, and if we have any change
>> within, the whole line needs to be changed).
>
> Additionally, it's a lot easier to read when indented properly,
> especially with the block info containing nested dicts.
>
>> Using the following ugly
>> piece of code here instead, we would still be able to use it:
>>
>> tr '\n' '\t' \
>> | sed -e
>> 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g'
>> \
>> | tr '\t' '\n'
>
> Nice trick. Why didn't I come up with it? ;)
Mishandles any event whose data includes nested dicts. But a little bit
more creativity can do it in two passes (the first modifies the stream
to mark the start of an event, the second then does multiline matching
to nuke the entire event):
tr '\n' '\t' |
sed 's/^{\(\s*"timestamp":\s*{[^}]*},\s*"event":\)/{MARK\1/g' |
tr '\t' '\n' |
sed '/^{MARK/,/^}/d'
> It definitely is a bit ugly, though. We can't just drop the entire line
> (using "d") as the entire stream now is a single line. Matching
> parenthesis pairs is context sensitive, so we can't just use regular
> expressions to aggregate results into lines. And before I start
> implementing a JSON indenter in awk, I'd rather rewrite the whole test
> in Python. So if we stay with the shell test for now, we need something
> like your incantation above. It's not perfect, but good enough for now
> and I can't think of anything significantly simpler right now either.
>
> Will test your version and send a v2. Thanks for the suggestion!
>
> Sascha
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-02-10 22:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-09 13:23 [Qemu-devel] [PATCH 0/2] qemu-iotests: fix 067 on s390x Sascha Silbe
2016-02-09 13:23 ` [Qemu-devel] [PATCH 1/2] qemu-iotests: add _filter_qmp_events() for filtering out QMP events Sascha Silbe
2016-02-10 16:43 ` Max Reitz
2016-02-10 18:52 ` Sascha Silbe
2016-02-10 22:14 ` Eric Blake [this message]
2016-02-11 16:54 ` Sascha Silbe
2016-02-09 13:23 ` [Qemu-devel] [PATCH 2/2] qemu-iotests: 067: ignore " Sascha Silbe
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=56BBB64B.7060401@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=silbe@linux.vnet.ibm.com \
--cc=tubo@linux.vnet.ibm.com \
/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).