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>
This commit is contained in:
Juan Quintela 2017-10-11 11:57:04 +02:00
parent d62fbe6039
commit 7195a87130

View File

@ -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)