[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/17] libqtest: add qtest_socket_server()
From: |
Michael S. Tsirkin |
Subject: |
[PULL 08/17] libqtest: add qtest_socket_server() |
Date: |
Sun, 15 Nov 2020 17:27:30 -0500 |
From: Stefan Hajnoczi <stefanha@redhat.com>
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>
Message-Id: <20201111124331.1393747-4-stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@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 d6236ea7a0..8792c09398 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 ff563cbaba..50a30f8e1f 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;
}
@@ -643,6 +627,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;
--
MST
- [PULL 00/17] pc,vhost: fixes, new test, Michael S. Tsirkin, 2020/11/15
- [PULL 01/17] vhost-user: fix VHOST_USER_ADD/REM_MEM_REG truncation, Michael S. Tsirkin, 2020/11/15
- [PULL 02/17] meson: move vhost_user_blk_server to meson.build, Michael S. Tsirkin, 2020/11/15
- [PULL 03/17] vhost-user-blk-server: depend on CONFIG_VHOST_USER, Michael S. Tsirkin, 2020/11/15
- [PULL 05/17] hw/i386/acpi-build: Fix maybe-uninitialized error when ACPI hotplug off, Michael S. Tsirkin, 2020/11/15
- [PULL 07/17] tests/qtest: add multi-queue test case to vhost-user-blk-test, Michael S. Tsirkin, 2020/11/15
- [PULL 08/17] libqtest: add qtest_socket_server(),
Michael S. Tsirkin <=
- [PULL 06/17] test: new qTest case to test the vhost-user-blk-server, Michael S. Tsirkin, 2020/11/15
- [PULL 09/17] vhost-user-blk-test: rename destroy_drive() to destroy_file(), Michael S. Tsirkin, 2020/11/15
- [PULL 11/17] vhost-user-blk-test: drop unused return value, Michael S. Tsirkin, 2020/11/15
- [PULL 12/17] vhost-user-blk-test: fix races by using fd passing, Michael S. Tsirkin, 2020/11/15
- [PULL 13/17] block/export: port virtio-blk discard/write zeroes input validation, Michael S. Tsirkin, 2020/11/15
- [PULL 14/17] vhost-user-blk-test: test discard/write zeroes invalid inputs, Michael S. Tsirkin, 2020/11/15
- [PULL 15/17] block/export: port virtio-blk read/write range check, Michael S. Tsirkin, 2020/11/15
- [PULL 16/17] contrib/libvhost-user: Fix bad printf format specifiers, Michael S. Tsirkin, 2020/11/15
- [PULL 04/17] configure: mark vhost-user Linux-only, Michael S. Tsirkin, 2020/11/15
- [PULL 10/17] vhost-user-blk-test: close fork child file descriptors, Michael S. Tsirkin, 2020/11/15