tests: Don't abuse global_qtest

As we have two guests running, just pass always who we want to send a
message to.  Once there, refactor return_or_event() into wait_command.

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 12:13:45 +02:00
parent 7195a87130
commit 863e27a8fc

View File

@ -223,20 +223,23 @@ static void wait_for_serial(const char *side)
/* /*
* Events can get in the way of responses we are actually waiting for. * Events can get in the way of responses we are actually waiting for.
*/ */
static QDict *return_or_event(QDict *response) static QDict *wait_command(QTestState *who, const char *command)
{ {
const char *event_string; const char *event_string;
if (!qdict_haskey(response, "event")) { QDict *response;
return response;
}
/* OK, it was an event */ response = qtest_qmp(who, command);
event_string = qdict_get_str(response, "event");
if (!strcmp(event_string, "STOP")) { while (qdict_haskey(response, "event")) {
got_stop = true; /* OK, it was an event */
event_string = qdict_get_str(response, "event");
if (!strcmp(event_string, "STOP")) {
got_stop = true;
}
QDECREF(response);
response = qtest_qmp_receive(who);
} }
QDECREF(response); return response;
return return_or_event(qtest_qmp_receive(global_qtest));
} }
@ -245,12 +248,12 @@ static QDict *return_or_event(QDict *response)
* events suddenly appearing confuse the qmp()/hmp() responses. * events suddenly appearing confuse the qmp()/hmp() responses.
*/ */
static uint64_t get_migration_pass(void) static uint64_t get_migration_pass(QTestState *who)
{ {
QDict *rsp, *rsp_return, *rsp_ram; QDict *rsp, *rsp_return, *rsp_ram;
uint64_t result; uint64_t result;
rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }")); rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
rsp_return = qdict_get_qdict(rsp, "return"); rsp_return = qdict_get_qdict(rsp, "return");
if (!qdict_haskey(rsp_return, "ram")) { if (!qdict_haskey(rsp_return, "ram")) {
/* Still in setup */ /* Still in setup */
@ -263,7 +266,7 @@ static uint64_t get_migration_pass(void)
return result; return result;
} }
static void wait_for_migration_complete(void) static void wait_for_migration_complete(QTestState *who)
{ {
QDict *rsp, *rsp_return; QDict *rsp, *rsp_return;
bool completed; bool completed;
@ -271,7 +274,7 @@ static void wait_for_migration_complete(void)
do { do {
const char *status; const char *status;
rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }")); rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
rsp_return = qdict_get_qdict(rsp, "return"); rsp_return = qdict_get_qdict(rsp, "return");
status = qdict_get_str(rsp_return, "status"); status = qdict_get_str(rsp_return, "status");
completed = strcmp(status, "completed") == 0; completed = strcmp(status, "completed") == 0;
@ -281,14 +284,14 @@ static void wait_for_migration_complete(void)
} while (!completed); } while (!completed);
} }
static void wait_for_migration_pass(void) static void wait_for_migration_pass(QTestState *who)
{ {
uint64_t initial_pass = get_migration_pass(); uint64_t initial_pass = get_migration_pass(who);
uint64_t pass; uint64_t pass;
/* Wait for the 1st sync */ /* Wait for the 1st sync */
do { do {
initial_pass = get_migration_pass(); initial_pass = get_migration_pass(who);
if (got_stop || initial_pass) { if (got_stop || initial_pass) {
break; break;
} }
@ -297,7 +300,7 @@ static void wait_for_migration_pass(void)
do { do {
usleep(1000 * 100); usleep(1000 * 100);
pass = get_migration_pass(); pass = get_migration_pass(who);
} while (pass == initial_pass && !got_stop); } while (pass == initial_pass && !got_stop);
} }
@ -493,7 +496,7 @@ static void test_migrate_end(QTestState *from, QTestState *to)
static void test_migrate(void) static void test_migrate(void)
{ {
char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
QTestState *global = global_qtest, *from, *to; QTestState *from, *to;
QDict *rsp; QDict *rsp;
test_migrate_start(&from, &to, uri); test_migrate_start(&from, &to, uri);
@ -513,26 +516,22 @@ static void test_migrate(void)
migrate(from, uri); migrate(from, uri);
global_qtest = from; wait_for_migration_pass(from);
wait_for_migration_pass();
rsp = return_or_event(qmp("{ 'execute': 'migrate-start-postcopy' }")); rsp = wait_command(from, "{ 'execute': 'migrate-start-postcopy' }");
g_assert(qdict_haskey(rsp, "return")); g_assert(qdict_haskey(rsp, "return"));
QDECREF(rsp); QDECREF(rsp);
if (!got_stop) { if (!got_stop) {
qmp_eventwait("STOP"); qtest_qmp_eventwait(from, "STOP");
} }
global_qtest = to; qtest_qmp_eventwait(to, "RESUME");
qmp_eventwait("RESUME");
wait_for_serial("dest_serial"); wait_for_serial("dest_serial");
global_qtest = from; wait_for_migration_complete(from);
wait_for_migration_complete();
g_free(uri); g_free(uri);
global_qtest = global;
test_migrate_end(from, to); test_migrate_end(from, to);
} }