From d62fbe603969c54f39eaed2876238c574cbed5cb Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 11 Oct 2017 11:46:00 +0200 Subject: tests: Refactor setting of parameters/capabilities So we can use them in future tests Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- tests/migration-test.c | 101 +++++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/tests/migration-test.c b/tests/migration-test.c index 55c4aed719..19a1445076 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -351,12 +351,69 @@ static void cleanup(const char *filename) g_free(path); } +static void migrate_set_downtime(QTestState *who, const char *value) +{ + QDict *rsp; + gchar *cmd; + + cmd = g_strdup_printf("{ 'execute': 'migrate_set_downtime'," + "'arguments': { 'value': %s } }", value); + rsp = qtest_qmp(who, cmd); + g_free(cmd); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); +} + +static void migrate_set_speed(QTestState *who, const char *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); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); +} + +static void migrate_set_capability(QTestState *who, const char *capability, + const char *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); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); +} + +static void migrate(QTestState *who, const char *uri) +{ + QDict *rsp; + gchar *cmd; + + cmd = g_strdup_printf("{ 'execute': 'migrate'," + "'arguments': { 'uri': '%s' } }", + uri); + rsp = qtest_qmp(who, cmd); + g_free(cmd); + g_assert(qdict_haskey(rsp, "return")); + QDECREF(rsp); +} + static void test_migrate(void) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *global = global_qtest, *from, *to; unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; - gchar *cmd, *cmd_src, *cmd_dst; + gchar *cmd_src, *cmd_dst; QDict *rsp; char *bootpath = g_strdup_printf("%s/bootsect", tmpfs); @@ -405,52 +462,22 @@ static void test_migrate(void) to = qtest_init(cmd_dst); g_free(cmd_dst); - global_qtest = from; - rsp = qmp("{ 'execute': 'migrate-set-capabilities'," - "'arguments': { " - "'capabilities': [ {" - "'capability': 'postcopy-ram'," - "'state': true } ] } }"); - g_assert(qdict_haskey(rsp, "return")); - QDECREF(rsp); - - global_qtest = to; - rsp = qmp("{ 'execute': 'migrate-set-capabilities'," - "'arguments': { " - "'capabilities': [ {" - "'capability': 'postcopy-ram'," - "'state': true } ] } }"); - g_assert(qdict_haskey(rsp, "return")); - QDECREF(rsp); + migrate_set_capability(from, "postcopy-ram", "true"); + migrate_set_capability(to, "postcopy-ram", "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. */ - global_qtest = from; - rsp = qmp("{ 'execute': 'migrate_set_speed'," - "'arguments': { 'value': 100000000 } }"); - g_assert(qdict_haskey(rsp, "return")); - QDECREF(rsp); - - /* 1ms downtime - it should never finish precopy */ - rsp = qmp("{ 'execute': 'migrate_set_downtime'," - "'arguments': { 'value': 0.001 } }"); - g_assert(qdict_haskey(rsp, "return")); - QDECREF(rsp); - + migrate_set_speed(from, "100000000"); + migrate_set_downtime(from, "0.001"); /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); - cmd = g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp = qmp(cmd); - g_free(cmd); - g_assert(qdict_haskey(rsp, "return")); - QDECREF(rsp); + migrate(from, uri); + global_qtest = from; wait_for_migration_pass(); rsp = return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }")); -- cgit v1.2.3