diff options
author | Juan Quintela <quintela@redhat.com> | 2017-10-11 11:57:04 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2017-10-29 14:06:16 +0100 |
commit | 7195a87130b2d58b27a0d5b1641a26e48423348b (patch) | |
tree | 4fda01494428fa1a840186320bbf92c32df9c60e /tests | |
parent | d62fbe603969c54f39eaed2876238c574cbed5cb (diff) |
tests: Factorize out migrate_test_start/end
We fix global_test users left and right
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 | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/tests/migration-test.c b/tests/migration-test.c index 19a1445076..91fb0277d6 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -301,7 +301,7 @@ static void wait_for_migration_pass(void) } while (pass == initial_pass && !got_stop); } -static void check_guests_ram(void) +static void check_guests_ram(QTestState *who) { /* Our ASM test will have been incrementing one byte from each page from * 1MB to <100MB in order. @@ -316,13 +316,13 @@ static void check_guests_ram(void) bool hit_edge = false; bool bad = false; - qtest_memread(global_qtest, start_address, &first_byte, 1); + qtest_memread(who, start_address, &first_byte, 1); last_byte = first_byte; for (address = start_address + 4096; address < end_address; address += 4096) { uint8_t b; - qtest_memread(global_qtest, address, &b, 1); + qtest_memread(who, address, &b, 1); if (b != last_byte) { if (((b + 1) % 256) == last_byte && !hit_edge) { /* This is OK, the guest stopped at the point of @@ -408,14 +408,10 @@ static void migrate(QTestState *who, const char *uri) QDECREF(rsp); } -static void test_migrate(void) +static void test_migrate_start(QTestState **from, QTestState **to, + const char *uri) { - 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_src, *cmd_dst; - QDict *rsp; - char *bootpath = g_strdup_printf("%s/bootsect", tmpfs); const char *arch = qtest_get_arch(); @@ -456,11 +452,51 @@ static void test_migrate(void) g_free(bootpath); - from = qtest_start(cmd_src); + *from = qtest_start(cmd_src); g_free(cmd_src); - to = qtest_init(cmd_dst); + *to = qtest_init(cmd_dst); g_free(cmd_dst); +} + +static void test_migrate_end(QTestState *from, QTestState *to) +{ + unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; + + qtest_quit(from); + + qtest_memread(to, start_address, &dest_byte_a, 1); + + /* Destination still running, wait for a byte to change */ + do { + qtest_memread(to, start_address, &dest_byte_b, 1); + usleep(10 * 1000); + } while (dest_byte_a == dest_byte_b); + + qtest_qmp_discard_response(to, "{ 'execute' : 'stop'}"); + /* With it stopped, check nothing changes */ + qtest_memread(to, start_address, &dest_byte_c, 1); + sleep(1); + qtest_memread(to, start_address, &dest_byte_d, 1); + g_assert_cmpint(dest_byte_c, ==, dest_byte_d); + + check_guests_ram(to); + + qtest_quit(to); + + cleanup("bootsect"); + cleanup("migsocket"); + cleanup("src_serial"); + cleanup("dest_serial"); +} + +static void test_migrate(void) +{ + char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *global = global_qtest, *from, *to; + QDict *rsp; + + test_migrate_start(&from, &to, uri); migrate_set_capability(from, "postcopy-ram", "true"); migrate_set_capability(to, "postcopy-ram", "true"); @@ -495,36 +531,10 @@ static void test_migrate(void) global_qtest = from; wait_for_migration_complete(); - qtest_quit(from); - - global_qtest = to; - - qtest_memread(to, start_address, &dest_byte_a, 1); - - /* Destination still running, wait for a byte to change */ - do { - qtest_memread(to, start_address, &dest_byte_b, 1); - usleep(10 * 1000); - } while (dest_byte_a == dest_byte_b); - - qmp_discard_response("{ 'execute' : 'stop'}"); - /* With it stopped, check nothing changes */ - qtest_memread(to, start_address, &dest_byte_c, 1); - sleep(1); - qtest_memread(to, start_address, &dest_byte_d, 1); - g_assert_cmpint(dest_byte_c, ==, dest_byte_d); - - check_guests_ram(); - - qtest_quit(to); g_free(uri); - global_qtest = global; - cleanup("bootsect"); - cleanup("migsocket"); - cleanup("src_serial"); - cleanup("dest_serial"); + test_migrate_end(from, to); } int main(int argc, char **argv) |