diff options
author | Juan Quintela <quintela@redhat.com> | 2017-10-11 11:46:00 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2017-10-29 14:06:16 +0100 |
commit | d62fbe603969c54f39eaed2876238c574cbed5cb (patch) | |
tree | d120cd887f699fb6b7f83814fa55422b9eca12df /tests | |
parent | 2656bfd9731d430f2767f90906a3f1b1bfbf62d2 (diff) |
tests: Refactor setting of parameters/capabilities
So we can use them in future tests
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/migration-test.c | 101 |
1 files changed, 64 insertions, 37 deletions
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' }")); |