From 3cd46d42fe632b4732eca23b15b99d1b26ee6f2c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 6 Aug 2018 08:53:37 +0200 Subject: tests: New helper qtest_qmp_receive_success() Commit b21373d0713 copied wait_command() from tests/migration-test.c to tests/tpm-util.c. Replace both copies by new libqtest helper qtest_qmp_receive_success(). Also use it to simplify qtest_qmp_device_del(). Bonus: gets rid of a non-literal format string. A step towards compile-time format string checking without triggering -Wformat-nonliteral. Cc: Thomas Huth Cc: Juan Quintela Cc: Dr. David Alan Gilbert Cc: Stefan Berger Signed-off-by: Markus Armbruster Reviewed-by: Juan Quintela Reviewed-by: Stefan Berger Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-17-armbru@redhat.com> --- tests/migration-test.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'tests/migration-test.c') diff --git a/tests/migration-test.c b/tests/migration-test.c index db652e30a0..402c82bdc4 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -149,31 +149,20 @@ static void wait_for_serial(const char *side) } while (true); } +static void stop_cb(void *opaque, const char *name, QDict *data) +{ + if (!strcmp(name, "STOP")) { + got_stop = true; + } +} + /* * Events can get in the way of responses we are actually waiting for. */ static QDict *wait_command(QTestState *who, const char *command) { - const char *event_string; - QDict *response, *ret; - - response = qtest_qmp(who, command); - - while (qdict_haskey(response, "event")) { - /* OK, it was an event */ - event_string = qdict_get_str(response, "event"); - if (!strcmp(event_string, "STOP")) { - got_stop = true; - } - qobject_unref(response); - response = qtest_qmp_receive(who); - } - - ret = qdict_get_qdict(response, "return"); - g_assert(ret); - qobject_ref(ret); - qobject_unref(response); - return ret; + qtest_qmp_send(who, command); + return qtest_qmp_receive_success(who, stop_cb, NULL); } /* -- cgit 1.4.1