diff options
Diffstat (limited to 'tests/migration-test.c')
-rw-r--r-- | tests/migration-test.c | 191 |
1 files changed, 86 insertions, 105 deletions
diff --git a/tests/migration-test.c b/tests/migration-test.c index e079e0b..eb58d0a 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -14,12 +14,16 @@ #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" #include "chardev/char.h" #include "sysemu/sysemu.h" +/* TODO actually test the results and get rid of this */ +#define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__)) + const unsigned start_address = 1024 * 1024; const unsigned end_address = 100 * 1024 * 1024; bool got_stop; @@ -146,26 +150,26 @@ static void wait_for_serial(const char *side) } while (true); } +static void stop_cb(void *opaque, const char *name, QDict *data) +{ + if (!strcmp(name, "STOP")) { + got_stop = true; + } +} + /* * Events can get in the way of responses we are actually waiting for. */ -static QDict *wait_command(QTestState *who, const char *command) +GCC_FMT_ATTR(2, 3) +static QDict *wait_command(QTestState *who, const char *command, ...) { - const char *event_string; - QDict *response; + va_list ap; - response = qtest_qmp(who, command); + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); - while (qdict_haskey(response, "event")) { - /* OK, it was an event */ - event_string = qdict_get_str(response, "event"); - if (!strcmp(event_string, "STOP")) { - got_stop = true; - } - qobject_unref(response); - response = qtest_qmp_receive(who); - } - return response; + return qtest_qmp_receive_success(who, stop_cb, NULL); } /* @@ -174,15 +178,7 @@ static QDict *wait_command(QTestState *who, const char *command) */ static QDict *migrate_query(QTestState *who) { - QDict *rsp, *rsp_return; - - rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); - rsp_return = qdict_get_qdict(rsp, "return"); - g_assert(rsp_return); - qobject_ref(rsp_return); - qobject_unref(rsp); - - return rsp_return; + return wait_command(who, "{ 'execute': 'query-migrate' }"); } /* @@ -322,31 +318,25 @@ static void cleanup(const char *filename) } static void migrate_check_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { - QDict *rsp, *rsp_return; - char *result; + QDict *rsp_return; - rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); - rsp_return = qdict_get_qdict(rsp, "return"); - result = g_strdup_printf("%" PRId64, - qdict_get_try_int(rsp_return, parameter, -1)); - g_assert_cmpstr(result, ==, value); - g_free(result); - qobject_unref(rsp); + rsp_return = wait_command(who, + "{ 'execute': 'query-migrate-parameters' }"); + g_assert_cmpint(qdict_get_int(rsp_return, parameter), ==, value); + qobject_unref(rsp_return); } static void migrate_set_parameter(QTestState *who, const char *parameter, - const char *value) + long long value) { QDict *rsp; - gchar *cmd; - cmd = g_strdup_printf("{ 'execute': 'migrate-set-parameters'," - "'arguments': { '%s': %s } }", - parameter, value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = qtest_qmp(who, + "{ 'execute': 'migrate-set-parameters'," + "'arguments': { %s: %lld } }", + parameter, value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); migrate_check_parameter(who, parameter, value); @@ -357,51 +347,55 @@ static void migrate_pause(QTestState *who) QDict *rsp; rsp = wait_command(who, "{ 'execute': 'migrate-pause' }"); - g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } static void migrate_recover(QTestState *who, const char *uri) { QDict *rsp; - gchar *cmd = g_strdup_printf( - "{ 'execute': 'migrate-recover', " - " 'id': 'recover-cmd', " - " 'arguments': { 'uri': '%s' } }", uri); - rsp = wait_command(who, cmd); - g_assert(qdict_haskey(rsp, "return")); - g_free(cmd); + rsp = wait_command(who, + "{ 'execute': 'migrate-recover', " + " 'id': 'recover-cmd', " + " 'arguments': { 'uri': %s } }", + uri); qobject_unref(rsp); } static void migrate_set_capability(QTestState *who, const char *capability, - const char *value) + bool value) { QDict *rsp; - gchar *cmd; - - cmd = g_strdup_printf("{ 'execute': 'migrate-set-capabilities'," - "'arguments': { " - "'capabilities': [ { " - "'capability': '%s', 'state': %s } ] } }", - capability, value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + + rsp = qtest_qmp(who, + "{ 'execute': 'migrate-set-capabilities'," + "'arguments': { " + "'capabilities': [ { " + "'capability': %s, 'state': %i } ] } }", + capability, value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } -static void migrate(QTestState *who, const char *uri, const char *extra) +/* + * Send QMP command "migrate". + * Arguments are built from @fmt... (formatted like + * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. + */ +GCC_FMT_ATTR(3, 4) +static void migrate(QTestState *who, const char *uri, const char *fmt, ...) { - QDict *rsp; - gchar *cmd; + va_list ap; + QDict *args, *rsp; + + 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); - cmd = g_strdup_printf("{ 'execute': 'migrate'," - " 'arguments': { 'uri': '%s' %s } }", - uri, extra ? extra : ""); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = qmp("{ 'execute': 'migrate', 'arguments': %p}", args); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); } @@ -411,7 +405,6 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to) QDict *rsp; rsp = wait_command(from, "{ 'execute': 'migrate-start-postcopy' }"); - g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); if (!got_stop) { @@ -529,31 +522,21 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest) static void deprecated_set_downtime(QTestState *who, const double value) { QDict *rsp; - gchar *cmd; - char *expected; - int64_t result_int; - - cmd = g_strdup_printf("{ 'execute': 'migrate_set_downtime'," - "'arguments': { 'value': %g } }", value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + + rsp = qtest_qmp(who, + "{ 'execute': 'migrate_set_downtime'," + " 'arguments': { 'value': %f } }", value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); - result_int = value * 1000L; - expected = g_strdup_printf("%" PRId64, result_int); - migrate_check_parameter(who, "downtime-limit", expected); - g_free(expected); + migrate_check_parameter(who, "downtime-limit", value * 1000); } -static void deprecated_set_speed(QTestState *who, const char *value) +static void deprecated_set_speed(QTestState *who, long long value) { QDict *rsp; - gchar *cmd; - cmd = g_strdup_printf("{ 'execute': 'migrate_set_speed'," - "'arguments': { 'value': %s } }", value); - rsp = qtest_qmp(who, cmd); - g_free(cmd); + rsp = qtest_qmp(who, "{ 'execute': 'migrate_set_speed'," + "'arguments': { 'value': %lld } }", value); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); migrate_check_parameter(who, "max-bandwidth", value); @@ -566,7 +549,7 @@ static void test_deprecated(void) from = qtest_start(""); deprecated_set_downtime(from, 0.12345); - deprecated_set_speed(from, "12345"); + deprecated_set_speed(from, 12345); qtest_quit(from); } @@ -582,21 +565,21 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, return -1; } - migrate_set_capability(from, "postcopy-ram", "true"); - migrate_set_capability(to, "postcopy-ram", "true"); - migrate_set_capability(to, "postcopy-blocktime", "true"); + migrate_set_capability(from, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-blocktime", true); /* We want to pick a speed slow enough that the test completes * quickly, but that it doesn't complete precopy even on a slow * machine, so also set the downtime. */ - migrate_set_parameter(from, "max-bandwidth", "100000000"); - migrate_set_parameter(from, "downtime-limit", "1"); + migrate_set_parameter(from, "max-bandwidth", 100000000); + migrate_set_parameter(from, "downtime-limit", 1); /* 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); @@ -642,7 +625,7 @@ static void test_postcopy_recovery(void) } /* Turn postcopy speed down, 4K/s is slow enough on any machines */ - migrate_set_parameter(from, "max-postcopy-bandwidth", "4096"); + migrate_set_parameter(from, "max-postcopy-bandwidth", 4096); /* Now we start the postcopy */ migrate_postcopy_start(from, to); @@ -679,11 +662,11 @@ 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 */ - migrate_set_parameter(from, "max-postcopy-bandwidth", "0"); + migrate_set_parameter(from, "max-postcopy-bandwidth", 0); migrate_postcopy_complete(from, to); } @@ -691,14 +674,14 @@ static void test_postcopy_recovery(void) static void test_baddest(void) { QTestState *from, *to; - QDict *rsp, *rsp_return; + QDict *rsp_return; char *status; bool failed; 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"))); @@ -707,12 +690,10 @@ static void test_baddest(void) } while (!failed); /* Is the machine currently running? */ - rsp = wait_command(from, "{ 'execute': 'query-status' }"); - g_assert(qdict_haskey(rsp, "return")); - rsp_return = qdict_get_qdict(rsp, "return"); + rsp_return = wait_command(from, "{ 'execute': 'query-status' }"); g_assert(qdict_haskey(rsp_return, "running")); g_assert(qdict_get_bool(rsp_return, "running")); - qobject_unref(rsp); + qobject_unref(rsp_return); test_migrate_end(from, to, false); } @@ -731,19 +712,19 @@ static void test_precopy_unix(void) * machine, so also set the downtime. */ /* 1 ms should make it not converge*/ - migrate_set_parameter(from, "downtime-limit", "1"); + migrate_set_parameter(from, "downtime-limit", 1); /* 1GB/s */ - migrate_set_parameter(from, "max-bandwidth", "1000000000"); + migrate_set_parameter(from, "max-bandwidth", 1000000000); /* 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); /* 300 ms should converge */ - migrate_set_parameter(from, "downtime-limit", "300"); + migrate_set_parameter(from, "downtime-limit", 300); if (!got_stop) { qtest_qmp_eventwait(from, "STOP"); |