qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 5/9] tests/libqos/usb: Clean up string interpolation into QMP input
Date: Fri, 21 Jul 2017 15:53:22 +0200	[thread overview]
Message-ID: <1500645206-13559-6-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1500645206-13559-1-git-send-email-armbru@redhat.com>

Leaving interpolation into JSON to qmp() is more robust than building
QMP input manually, as explained in the previous commit.

The case in usb_test_hotplug() slightly more complicated: it
interpolates *into* JSON values.  Clean it up by building the values
separately, so we can again leave interpolation to qmp().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/libqos/usb.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c
index 0cdfaec..f88d4a6 100644
--- a/tests/libqos/usb.c
+++ b/tests/libqos/usb.c
@@ -40,18 +40,20 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
 void usb_test_hotplug(const char *hcd_id, const int port,
                       void (*port_check)(void))
 {
+    char id[32];
+    char *bus;
     QDict *response;
-    char  *cmd;
 
-    cmd = g_strdup_printf("{'execute': 'device_add',"
-                          " 'arguments': {"
-                          "   'driver': 'usb-tablet',"
-                          "   'port': '%d',"
-                          "   'bus': '%s.0',"
-                          "   'id': 'usbdev%d'"
-                          "}}", port, hcd_id, port);
-    response = qmp(cmd);
-    g_free(cmd);
+    sprintf(id, "usbdev%d", port);
+    bus = g_strdup_printf("%s.0", hcd_id);
+    response = qmp("{'execute': 'device_add',"
+                   " 'arguments': {"
+                   "   'driver': 'usb-tablet',"
+                   "   'port': %s,"
+                   "   'bus': %s,"
+                   "   'id': %s"
+                   " }}", id + 6, bus, id);
+    g_free(bus);
     g_assert(response);
     g_assert(!qdict_haskey(response, "error"));
     QDECREF(response);
@@ -60,12 +62,8 @@ void usb_test_hotplug(const char *hcd_id, const int port,
         port_check();
     }
 
-    cmd = g_strdup_printf("{'execute': 'device_del',"
-                           " 'arguments': {"
-                           "   'id': 'usbdev%d'"
-                           "}}", port);
-    response = qmp(cmd);
-    g_free(cmd);
+    response = qmp("{'execute': 'device_del', 'arguments': { 'id': %s }}",
+                   id);
     g_assert(response);
     g_assert(qdict_haskey(response, "event"));
     g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
-- 
2.7.5

  parent reply	other threads:[~2017-07-21 13:53 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 13:53 [Qemu-devel] [PATCH 0/9] tests: Clean up around qmp() and hmp() Markus Armbruster
2017-07-21 13:53 ` [Qemu-devel] [PATCH 1/9] qtest: Avoid passing raw strings through hmp() Markus Armbruster
2017-07-25 13:56   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 2/9] qtest: Document calling conventions Markus Armbruster
2017-07-21 14:24   ` Eric Blake
2017-07-21 15:48     ` Markus Armbruster
2017-07-25 13:57   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 3/9] tests: Pass literal format strings directly to qmp_FOO() Markus Armbruster
2017-07-21 14:26   ` Eric Blake
2017-07-25 13:57   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 4/9] tests: Clean up string interpolation into QMP input (simple cases) Markus Armbruster
2017-07-21 14:39   ` Eric Blake
2017-07-21 16:48     ` Markus Armbruster
2017-07-21 20:08       ` Eric Blake
2017-07-21 21:15         ` Eric Blake
2017-07-24  8:30         ` Markus Armbruster
2017-07-21 13:53 ` Markus Armbruster [this message]
2017-07-21 14:50   ` [Qemu-devel] [PATCH 5/9] tests/libqos/usb: Clean up string interpolation into QMP input Eric Blake
2017-07-21 16:49     ` Markus Armbruster
2017-07-25 14:02   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 6/9] tests/libqos/pci: " Markus Armbruster
2017-07-21 15:00   ` Eric Blake
2017-07-21 16:50     ` Markus Armbruster
2017-07-25 14:06   ` Stefan Hajnoczi
2017-07-25 14:10   ` Eric Blake
2017-07-27  8:31     ` Markus Armbruster
2017-07-21 13:53 ` [Qemu-devel] [PATCH 7/9] tests: Clean up wait for event Markus Armbruster
2017-07-21 15:02   ` Eric Blake
2017-07-25 14:08   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 8/9] tests/libqtest: Clean up how we read the QMP greeting Markus Armbruster
2017-07-21 15:02   ` Eric Blake
2017-07-25 14:08   ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 9/9] tests/libqtest: Enable compile-time format string checking Markus Armbruster
2017-07-21 15:04   ` Eric Blake
2017-07-27  8:36     ` Markus Armbruster
2017-07-25 14:09   ` Stefan Hajnoczi

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=1500645206-13559-6-git-send-email-armbru@redhat.com \
    --to=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).