From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "open list:IDE" <qemu-block@nongnu.org>,
John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 14/22] libqtest: Separate qmp_discard_response() from command
Date: Wed, 9 Aug 2017 10:32:50 -0500 [thread overview]
Message-ID: <ecd3699b-1a73-a8e2-5dac-b4f227f106b9@redhat.com> (raw)
In-Reply-To: <87d184ojqp.fsf@dusky.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 3842 bytes --]
On 08/09/2017 10:15 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
>
>> Upcoming patches will be adding new convenience methods for
>> constructing QMP commands. But making every variation of sending
>> support every variation of response handling becomes unwieldy;
>> it's easier to specify that discarding a JSON response is
>> unassociated with sending the command, where qmp_async() already
>> fits the bill for sending a command without tying up a reference
>> to the response.
>>
>> Doing this renders qtest_qmp[v]_discard_response() unused.
>>
>> Bonus: gets rid of a non-literal format string, which is a step
>> towards compile-time format string checking without triggering
>> -Wformat-nonliteral.
>
> Where? (I'm feeling lazy today)
>
Sure:
>
> +++ b/tests/ide-test.c
> @@ -624,7 +624,6 @@ static void test_retry_flush(const char *machine)
> QPCIDevice *dev;
> QPCIBar bmdma_bar, ide_bar;
> uint8_t data;
> - const char *s;
>
> prepare_blkdebug_script(debug_path, "flush_to_disk");
>
> @@ -652,8 +651,8 @@ static void test_retry_flush(const char *machine)
> qmp_eventwait("STOP");
>
> /* Complete the command */
> - s = "{'execute':'cont' }";
> - qmp_discard_response(s);
> + qmp_async("{'execute':'cont' }");
> + qmp_discard_response();
Yes, I can update the commit message to focus in on it more precisely.
>> +++ b/tests/libqtest.c
>> @@ -235,7 +235,8 @@ QTestState *qtest_init(const char *extra_args)
>> /* Read the QMP greeting and then do the handshake */
>> greeting = qtest_qmp_receive(s);
>> QDECREF(greeting);
>> - qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
>> + greeting = qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
>> + QDECREF(greeting);
>
> Here, you replace
>
> qtest_qmp_discard_response(ARGS...);
>
> effectively by
>
> QDECREF(qtest_qmp(ARGS...));
>
> which is how qtest_qmp_discard_response() does its job before this
> patch. Okay.
I deleted qtest_qmp_discard_response(). If I had kept it around (but
made it static instead), I could have written this one as:
/* Read the QMP greeting and then do the handshake */
qtest_qmp_discard_response(s);
qtest_qmp_async(s, "{'execute': 'qmp_capabilities'}");
qtest_qmp_discard_response(s);
But as the only place that needed to pass 's' on through, I was just as
comfortable open-coding the QDECREF after the fact.
>> +++ b/tests/ahci-test.c
>> @@ -1596,8 +1596,9 @@ static void test_atapi_tray(void)
>> rsp = qmp_receive();
>> QDECREF(rsp);
Hmm - this code already was manually using QDECREF()...
>>
>> - qmp_discard_response("{'execute': 'x-blockdev-remove-medium', "
>> - "'arguments': {'device': 'drive0'}}");
>> + qmp_async("{'execute': 'x-blockdev-remove-medium', "
>> + "'arguments': {'device': 'drive0'}}");
>> + qmp_discard_response();
which means this could have reused rsp = qmp(...); QDECREF(rsp); as well.
>
> Here, you replace the same pattern (less the QTestState argument) by
>
> qmp_async(F, ...);
> qmp_discard_response();
>
> Also okay. But why two ways to do the same things?
>
> Apropos QTestState argument: do we have a test with more than one state,
> or is having two versions of every function just "avoiding global state
> is virtuous" self-flagellation?
We DO have tests that use more than one state - AND those tests prefer
calling the qmp() version (rather than the qtest_qmp() version) with
manipulation of the global_qtest as needed. See my cleanup in 15/22.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
next prev parent reply other threads:[~2017-08-09 15:33 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-04 1:25 [Qemu-devel] [PATCH v4 00/22] Clean up around qmp() and hmp() Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 01/22] qobject: Accept "%"PRId64 in qobject_from_jsonf() Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 02/22] tests: Clean up wait for event Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 03/22] tests/libqtest: Clean up how we read the QMP greeting Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 04/22] tests: Add assertion for no qmp("") Eric Blake
2017-08-09 7:13 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 05/22] qobject: Simplify qobject_from_jsonv() Eric Blake
2017-08-09 7:59 ` Markus Armbruster
2017-08-09 13:14 ` Eric Blake
2017-10-02 5:46 ` Markus Armbruster
2017-10-02 14:30 ` Eric Blake
2018-01-08 16:46 ` Eric Blake
2017-09-11 21:52 ` Eric Blake
2017-10-02 7:15 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 06/22] qobject: Perform %% interpolation in qobject_from_jsonf() Eric Blake
2017-08-09 9:06 ` Markus Armbruster
2017-08-09 13:21 ` Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 07/22] numa-test: Use hmp() Eric Blake
2017-08-09 9:07 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 08/22] qtest: Avoid passing raw strings through hmp() Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 09/22] qtest: Document calling conventions Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 10/22] libqtest: Skip round-trip through QObject Eric Blake
2017-08-09 10:10 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 11/22] test-qga: Simplify command construction Eric Blake
2017-08-09 11:40 ` Markus Armbruster
2017-08-09 13:29 ` Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 12/22] libqtest: Change qmp_fd_send() to drop varargs Eric Blake
2017-08-09 13:18 ` Markus Armbruster
2017-08-09 13:44 ` Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 13/22] libqtest: Add qmp_raw() Eric Blake
2017-08-09 14:54 ` Markus Armbruster
2017-08-09 15:18 ` Eric Blake
2017-08-10 7:29 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 14/22] libqtest: Separate qmp_discard_response() from command Eric Blake
2017-08-09 15:15 ` Markus Armbruster
2017-08-09 15:32 ` Eric Blake [this message]
2017-08-10 7:40 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 15/22] libqtest: Delete qtest_qmp() wrappers Eric Blake
2017-08-09 15:34 ` Markus Armbruster
2017-08-09 16:35 ` Eric Blake
2017-08-10 7:47 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 16/22] libqtest: Add qmp_cmd() helper Eric Blake
2017-08-09 15:40 ` Markus Armbruster
2017-08-09 16:39 ` Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 17/22] libqtest: Add qmp_args() helper Eric Blake
2017-08-09 15:57 ` Markus Armbruster
2017-08-09 21:57 ` Eric Blake
2017-08-10 8:17 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 18/22] tests/libqos/usb: Clean up string interpolation into QMP input Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 19/22] libqtest: Add qmp_args_dict() helper Eric Blake
2017-08-09 15:59 ` Markus Armbruster
2017-08-09 16:41 ` Eric Blake
2017-08-10 8:19 ` Markus Armbruster
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 20/22] tests/libqos/pci: Clean up string interpolation into QMP input Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 21/22] libqtest: Drop now-unused qmp() Eric Blake
2017-08-09 16:01 ` Markus Armbruster
2017-08-09 16:43 ` Eric Blake
2017-08-04 1:25 ` [Qemu-devel] [PATCH v4 22/22] libqtest: Rename qmp_cmd() to qmp() Eric Blake
2017-08-04 1:54 ` [Qemu-devel] [PATCH v4 00/22] Clean up around qmp() and hmp() no-reply
2017-08-04 11:50 ` Eric Blake
2017-08-04 12:10 ` Fam Zheng
2017-08-07 6:43 ` Fam Zheng
2017-08-07 7:33 ` Fam Zheng
2017-08-07 14:08 ` Philippe Mathieu-Daudé
2017-08-07 8:09 ` Fam Zheng
2017-08-04 2:02 ` no-reply
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=ecd3699b-1a73-a8e2-5dac-b4f227f106b9@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).