[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/12] libqtest: add qtest_socket_server()
From: |
Stefan Hajnoczi |
Subject: |
[PATCH 08/12] libqtest: add qtest_socket_server() |
Date: |
Tue, 27 Oct 2020 17:35:24 +0000 |
There is a qtest_socket_client() API. Add an equivalent
qtest_socket_server() API that returns a new UNIX domain socket in the
listen state. The code for this was already there but only used
internally in init_socket().
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/qtest/libqos/libqtest.h | 8 +++++++
tests/qtest/libqtest.c | 40 ++++++++++++++++++++---------------
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index 241b5f89fb..699be8c2a2 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -132,6 +132,14 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...)
void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
+/**
+ * qtest_socket_server:
+ * @socket_path: the UNIX domain socket path
+ *
+ * Create and return a listen socket file descriptor, or abort on failure.
+ */
+int qtest_socket_server(const char *socket_path);
+
/**
* qtest_socket_client:
* @server_socket_path: the socket server's path
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index ab34075f2b..d652ffc90d 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -82,24 +82,8 @@ static void qtest_client_set_rx_handler(QTestState *s,
QTestRecvFn recv);
static int init_socket(const char *socket_path)
{
- struct sockaddr_un addr;
- int sock;
- int ret;
-
- sock = socket(PF_UNIX, SOCK_STREAM, 0);
- g_assert_cmpint(sock, !=, -1);
-
- addr.sun_family = AF_UNIX;
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
+ int sock = qtest_socket_server(socket_path);
qemu_set_cloexec(sock);
-
- do {
- ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
- } while (ret == -1 && errno == EINTR);
- g_assert_cmpint(ret, !=, -1);
- ret = listen(sock, 1);
- g_assert_cmpint(ret, !=, -1);
-
return sock;
}
@@ -638,6 +622,28 @@ QTestState *qtest_create_state_with_qmp_fd(int fd)
return qmp_test_state;
}
+int qtest_socket_server(const char *socket_path)
+{
+ struct sockaddr_un addr;
+ int sock;
+ int ret;
+
+ sock = socket(PF_UNIX, SOCK_STREAM, 0);
+ g_assert_cmpint(sock, !=, -1);
+
+ addr.sun_family = AF_UNIX;
+ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
+
+ do {
+ ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
+ } while (ret == -1 && errno == EINTR);
+ g_assert_cmpint(ret, !=, -1);
+ ret = listen(sock, 1);
+ g_assert_cmpint(ret, !=, -1);
+
+ return sock;
+}
+
int qtest_socket_client(char *server_socket_path)
{
struct sockaddr_un serv_addr;
--
2.26.2
- [PATCH 00/12] block/export: vhost-user-blk server cleanups and tests, Stefan Hajnoczi, 2020/10/27
- [PATCH 01/12] libvhost-user: follow QEMU comment style, Stefan Hajnoczi, 2020/10/27
- [PATCH 02/12] configure: introduce --enable-vhost-user-blk-server, Stefan Hajnoczi, 2020/10/27
- [PATCH 03/12] block/export: make vhost-user-blk config space little-endian, Stefan Hajnoczi, 2020/10/27
- [PATCH 05/12] contrib/vhost-user-blk: fix get_config() information leak, Stefan Hajnoczi, 2020/10/27
- [PATCH 04/12] block/export: fix vhost-user-blk get_config() information leak, Stefan Hajnoczi, 2020/10/27
- [PATCH 07/12] tests/qtest: add multi-queue test case to vhost-user-blk-test, Stefan Hajnoczi, 2020/10/27
- [PATCH 10/12] vhost-user-blk-test: close fork child file descriptors, Stefan Hajnoczi, 2020/10/27
- [PATCH 09/12] vhost-user-blk-test: rename destroy_drive() to destroy_file(), Stefan Hajnoczi, 2020/10/27
- [PATCH 06/12] test: new qTest case to test the vhost-user-blk-server, Stefan Hajnoczi, 2020/10/27
- [PATCH 08/12] libqtest: add qtest_socket_server(),
Stefan Hajnoczi <=
- [PATCH 12/12] vhost-user-blk-test: fix races by using fd passing, Stefan Hajnoczi, 2020/10/27
- [PATCH 11/12] vhost-user-blk-test: drop unused return value, Stefan Hajnoczi, 2020/10/27
- Re: [PATCH 00/12] block/export: vhost-user-blk server cleanups and tests, Michael S. Tsirkin, 2020/10/30