diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2020-05-21 16:47:28 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2020-05-21 16:47:28 +0100 |
commit | ae3aa5da96f4ccf0c2a28851449d92db9fcfad71 (patch) | |
tree | 89832eacef77d2ef17f3007a89e92c13df3cd0a8 /tests | |
parent | ad5a59124c251abd7e725fa3f6a3308c06d6b486 (diff) | |
parent | e339273bfc514824410a49837e4f16dd4e51ae8e (diff) | |
download | qemu-ae3aa5da96f4ccf0c2a28851449d92db9fcfad71.zip qemu-ae3aa5da96f4ccf0c2a28851449d92db9fcfad71.tar.gz qemu-ae3aa5da96f4ccf0c2a28851449d92db9fcfad71.tar.bz2 |
Merge remote-tracking branch 'remotes/berrange/tags/socket-next-pull-request' into staging
Add support for UNIX sockets in the abstract namespace
# gpg: Signature made Wed 20 May 2020 13:58:43 BST
# gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full]
# gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full]
# Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF
* remotes/berrange/tags/socket-next-pull-request:
qemu-options: updates for abstract unix sockets
tests/util-sockets: add abstract unix socket cases
qemu-sockets: add abstract UNIX domain socket support
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-util-sockets.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index 5fd947c..2ca1e99 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(); } |