From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTd24-0000b1-Iv for qemu-devel@nongnu.org; Wed, 10 Feb 2016 17:14:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTd23-0002dy-CT for qemu-devel@nongnu.org; Wed, 10 Feb 2016 17:14:44 -0500 References: <1455024190-105823-1-git-send-email-silbe@linux.vnet.ibm.com> <1455024190-105823-2-git-send-email-silbe@linux.vnet.ibm.com> <56BB68CA.6080508@redhat.com> <87pow4cs8t.fsf@oc4731375738.ibm.com> From: Eric Blake Message-ID: <56BBB64B.7060401@redhat.com> Date: Wed, 10 Feb 2016 15:14:35 -0700 MIME-Version: 1.0 In-Reply-To: <87pow4cs8t.fsf@oc4731375738.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jXFBRkrXOdAtK7khmawlowAQ1AncXL6NX" Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-iotests: add _filter_qmp_events() for filtering out QMP events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sascha Silbe , Max Reitz , qemu-devel@nongnu.org, Kevin Wolf , qemu-block@nongnu.org Cc: Tu Bo This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --jXFBRkrXOdAtK7khmawlowAQ1AncXL6NX Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/10/2016 11:52 AM, Sascha Silbe wrote: > Dear Max, >=20 > Max Reitz writes: >=20 >>> +# 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 yourse= lf >> say, the lines get pretty long otherwise, and if we have any change >> within, the whole line needs to be changed). >=20 > Additionally, it's a lot easier to read when indented properly, > especially with the block info containing nested dicts. >=20 >> 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' >=20 > 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. >=20 > Will test your version and send a v2. Thanks for the suggestion! >=20 > Sascha >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --jXFBRkrXOdAtK7khmawlowAQ1AncXL6NX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWu7ZLAAoJEKeha0olJ0NqcWcH/RM1WTRTVM1/TCGMm2PvmOiT 3V6+Ym/86K7xMmrMgz8H4SqpAa3RvTLpd1s5N3r/zBEH3ALJgiy8imznw1w7kwBG JNd0BJjbfuB34jX2vx1+tQ2TgigxLXvAr7O41pw63fCjh93sfJ9RNazkB0/G9iAA gH/9sWp/nzXtlK/YYnxTi7cKUl7nn3lZU0dyPIDeoPn+UTrG5mNgwWuRxFpae4q5 EddvWA5cduoIQQVd6AEi7gGYmMUAKkYK7qDEYQuMtLzqPTAjF3b5WuF93GzQ/hk/ kUomV1m6JsU3u3iXN5A50Loo8jHXpMspQOa4owKwwoaflqXQq8z5fuuSAfczPvc= =ss3K -----END PGP SIGNATURE----- --jXFBRkrXOdAtK7khmawlowAQ1AncXL6NX--