@@ -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);
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 <quintela@redhat.com> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/migration-test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)