qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
	Bandan Das <bdas@redhat.com>, Zhijian Li <lizhijian@fujitsu.com>,
	Fabiano Rosas <farosas@suse.de>,
	Jiri Denemark <jdenemar@redhat.com>,
	Prasad Pandit <ppandit@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	peterx@redhat.com
Subject: [PATCH v3 09/11] tests/migration-tests: migration_event_wait()
Date: Wed, 19 Jun 2024 18:30:44 -0400	[thread overview]
Message-ID: <20240619223046.1798968-10-peterx@redhat.com> (raw)
In-Reply-To: <20240619223046.1798968-1-peterx@redhat.com>

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>
---
 tests/qtest/migration-helpers.h |  2 ++
 tests/qtest/migration-helpers.c | 31 ++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 50095fca4a..72dba369fb 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 */
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 2ca4425d71..84f49db85e 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);
+}
-- 
2.45.0



  parent reply	other threads:[~2024-06-19 22:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 22:30 [PATCH v3 00/11] migration: New postcopy state, and some cleanups Peter Xu
2024-06-19 22:30 ` [PATCH v3 01/11] migration/multifd: Avoid the final FLUSH in complete() Peter Xu
2024-06-19 22:30 ` [PATCH v3 02/11] migration: Rename thread debug names Peter Xu
2024-06-19 22:30 ` [PATCH v3 03/11] migration: Use MigrationStatus instead of int Peter Xu
2024-06-19 22:30 ` [PATCH v3 04/11] migration: Cleanup incoming migration setup state change Peter Xu
2024-06-19 22:30 ` [PATCH v3 05/11] migration/postcopy: Add postcopy-recover-setup phase Peter Xu
2024-06-19 22:30 ` [PATCH v3 06/11] migration/docs: Update postcopy recover session for SETUP phase Peter Xu
2024-06-19 22:30 ` [PATCH v3 07/11] tests/migration-tests: Drop most WIN32 ifdefs for postcopy failure tests Peter Xu
2024-06-19 22:30 ` [PATCH v3 08/11] tests/migration-tests: Always enable migration events Peter Xu
2024-06-20 13:20   ` Fabiano Rosas
2024-06-19 22:30 ` Peter Xu [this message]
2024-06-20 13:21   ` [PATCH v3 09/11] tests/migration-tests: migration_event_wait() Fabiano Rosas
2024-06-19 22:30 ` [PATCH v3 10/11] tests/migration-tests: Verify postcopy-recover-setup status Peter Xu
2024-06-20 13:21   ` Fabiano Rosas
2024-06-19 22:30 ` [PATCH v3 11/11] tests/migration-tests: Cover postcopy failure on reconnect Peter Xu
2024-06-21 17:38 ` [PATCH v3 00/11] migration: New postcopy state, and some cleanups Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240619223046.1798968-10-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=bdas@redhat.com \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=jdenemar@redhat.com \
    --cc=lizhijian@fujitsu.com \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).