All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, "open list:IDE" <qemu-block@nongnu.org>,
	"Amit Shah" <amit@kernel.org>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v4 17/22] libqtest: Add qmp_args() helper
Date: Wed, 09 Aug 2017 17:57:23 +0200	[thread overview]
Message-ID: <87shh0n38c.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170804012551.2714-18-eblake@redhat.com> (Eric Blake's message of "Thu, 3 Aug 2017 20:25:46 -0500")

Eric Blake <eblake@redhat.com> writes:

> Similar to the previous helper, we can reduce the boilerplate
> of most callers by passing the command name separately from
> the interpolated arguments.  Adjust the majority of the callers
> that can use the new helpers; in the process, fixing a few
> places where we would have failed -Wformat-nonliteral.  The
> new helper function already uses GCC_FMT_ATTR to match the
> underlying use of qobject_from_jsonv().
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  tests/libqtest.h               |  20 ++++++
>  tests/libqtest.c               |  29 +++++++++
>  tests/ahci-test.c              |  19 +++---
>  tests/device-introspect-test.c |   4 +-
>  tests/drive_del-test.c         |  10 +--
>  tests/fdc-test.c               |   8 +--
>  tests/libqos/libqos.c          |   7 +--
>  tests/libqos/pci-pc.c          |   8 +--
>  tests/pc-cpu-test.c            |   8 +--
>  tests/postcopy-test.c          |  30 +++------
>  tests/qom-test.c               |   9 +--
>  tests/test-netfilter.c         | 139 ++++++++++++++++-------------------------
>  tests/test-x86-cpuid-compat.c  |   6 +-
>  tests/tmp105-test.c            |   9 +--
>  tests/usb-hcd-uhci-test.c      |  14 ++---
>  tests/usb-hcd-xhci-test.c      |  25 ++------
>  tests/vhost-user-test.c        |  12 +---
>  tests/virtio-blk-test.c        |  12 +---
>  tests/virtio-scsi-test.c       |  13 +---
>  tests/virtio-serial-test.c     |  12 +---
>  20 files changed, 167 insertions(+), 227 deletions(-)
>
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index e0d87d035a..86ca7fa581 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -499,6 +499,26 @@ QDict *qmp_cmd(const char *cmd);
>  void qmp_cmd_async(const char *cmd);
>
>  /**
> + * qmp_args:
> + * @cmd: QMP command to send to QEMU.
> + * @fmt...: Arguments for the command; formats arguments through
> + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf%])').
> + *
> + * Sends a QMP message to QEMU and returns the response.
> + */
> +QDict *qmp_args(const char *cmd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
> +
> +/**
> + * qmp_args_async:
> + * @cmd: QMP command to send to QEMU.
> + * @fmt...: Arguments for the command; formats arguments through
> + * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf%])').
> + *
> + * Sends a QMP message to QEMU and leaves the response in the stream.
> + */
> +void qmp_args_async(const char *cmd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
> +
> +/**
>   * qmp_discard_response:
>   *
>   * Read and discard a QMP response, typically after qmp_async().
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 3926a4d481..49786cf2d7 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -869,6 +869,35 @@ void qmp_cmd_async(const char *cmd)
>      qtest_qmp_send(global_qtest, "{'execute':%s}", cmd);
>  }
>
> +static void qmp_args_dict_async(const char *cmd, QDict *args)
> +{
> +    assert(args);
> +    qtest_qmp_send(global_qtest, "{'execute':%s, 'arguments':%p}", cmd, args);
> +}
> +
> +QDict *qmp_args(const char *cmd, const char *fmt, ...)
> +{
> +    va_list ap;
> +    QObject *obj;
> +
> +    va_start(ap, fmt);
> +    obj = qobject_from_jsonv(fmt, ap);
> +    va_end(ap);
> +    qmp_args_dict_async(cmd, qobject_to_qdict(obj));
> +    return qtest_qmp_receive(global_qtest);
> +}
> +
> +void qmp_args_async(const char *cmd, const char *fmt, ...)
> +{
> +    va_list ap;
> +    QObject *obj;
> +
> +    va_start(ap, fmt);
> +    obj = qobject_from_jsonv(fmt, ap);
> +    va_end(ap);
> +    qmp_args_dict_async(cmd, qobject_to_qdict(obj));
> +}
> +

I don't like the qmp_args name.  It's not about arguments, it's about
sending a command with arguments.

I'm afraid I'm getting pretty thorougly confused by the evolving
interface.  So I stop and think how it should look like when done.

We need send and receive.  Convenience functions to do both, and to
receive and throw away are nice to have.

We need qmp_raw().  We haven't found a need for a raw receive function.

Convenience functions to build commands and send are nice to have.  They
come in pairs, without arguments, to avoid -Wno-format-zero-length
(aside: that's one of the sillier warnings).

We used to have almost everything with and without QTestState, but we're
refusing to continue that self-flagellation.

For every function taking ..., we want one taking va_list.

Makes sense?

Can we derive a sensible set of function names from this?

[...]

  reply	other threads:[~2017-08-09 15:57 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
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 [this message]
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=87shh0n38c.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=afaerber@suse.de \
    --cc=amit@kernel.org \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.