aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2024-06-19 18:30:44 -0400
committerFabiano Rosas <farosas@suse.de>2024-06-21 09:48:00 -0300
commitd444e5673c223241bd2edbc207b02cc1b2114b71 (patch)
tree245b65483e278c2fafc3bb0b8bf7cf870560b92f
parentcd313b66f203381f2f2f984d5155d7942d26725d (diff)
downloadqemu-d444e5673c223241bd2edbc207b02cc1b2114b71.zip
qemu-d444e5673c223241bd2edbc207b02cc1b2114b71.tar.gz
qemu-d444e5673c223241bd2edbc207b02cc1b2114b71.tar.bz2
tests/migration-tests: migration_event_wait()
Introduce a small helper to wait for a migration event, generalized from the incoming migration path. Make the helper easier to use by allowing it to keep waiting until the expected event is received. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de>
-rw-r--r--tests/qtest/migration-helpers.c31
-rw-r--r--tests/qtest/migration-helpers.h2
2 files changed, 24 insertions, 9 deletions
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 2ca4425..84f49db 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -249,7 +249,7 @@ void migrate_set_capability(QTestState *who, const char *capability,
void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
{
va_list ap;
- QDict *args, *rsp, *data;
+ QDict *args, *rsp;
va_start(ap, fmt);
args = qdict_from_vjsonf_nofail(fmt, ap);
@@ -272,14 +272,7 @@ void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
g_assert(qdict_haskey(rsp, "return"));
qobject_unref(rsp);
- rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
- g_assert(qdict_haskey(rsp, "data"));
-
- data = qdict_get_qdict(rsp, "data");
- g_assert(qdict_haskey(data, "status"));
- g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
-
- qobject_unref(rsp);
+ migration_event_wait(to, "setup");
}
/*
@@ -518,3 +511,23 @@ bool probe_o_direct_support(const char *tmpfs)
return true;
}
#endif
+
+/*
+ * Wait for a "MIGRATION" event. This is what Libvirt uses to track
+ * migration status changes.
+ */
+void migration_event_wait(QTestState *s, const char *target)
+{
+ QDict *response, *data;
+ const char *status;
+ bool found;
+
+ do {
+ response = qtest_qmp_eventwait_ref(s, "MIGRATION");
+ data = qdict_get_qdict(response, "data");
+ g_assert(data);
+ status = qdict_get_str(data, "status");
+ found = (strcmp(status, target) == 0);
+ qobject_unref(response);
+ } while (!found);
+}
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 50095fc..72dba36 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -63,4 +63,6 @@ static inline bool probe_o_direct_support(const char *tmpfs)
}
#endif
void migration_test_add(const char *path, void (*fn)(void));
+void migration_event_wait(QTestState *s, const char *target);
+
#endif /* MIGRATION_HELPERS_H */