[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 18/22] tests/libqos/usb: Clean up string interpol
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v4 18/22] tests/libqos/usb: Clean up string interpolation into QMP input |
Date: |
Thu, 3 Aug 2017 20:25:47 -0500 |
From: Markus Armbruster <address@hidden>
Leaving interpolation into JSON to qmp() is more robust than building
QMP input manually, as explained in a previous commit.
The case in usb_test_hotplug() is 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 <address@hidden>
Message-Id: <address@hidden>
[use qmp_args(), fix commit message typo]
Signed-off-by: Eric Blake <address@hidden>
---
tests/libqos/usb.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c
index 0cdfaecda7..498e6e60e7 100644
--- a/tests/libqos/usb.c
+++ b/tests/libqos/usb.c
@@ -40,18 +40,17 @@ 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_args("device_add",
+ "{'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 +59,7 @@ 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_args("device_del", "{ 'id': %s }", id);
g_assert(response);
g_assert(qdict_haskey(response, "event"));
g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
--
2.13.3
- Re: [Qemu-devel] [PATCH v4 13/22] libqtest: Add qmp_raw(), (continued)
[Qemu-devel] [PATCH v4 15/22] libqtest: Delete qtest_qmp() wrappers, Eric Blake, 2017/08/03
[Qemu-devel] [PATCH v4 14/22] libqtest: Separate qmp_discard_response() from command, Eric Blake, 2017/08/03
[Qemu-devel] [PATCH v4 18/22] tests/libqos/usb: Clean up string interpolation into QMP input,
Eric Blake <=
[Qemu-devel] [PATCH v4 19/22] libqtest: Add qmp_args_dict() helper, Eric Blake, 2017/08/03
[Qemu-devel] [PATCH v4 21/22] libqtest: Drop now-unused qmp(), Eric Blake, 2017/08/03
[Qemu-devel] [PATCH v4 16/22] libqtest: Add qmp_cmd() helper, Eric Blake, 2017/08/03