From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"xiaoqiang zhao" <zxq_yx_007@163.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PULL 2/3] tests/util-sockets: add abstract unix socket cases
Date: Wed, 20 May 2020 14:00:24 +0100 [thread overview]
Message-ID: <20200520130025.2201467-3-berrange@redhat.com> (raw)
In-Reply-To: <20200520130025.2201467-1-berrange@redhat.com>
From: xiaoqiang zhao <zxq_yx_007@163.com>
add cases to test tight and non-tight for abstract address type
Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
tests/test-util-sockets.c | 92 +++++++++++++++++++++++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index 5fd947c7bf..2ca1e99f17 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -227,6 +227,93 @@ static void test_socket_fd_pass_num_nocli(void)
g_free(addr.u.fd.str);
}
+#ifdef __linux__
+static gchar *abstract_sock_name;
+
+static gpointer unix_server_thread_func(gpointer user_data)
+{
+ SocketAddress addr;
+ Error *err = NULL;
+ int fd = -1;
+ int connfd = -1;
+ struct sockaddr_un un;
+ socklen_t len = sizeof(un);
+
+ addr.type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr.u.q_unix.path = abstract_sock_name;
+ addr.u.q_unix.tight = user_data != NULL;
+ addr.u.q_unix.abstract = true;
+
+ fd = socket_listen(&addr, 1, &err);
+ g_assert_cmpint(fd, >=, 0);
+ g_assert(fd_is_socket(fd));
+
+ connfd = accept(fd, (struct sockaddr *)&un, &len);
+ g_assert_cmpint(connfd, !=, -1);
+
+ close(fd);
+
+ return NULL;
+}
+
+static gpointer unix_client_thread_func(gpointer user_data)
+{
+ SocketAddress addr;
+ Error *err = NULL;
+ int fd = -1;
+
+ addr.type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr.u.q_unix.path = abstract_sock_name;
+ addr.u.q_unix.tight = user_data != NULL;
+ addr.u.q_unix.abstract = true;
+
+ fd = socket_connect(&addr, &err);
+
+ g_assert_cmpint(fd, >=, 0);
+
+ close(fd);
+
+ return NULL;
+}
+
+static void test_socket_unix_abstract_good(void)
+{
+ GRand *r = g_rand_new();
+
+ abstract_sock_name = g_strdup_printf("unix-%d-%d", getpid(),
+ g_rand_int_range(r, 100, 1000));
+
+ /* non tight socklen serv and cli */
+ GThread *serv = g_thread_new("abstract_unix_server",
+ unix_server_thread_func,
+ NULL);
+
+ sleep(1);
+
+ GThread *cli = g_thread_new("abstract_unix_client",
+ unix_client_thread_func,
+ NULL);
+
+ g_thread_join(cli);
+ g_thread_join(serv);
+
+ /* tight socklen serv and cli */
+ serv = g_thread_new("abstract_unix_server",
+ unix_server_thread_func,
+ (gpointer)1);
+
+ sleep(1);
+
+ cli = g_thread_new("abstract_unix_client",
+ unix_client_thread_func,
+ (gpointer)1);
+
+ g_thread_join(cli);
+ g_thread_join(serv);
+
+ g_free(abstract_sock_name);
+}
+#endif
int main(int argc, char **argv)
{
@@ -265,6 +352,11 @@ int main(int argc, char **argv)
test_socket_fd_pass_num_nocli);
}
+#ifdef __linux__
+ g_test_add_func("/util/socket/unix-abstract/good",
+ test_socket_unix_abstract_good);
+#endif
+
end:
return g_test_run();
}
--
2.26.2
next prev parent reply other threads:[~2020-05-20 13:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 13:00 [PULL 0/3] Socket next patches Daniel P. Berrangé
2020-05-20 13:00 ` [PULL 1/3] qemu-sockets: add abstract UNIX domain socket support Daniel P. Berrangé
2020-05-20 14:23 ` Markus Armbruster
2020-05-20 14:33 ` Daniel P. Berrangé
2020-05-20 13:00 ` Daniel P. Berrangé [this message]
2020-05-20 13:00 ` [PULL 3/3] qemu-options: updates for abstract unix sockets Daniel P. Berrangé
2020-05-21 18:58 ` [PULL 0/3] Socket next patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200520130025.2201467-3-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zxq_yx_007@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).