[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/10] libqtest: make qtest_qmp_add_client work on win32
From: |
marcandre . lureau |
Subject: |
[PATCH 09/10] libqtest: make qtest_qmp_add_client work on win32 |
Date: |
Tue, 3 Jan 2023 15:08:13 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Use the "get-win32-socket" function to pass an opened socket to QEMU,
instead of using "getfd", which relies on socket ancillary FD message
passing.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
tests/qtest/libqtest.h | 5 ++---
tests/qtest/libqtest.c | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index fcf1c3c3b3..8d7d450963 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -758,17 +758,16 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const
char *drv,
void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
const char *fmt, ...) G_GNUC_PRINTF(4, 5);
-#ifndef _WIN32
/**
* 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.
+ * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
+ * ``add_client`` with the given @fd.
*/
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
-#endif /* _WIN32 */
/**
* qtest_qmp_device_del_send:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 2fbc3b88f3..63ec328e27 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1440,13 +1440,26 @@ void qtest_qmp_device_add(QTestState *qts, const char
*driver, const char *id,
qobject_unref(args);
}
-#ifndef _WIN32
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
{
QDict *resp;
+#ifdef WIN32
+ WSAPROTOCOL_INFOW info;
+ g_autofree char *info64 = NULL;
+
+ assert(fd_is_socket(fd));
+ if (WSADuplicateSocketW(fd, GetProcessId((HANDLE)qts->qemu_pid), &info) ==
SOCKET_ERROR) {
+ g_autofree char *emsg = g_win32_error_message(WSAGetLastError());
+ g_error("WSADuplicateSocketW failed: %s", emsg);
+ }
+ info64 = g_base64_encode((guchar *)&info, sizeof(info));
+ resp = qtest_qmp(qts, "{'execute': 'get-win32-socket',"
+ "'arguments': {'fdname': 'fdname', 'info': %s}}", info64);
+#else
resp = qtest_qmp_fds(qts, &fd, 1, "{'execute': 'getfd',"
"'arguments': {'fdname': 'fdname'}}");
+#endif
g_assert(resp);
g_assert(!qdict_haskey(resp, "event")); /* We don't expect any events */
g_assert(!qdict_haskey(resp, "error"));
@@ -1460,7 +1473,6 @@ void qtest_qmp_add_client(QTestState *qts, const char
*protocol, int fd)
g_assert(!qdict_haskey(resp, "error"));
qobject_unref(resp);
}
-#endif
/*
* Generic hot-unplugging test via the device_del QMP command.
--
2.39.0
- [PATCH 04/10] tests/docker: fix a win32 error due to portability, (continued)
- [PATCH 04/10] tests/docker: fix a win32 error due to portability, marcandre . lureau, 2023/01/03
- [PATCH 05/10] tests/readconfig: spice doesn't support unix socket on windows yet, marcandre . lureau, 2023/01/03
- [PATCH 06/10] osdep: implement qemu_socketpair() for win32, marcandre . lureau, 2023/01/03
- [PATCH 07/10] qmp: 'add_client' actually expects sockets, marcandre . lureau, 2023/01/03
- [PATCH 08/10] qmp: add 'get-win32-socket', marcandre . lureau, 2023/01/03
- [PATCH 09/10] libqtest: make qtest_qmp_add_client work on win32,
marcandre . lureau <=
- [PATCH 10/10] qtest: enable vnc-display test on win32, marcandre . lureau, 2023/01/03
- Re: [PATCH 00/10] Various win32 fixes & new 'get-win32-socket' QMP command, Philippe Mathieu-Daudé, 2023/01/03