From 2c7294d72c4086fc89935514430bd2bfb5ae5011 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 7 Oct 2021 01:07:30 +0400 Subject: [PATCH] tests/qtests: add qtest_qmp_add_client() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Acked-by: Gerd Hoffmann --- tests/qtest/libqos/libqtest.h | 10 ++++++++++ tests/qtest/libqtest.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index dff6b31cf0..a6d38d7ef7 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -745,6 +745,16 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, const char *fmt, ...) GCC_FMT_ATTR(4, 5); /** + * qtest_qmp_add_client: + * @qts: QTestState instance to operate on + * @protocol: the protocol to add to + * @fd: the client file-descriptor + * + * Call QMP ``getfd`` followed by ``add_client`` with the given @fd. + */ +void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd); + +/** * qtest_qmp_device_del: * @qts: QTestState instance to operate on * @id: Identification string diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 65ed949685..a68326caae 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1453,6 +1453,25 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, qobject_unref(args); } +void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd) +{ + QDict *resp; + + resp = qtest_qmp_fds(qts, &fd, 1, "{'execute': 'getfd'," + "'arguments': {'fdname': 'fdname'}}"); + g_assert(resp); + g_assert(!qdict_haskey(resp, "event")); /* We don't expect any events */ + g_assert(!qdict_haskey(resp, "error")); + qobject_unref(resp); + + resp = qtest_qmp( + qts, "{'execute': 'add_client'," + "'arguments': {'protocol': %s, 'fdname': 'fdname'}}", protocol); + g_assert(resp); + g_assert(!qdict_haskey(resp, "event")); /* We don't expect any events */ + g_assert(!qdict_haskey(resp, "error")); + qobject_unref(resp); +} /* * Generic hot-unplugging test via the device_del QMP command. -- 2.11.0