[Spice-devel] [spice-server 8/8] test-listen: Add Unix socket test
Christophe Fergeau
cfergeau at redhat.com
Tue Mar 6 13:53:22 UTC 2018
---
configure.ac | 3 +++
server/tests/Makefile.am | 4 +++-
server/tests/test-listen.c | 38 +++++++++++++++++++++++++++++++++++---
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index bcd4bb4d5..863834343 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,6 +171,9 @@ AS_VAR_APPEND([SPICE_REQUIRES], [" glib-2.0 >= $GLIB2_REQUIRED gio-2.0 >= $GLIB2
PKG_CHECK_MODULES([GOBJECT2], [gobject-2.0 >= $GLIB2_REQUIRED])
AS_VAR_APPEND([SPICE_REQUIRES], [" gobject-2.0 >= $GLIB2_REQUIRED"])
+#used only by tests
+PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= $GLIB2_REQUIRED])
+
PIXMAN_REQUIRED=0.17.7
PKG_CHECK_MODULES(PIXMAN, pixman-1 >= $PIXMAN_REQUIRED)
AC_SUBST(PIXMAN_CFLAGS)
diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 0aae1fd61..ffeb8fc04 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -16,8 +16,9 @@ AM_CPPFLAGS = \
-I$(top_builddir)/server \
-I$(top_srcdir)/server/tests \
$(COMMON_CFLAGS) \
+ $(GIO_UNIX_CFLAGS) \
$(GLIB2_CFLAGS) \
- $(GOBJECT2_CFLAGS) \
+ $(GOBJECT2_CFLAGS) \
$(SMARTCARD_CFLAGS) \
$(SPICE_NONPKGCONFIG_CFLAGS) \
$(SPICE_PROTOCOL_CFLAGS) \
@@ -39,6 +40,7 @@ LDADD = \
libtest.a \
$(top_builddir)/spice-common/common/libspice-common.la \
$(top_builddir)/server/libserver.la \
+ $(GIO_UNIX_LIBS) \
$(GLIB2_LIBS) \
$(GOBJECT2_LIBS) \
$(SPICE_NONPKGCONFIG_LIBS) \
diff --git a/server/tests/test-listen.c b/server/tests/test-listen.c
index 2a15df1ab..2658d61c5 100644
--- a/server/tests/test-listen.c
+++ b/server/tests/test-listen.c
@@ -27,6 +27,7 @@
#include <stdint.h>
#include <string.h>
#include <gio/gio.h>
+#include <gio/gunixsocketaddress.h>
#define PKI_DIR SPICE_TOP_SRCDIR "/server/tests/pki/"
@@ -207,9 +208,13 @@ static GThread *fake_client_new(GThreadFunc thread_func,
{
ThreadData *thread_data = g_new0(ThreadData, 1);
- g_assert_cmpuint(port, >, 0);
- g_assert_cmpuint(port, <, 65536);
- thread_data->connectable = g_network_address_new(hostname, port);
+ if (port == -1) {
+ thread_data->connectable = G_SOCKET_CONNECTABLE(g_unix_socket_address_new(hostname));
+ } else {
+ g_assert_cmpuint(port, >, 0);
+ g_assert_cmpuint(port, <, 65536);
+ thread_data->connectable = g_network_address_new(hostname, port);
+ }
thread_data->use_tls = use_tls;
thread_data->user_data = user_data;
@@ -310,6 +315,32 @@ static void test_connect_both(void)
spice_server_destroy(server);
}
+static void test_connect_unix(void)
+{
+ GThread *thread;
+ int result;
+
+ TestEventLoop event_loop = { 0, };
+
+ test_event_loop_init(&event_loop);
+
+ /* server */
+ SpiceServer *server = spice_server_new();
+ spice_server_set_name(server, "SPICE listen test");
+ spice_server_set_noauth(server);
+ spice_server_set_addr(server, "test-listen.unix", SPICE_ADDR_FLAG_UNIX_ONLY);
+ result = spice_server_init(server, event_loop.core);
+ g_assert_cmpint(result, ==, 0);
+
+ /* fake client */
+ thread = fake_client_new(check_magic_thread, "test-listen.unix", -1, false, &event_loop);
+ test_event_loop_run(&event_loop);
+ g_assert_null(g_thread_join(thread));
+
+ test_event_loop_destroy(&event_loop);
+ spice_server_destroy(server);
+}
+
static void test_connect_ko(void)
{
GThread *thread;
@@ -332,6 +363,7 @@ int main(int argc, char **argv)
g_test_add_func("/server/listen/connect_plain", test_connect_plain);
g_test_add_func("/server/listen/connect_tls", test_connect_tls);
g_test_add_func("/server/listen/connect_both", test_connect_both);
+ g_test_add_func("/server/listen/connect_unix", test_connect_unix);
g_test_add_func("/server/listen/connect_ko", test_connect_ko);
return g_test_run();
--
2.14.3
More information about the Spice-devel
mailing list