[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/20] migration-test: Clean up string interpolation
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 18/20] migration-test: Clean up string interpolation into QMP, part 2 |
Date: |
Thu, 12 Jul 2018 13:12:19 +0200 |
Leaving interpolation into JSON to qmp() is more robust than building
QMP input manually, as explained in the recent commit "tests: Clean up
string interpolation into QMP input (simple cases)".
migrate() interpolates members into a JSON object. Change it to take
its extra QMP arguments as arguments for qdict_from_jsonf_nofail()
instead of a string containing JSON members.
Bonus: gets rid of a non-literal format string. A step towards
compile-time format string checking without triggering
-Wformat-nonliteral.
Cc: Juan Quintela <address@hidden>
Cc: Dr. David Alan Gilbert <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
tests/migration-test.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 66a4cd2395..4a4db88b61 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -14,6 +14,7 @@
#include "libqtest.h"
#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qjson.h"
#include "qemu/option.h"
#include "qemu/range.h"
#include "qemu/sockets.h"
@@ -381,16 +382,19 @@ static void migrate_set_capability(QTestState *who, const
char *capability,
qobject_unref(rsp);
}
-static void migrate(QTestState *who, const char *uri, const char *extra)
+static void migrate(QTestState *who, const char *uri, const char *fmt, ...)
{
- QDict *rsp;
- gchar *cmd;
+ va_list ap;
+ QDict *args, *rsp;
- cmd = g_strdup_printf("{ 'execute': 'migrate',"
- " 'arguments': { 'uri': '%s' %s } }",
- uri, extra ? extra : "");
- rsp = qtest_qmp(who, cmd);
- g_free(cmd);
+ va_start(ap, fmt);
+ args = qdict_from_vjsonf_nofail(fmt, ap);
+ va_end(ap);
+
+ g_assert(!qdict_haskey(args, "uri"));
+ qdict_put_str(args, "uri", uri);
+
+ rsp = qmp("{ 'execute': 'migrate', 'arguments': %p}", args);
g_assert(qdict_haskey(rsp, "return"));
qobject_unref(rsp);
}
@@ -582,7 +586,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,
/* Wait for the first serial output from the source */
wait_for_serial("src_serial");
- migrate(from, uri, NULL);
+ migrate(from, uri, "{}");
g_free(uri);
wait_for_migration_pass(from);
@@ -665,7 +669,7 @@ static void test_postcopy_recovery(void)
* the newly created channel
*/
wait_for_migration_status(from, "postcopy-paused");
- migrate(from, uri, ", 'resume': true");
+ migrate(from, uri, "{'resume': true}");
g_free(uri);
/* Restore the postcopy bandwidth to unlimited */
@@ -684,7 +688,7 @@ static void test_baddest(void)
if (test_migrate_start(&from, &to, "tcp:0:0", true)) {
return;
}
- migrate(from, "tcp:0:0", NULL);
+ migrate(from, "tcp:0:0", "{}");
do {
status = migrate_query_status(from);
g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
@@ -722,7 +726,7 @@ static void test_precopy_unix(void)
/* Wait for the first serial output from the source */
wait_for_serial("src_serial");
- migrate(from, uri, NULL);
+ migrate(from, uri, "{}");
wait_for_migration_pass(from);
--
2.17.1
- [Qemu-devel] [PATCH 16/20] migration-test: Make wait_command() cope with '%', (continued)
- [Qemu-devel] [PATCH 16/20] migration-test: Make wait_command() cope with '%', Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 01/20] libqtest: Document calling conventions, Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 09/20] qobject: qobject_from_jsonv() is dangerous, hide it away, Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 12/20] cpu-plug-test: Don't pass integers as strings to device_add, Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 06/20] qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail(), Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 18/20] migration-test: Clean up string interpolation into QMP, part 2,
Markus Armbruster <=
- [Qemu-devel] [PATCH 02/20] libqtest: Rename functions to send QMP messages, Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 14/20] migration-test: Make wait_command() return the "return" member, Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 15/20] tests: New helper qtest_qmp_receive_success(), Markus Armbruster, 2018/07/12
- [Qemu-devel] [PATCH 04/20] libqtest: Clean up how we read the QMP greeting, Markus Armbruster, 2018/07/12