ahci-test: Drop dependence on global_qtest

Managing parallel connections to two different monitors via
the implicit global_qtest makes it hard to copy-and-paste code
to tests that are not aware of the implicit state; the
management of global_qtest is even harder to follow because
it was masked behind set_context().

Instead, explicitly pass QTestState* around (generally, by
reusing the member already present in ahci->parent QOSState),
and call explicit qtest_* functions on all places that
interact with a monitor.

We can assert that the conversion is correct by checking that
global_qtest remains NULL throughout the test (a later patch
that changes global_qtest to not be a public global variable
will drop the assertions).

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: John Snow <jsnow@redhat.com>
[thuth: rebased patch to current master branch]
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Eric Blake 2017-09-11 12:20:02 -05:00 committed by Thomas Huth
parent 6415c2d0b6
commit a189a9375b
3 changed files with 39 additions and 52 deletions

View file

@ -73,11 +73,6 @@ void qtest_shutdown(QOSState *qs)
}
}
void set_context(QOSState *s)
{
global_qtest = s->qts;
}
static QDict *qmp_execute(QTestState *qts, const char *command)
{
return qtest_qmp(qts, "{ 'execute': %s }", command);
@ -89,8 +84,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
QDict *rsp, *sub;
bool running;
set_context(from);
/* Is the machine currently running? */
rsp = qmp_execute(from->qts, "query-status");
g_assert(qdict_haskey(rsp, "return"));
@ -114,7 +107,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
/* If we were running, we can wait for an event. */
if (running) {
migrate_allocator(&from->alloc, &to->alloc);
set_context(to);
qtest_qmp_eventwait(to->qts, "RESUME");
return;
}
@ -144,7 +136,6 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
}
migrate_allocator(&from->alloc, &to->alloc);
set_context(to);
}
bool have_qemu_img(void)