summaryrefslogtreecommitdiff
path: root/tests/libqos
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-09-11 12:20:01 -0500
committerThomas Huth <thuth@redhat.com>2018-02-14 11:43:41 +0100
commit3d95fb9770f0fbf4396879bb6152b0e78edf0546 (patch)
treee2e4022460ab6878de071853c5d8cba8c3410be1 /tests/libqos
parent10747e55d53d32f1f062456cac1e4fa32f58c44e (diff)
downloadqemu-3d95fb9770f0fbf4396879bb6152b0e78edf0546.tar.gz
libqos: Use explicit QTestState for remaining libqos operations
Drop one more client of global_qtest by teaching all remaining libqos stragglers to pass in an explicit QTestState. Change the setting of global_qtest from being implicit in libqos' call to qtest_start() to instead be explicit in all clients that are still relying on global_qtest. Note that qmp_execute() can be greatly simplified in the process, and that we also get rid of interpolation of a JSON string into a temporary variable when qtest_qmp() can do it more reliably. Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Greg Kurz <groug@kaod.org> Reviewed-by: John Snow <jsnow@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/libqos')
-rw-r--r--tests/libqos/libqos-pc.c2
-rw-r--r--tests/libqos/libqos.c30
2 files changed, 11 insertions, 21 deletions
diff --git a/tests/libqos/libqos-pc.c b/tests/libqos/libqos-pc.c
index b554758802..a9c1aceaa7 100644
--- a/tests/libqos/libqos-pc.c
+++ b/tests/libqos/libqos-pc.c
@@ -25,7 +25,7 @@ QOSState *qtest_pc_boot(const char *cmdline_fmt, ...)
qs = qtest_vboot(&qos_ops, cmdline_fmt, ap);
va_end(ap);
- qtest_irq_intercept_in(global_qtest, "ioapic");
+ qtest_irq_intercept_in(qs->qts, "ioapic");
return qs;
}
diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
index 5729a0618d..5124e982c1 100644
--- a/tests/libqos/libqos.c
+++ b/tests/libqos/libqos.c
@@ -21,7 +21,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
QOSState *qs = g_new0(QOSState, 1);
cmdline = g_strdup_vprintf(cmdline_fmt, ap);
- qs->qts = qtest_start(cmdline);
+ qs->qts = qtest_init(cmdline);
qs->ops = ops;
if (ops) {
qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS);
@@ -81,29 +81,21 @@ void set_context(QOSState *s)
global_qtest = s->qts;
}
-static QDict *qmp_execute(const char *command)
+static QDict *qmp_execute(QTestState *qts, const char *command)
{
- char *fmt;
- QDict *rsp;
-
- fmt = g_strdup_printf("{ 'execute': '%s' }", command);
- rsp = qmp(fmt);
- g_free(fmt);
-
- return rsp;
+ return qtest_qmp(qts, "{ 'execute': %s }", command);
}
void migrate(QOSState *from, QOSState *to, const char *uri)
{
const char *st;
- char *s;
QDict *rsp, *sub;
bool running;
set_context(from);
/* Is the machine currently running? */
- rsp = qmp_execute("query-status");
+ rsp = qmp_execute(from->qts, "query-status");
g_assert(qdict_haskey(rsp, "return"));
sub = qdict_get_qdict(rsp, "return");
g_assert(qdict_haskey(sub, "running"));
@@ -111,30 +103,28 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
QDECREF(rsp);
/* Issue the migrate command. */
- s = g_strdup_printf("{ 'execute': 'migrate',"
- "'arguments': { 'uri': '%s' } }",
- uri);
- rsp = qmp(s);
- g_free(s);
+ rsp = qtest_qmp(from->qts,
+ "{ 'execute': 'migrate', 'arguments': { 'uri': %s }}",
+ uri);
g_assert(qdict_haskey(rsp, "return"));
QDECREF(rsp);
/* Wait for STOP event, but only if we were running: */
if (running) {
- qmp_eventwait("STOP");
+ qtest_qmp_eventwait(from->qts, "STOP");
}
/* If we were running, we can wait for an event. */
if (running) {
migrate_allocator(from->alloc, to->alloc);
set_context(to);
- qmp_eventwait("RESUME");
+ qtest_qmp_eventwait(to->qts, "RESUME");
return;
}
/* Otherwise, we need to wait: poll until migration is completed. */
while (1) {
- rsp = qmp_execute("query-migrate");
+ rsp = qmp_execute(from->qts, "query-migrate");
g_assert(qdict_haskey(rsp, "return"));
sub = qdict_get_qdict(rsp, "return");
g_assert(qdict_haskey(sub, "status"));