qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [Qemu-devel] [PATCH v4 15/22] libqtest: Delete qtest_qmp() wrappers
Date: Thu,  3 Aug 2017 20:25:44 -0500	[thread overview]
Message-ID: <20170804012551.2714-16-eblake@redhat.com> (raw)
In-Reply-To: <20170804012551.2714-1-eblake@redhat.com>

None of our tests were directly using qtest_qmp() and friends;
even tests like postcopy-test.c that manage multiple connections
get along just fine changing global_qtest as needed (other than
one callsite where it forgot to use the inlined form).  It's
also annoying that we have qmp_async() but qtest_async_qmp(),
with inconsistent naming for tracing through the wrappers.

As future patches are about to add some convenience functions
for easier generation of QMP commands, it's easier if we don't
have to percolate the changes through as many layers of the stack,
by getting rid of the layer that no one uses, and just documenting
that callers have to massage the global variable as needed. (Yes,
this is backwards from good design that says all state should be
passed as parameters rather than via a global variable - but such
is life in maintaining a testsuite, where it is easier to write
concise tests than it is to retrofit all existing tests to pass
the extra parameter everywhere.)

Internally, we rename qmp_fd_sendv() to qtest_qmp_sendv(), as
well as give it a ... counterpart qmp_fd_send(), but the overall
reduction in code makes this file a bit less repetitive.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 tests/libqtest.h      | 75 +++++----------------------------------------------
 tests/libqtest.c      | 71 +++++++++++++-----------------------------------
 tests/postcopy-test.c |  2 +-
 3 files changed, 25 insertions(+), 123 deletions(-)

diff --git a/tests/libqtest.h b/tests/libqtest.h
index 6bae0223aa..684cfb3507 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -21,6 +21,11 @@

 typedef struct QTestState QTestState;

+/*
+ * The various qmp_*() commands operate on global_qtest.  Tests can
+ * alternate between two parallel connections by switching which state
+ * is current before issuing commands.
+ */
 extern QTestState *global_qtest;

 /**
@@ -48,49 +53,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
 void qtest_quit(QTestState *s);

 /**
- * qtest_qmp:
- * @s: #QTestState instance to operate on.
- * @fmt...: QMP message to send to qemu; 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 *qtest_qmp(QTestState *s, const char *fmt, ...);
-
-/**
- * qtest_async_qmp:
- * @s: #QTestState instance to operate on.
- * @fmt...: QMP message to send to qemu; 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 qtest_async_qmp(QTestState *s, const char *fmt, ...);
-
-/**
- * qtest_qmpv:
- * @s: #QTestState instance to operate on.
- * @fmt: QMP message to send to QEMU; formats arguments through
- * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf%])').
- * @ap: QMP message arguments
- *
- * Sends a QMP message to QEMU and returns the response.
- */
-QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
-
-/**
- * qtest_async_qmpv:
- * @s: #QTestState instance to operate on.
- * @fmt: QMP message to send to QEMU; formats arguments through
- * json-lexer.c (only understands '%(PRI[ud]64|(l|ll)?[du]|[ipsf%])').
- * @ap: QMP message arguments
- *
- * Sends a QMP message to QEMU and leaves the response in the stream.
- */
-void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap);
-
-/**
- * qtest_receive:
+ * qtest_qmp_receive:
  * @s: #QTestState instance to operate on.
  *
  * Reads a QMP message from QEMU and returns the response.
@@ -117,32 +80,6 @@ void qtest_qmp_eventwait(QTestState *s, const char *event);
 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);

 /**
- * qtest_hmp:
- * @s: #QTestState instance to operate on.
- * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
- *
- * Send HMP command to QEMU via QMP's human-monitor-command.
- * QMP events are discarded.
- *
- * Returns: the command's output.  The caller should g_free() it.
- */
-char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
-
-/**
- * qtest_hmpv:
- * @s: #QTestState instance to operate on.
- * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
- * @ap: HMP command arguments
- *
- * Send HMP command to QEMU via QMP's human-monitor-command.
- * QMP events are discarded.
- *
- * Returns: the command's output.  The caller should g_free() it.
- */
-char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap)
-    GCC_FMT_ATTR(2, 0);
-
-/**
  * qtest_get_irq:
  * @s: #QTestState instance to operate on.
  * @num: Interrupt to observe.
diff --git a/tests/libqtest.c b/tests/libqtest.c
index f9781d67f5..2df01682c0 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -233,9 +233,10 @@ QTestState *qtest_init(const char *extra_args)
     QDict *greeting;

     /* Read the QMP greeting and then do the handshake */
-    greeting = qtest_qmp_receive(s);
+    greeting = qmp_fd_receive(s->qmp_fd);
     QDECREF(greeting);
-    greeting = qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }");
+    qmp_fd_send(s->qmp_fd, "{ 'execute': 'qmp_capabilities' }");
+    greeting = qmp_fd_receive(s->qmp_fd);
     QDECREF(greeting);

     return s;
@@ -446,7 +447,7 @@ QDict *qtest_qmp_receive(QTestState *s)
  * Internal code that converts from interpolated JSON into a message
  * to send over the wire, without waiting for a reply.
  */
-static void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
+static void qtest_qmp_sendv(QTestState *s, const char *fmt, va_list ap)
 {
     QObject *qobj = NULL;
     QString *qstr;
@@ -460,7 +461,7 @@ static void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
      * order to escape strings properly.
      */
     if (!strchr(fmt, '%')) {
-        qmp_fd_send(fd, fmt);
+        qmp_fd_send(s->qmp_fd, fmt);
         return;
     }

@@ -469,23 +470,19 @@ static void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
     str = qstring_get_str(qstr);

     /* Send QMP request */
-    qmp_fd_send(fd, str);
+    qmp_fd_send(s->qmp_fd, str);

     QDECREF(qstr);
     qobject_decref(qobj);
 }

-void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap)
+static void qtest_qmp_send(QTestState *s, const char *fmt, ...)
 {
-    qmp_fd_sendv(s->qmp_fd, fmt, ap);
-}
+    va_list ap;

-QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
-{
-    qtest_async_qmpv(s, fmt, ap);
-
-    /* Receive reply */
-    return qtest_qmp_receive(s);
+    va_start(ap, fmt);
+    qtest_qmp_sendv(s, fmt, ap);
+    va_end(ap);
 }

 void qmp_fd_send(int fd, const char *msg)
@@ -499,26 +496,6 @@ void qmp_fd_send(int fd, const char *msg)
     socket_send(fd, msg, strlen(msg));
 }

-QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
-{
-    va_list ap;
-    QDict *response;
-
-    va_start(ap, fmt);
-    response = qtest_qmpv(s, fmt, ap);
-    va_end(ap);
-    return response;
-}
-
-void qtest_async_qmp(QTestState *s, const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    qtest_async_qmpv(s, fmt, ap);
-    va_end(ap);
-}
-
 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event)
 {
     QDict *response;
@@ -541,16 +518,16 @@ void qtest_qmp_eventwait(QTestState *s, const char *event)
     QDECREF(response);
 }

-char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap)
+static char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap)
 {
     char *cmd;
     QDict *resp;
     char *ret;

     cmd = g_strdup_vprintf(fmt, ap);
-    resp = qtest_qmp(s, "{'execute': 'human-monitor-command',"
-                     " 'arguments': {'command-line': %s}}",
-                     cmd);
+    qtest_qmp_send(s, "{'execute': 'human-monitor-command',"
+                   " 'arguments': {'command-line': %s}}", cmd);
+    resp = qtest_qmp_receive(s);
     ret = g_strdup(qdict_get_try_str(resp, "return"));
     while (ret == NULL && qdict_get_try_str(resp, "event")) {
         /* Ignore asynchronous QMP events */
@@ -564,17 +541,6 @@ char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap)
     return ret;
 }

-char *qtest_hmp(QTestState *s, const char *fmt, ...)
-{
-    va_list ap;
-    char *ret;
-
-    va_start(ap, fmt);
-    ret = qtest_hmpv(s, fmt, ap);
-    va_end(ap);
-    return ret;
-}
-
 const char *qtest_get_arch(void)
 {
     const char *qemu = getenv("QTEST_QEMU_BINARY");
@@ -870,12 +836,11 @@ void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)
 QDict *qmp(const char *fmt, ...)
 {
     va_list ap;
-    QDict *response;

     va_start(ap, fmt);
-    response = qtest_qmpv(global_qtest, fmt, ap);
+    qtest_qmp_sendv(global_qtest, fmt, ap);
     va_end(ap);
-    return response;
+    return qtest_qmp_receive(global_qtest);
 }

 QDict *qmp_raw(const char *msg)
@@ -889,7 +854,7 @@ void qmp_async(const char *fmt, ...)
     va_list ap;

     va_start(ap, fmt);
-    qtest_async_qmpv(global_qtest, fmt, ap);
+    qtest_qmp_sendv(global_qtest, fmt, ap);
     va_end(ap);
 }

diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c
index ceaed823eb..61f4b4180a 100644
--- a/tests/postcopy-test.c
+++ b/tests/postcopy-test.c
@@ -236,7 +236,7 @@ static QDict *return_or_event(QDict *response)
         got_stop = true;
     }
     QDECREF(response);
-    return return_or_event(qtest_qmp_receive(global_qtest));
+    return return_or_event(qmp_receive());
 }


-- 
2.13.3

  parent reply	other threads:[~2017-08-04  1:26 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 ` Eric Blake [this message]
2017-08-09 15:34   ` [Qemu-devel] [PATCH v4 15/22] libqtest: Delete qtest_qmp() wrappers 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=20170804012551.2714-16-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.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).