[Spice-commits] configure.ac server/Makefile.am server/tests

Alon Levy alon at kemper.freedesktop.org
Mon Nov 8 06:04:50 PST 2010


 configure.ac                                    |    1 
 server/Makefile.am                              |    2 
 server/tests/Makefile.am                        |   25 ++++
 server/tests/README                             |   24 ++++
 server/tests/basic_event_loop.c                 |  144 ++++++++++++++++++++++++
 server/tests/basic_event_loop.h                 |    9 +
 server/tests/test_empty_success.c               |   57 +++++++++
 server/tests/test_fail_on_null_core_interface.c |   13 ++
 server/tests/test_just_sockets_no_ssl.c         |   19 +++
 9 files changed, 294 insertions(+)

New commits:
commit 0ede43e893721807813b2ad09b2a2ce8c213abe6
Author: Alon Levy <alevy at redhat.com>
Date:   Wed Nov 3 01:51:23 2010 +0200

    server: tests: add basic tests with working do nothing server

diff --git a/configure.ac b/configure.ac
index 0ab6dd8..8742fab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -394,6 +394,7 @@ common/win/Makefile
 common/win/my_getopt-1.5/Makefile
 python_modules/Makefile
 server/Makefile
+server/tests/Makefile
 client/Makefile
 client/x11/Makefile
 client/x11/images/Makefile
diff --git a/server/Makefile.am b/server/Makefile.am
index debcd27..3ccb9a2 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = . tests
+
 NULL =
 
 INCLUDES = \
diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
new file mode 100644
index 0000000..dbae555
--- /dev/null
+++ b/server/tests/Makefile.am
@@ -0,0 +1,25 @@
+NULL =
+
+INCLUDES = 	\
+	-I..		\
+	$(PROTOCOL_CFLAGS) \
+	$(SPICE_NONPKGCONFIG_CFLAGS)			\
+	$(NULL)
+
+LDFLAGS = -L../.libs -lspice-server
+
+bin_PROGRAMS = test_just_sockets_no_ssl test_empty_success test_fail_on_null_core_interface
+
+test_just_sockets_no_ssl_SOURCES = test_just_sockets_no_ssl.c basic_event_loop.c
+
+test_just_sockets_no_ssl_LDFLAGS = $(LDFLAGS)
+
+test_empty_success_SOURCES = test_empty_success.c
+
+test_empty_success_LDFLAGS = $(LDFLAGS)
+
+test_fail_on_null_core_interface_SOURCES = test_fail_on_null_core_interface.c
+
+test_fail_on_null_core_interface_LDFLAGS = $(LDFLAGS)
+
+
diff --git a/server/tests/README b/server/tests/README
new file mode 100644
index 0000000..477ca0c
--- /dev/null
+++ b/server/tests/README
@@ -0,0 +1,24 @@
+What is here
+============
+
+This directory will contain a testsuite for the server including tetris drawing.
+
+Unfortunately tetris and most of the tests are not here right now. You can however run all the tests and use libtool to debug any of them thus:
+
+libtool --mode=execute gdb test_just_sockets_no_ssl
+
+Overview of tests
+=================
+
+test_just_sockets_no_ssl
+ A complete server, only provides the main and inputs channels. Doesn't actually produce anything on the channels. Essentially a test of the regular link code (reds.c), good for multiple connect/disconnect tests.
+
+test_empty_success
+ tests calling 
+
+test_fail_on_null_core_interface
+ should abort when run (when spice tries to watch_add)
+
+basic_event_loop.c
+ used by test_just_sockets_no_ssl, can be used by other tests. very crude event loop. Should probably use libevent for better tests, but this is self contained.
+
diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
new file mode 100644
index 0000000..14dec51
--- /dev/null
+++ b/server/tests/basic_event_loop.c
@@ -0,0 +1,144 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "basic_event_loop.h"
+
+#define NOT_IMPLEMENTED printf("%s not implemented\n", __func__);
+
+static SpiceCoreInterface core;
+
+static SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque)
+{
+    NOT_IMPLEMENTED
+}
+
+static void timer_start(SpiceTimer *timer, uint32_t ms)
+{
+    NOT_IMPLEMENTED
+}
+
+static void timer_cancel(SpiceTimer *timer)
+{
+    NOT_IMPLEMENTED
+}
+
+static void timer_remove(SpiceTimer *timer)
+{
+    NOT_IMPLEMENTED
+}
+
+struct SpiceWatch {
+    int id;
+};
+
+typedef struct Watch {
+    SpiceWatch id;
+    int fd;
+    int event_mask;
+    SpiceWatchFunc func;
+    void *opaque;
+} Watch;
+
+Watch watches[100];
+int watch_count = 0;
+int next_id = 1;
+
+static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+{
+    watches[watch_count].fd = fd;
+    watches[watch_count].event_mask = event_mask;
+    watches[watch_count].func = func;
+    watches[watch_count].opaque = opaque;
+    watches[watch_count].id.id = next_id++;
+    return &watches[watch_count++].id;
+}
+
+static void watch_update_mask(SpiceWatch *watch, int event_mask)
+{
+    int i;
+    Watch *my_watch;
+
+    for (i = 0 ; i < watch_count; ++i) {
+        if (watches[i].id.id == watch->id) {
+            my_watch = &watches[i];
+            if (my_watch->event_mask != event_mask) {
+                my_watch->event_mask = event_mask;
+            }
+            return;
+        }
+    }
+}
+
+static void watch_remove(SpiceWatch *watch)
+{
+    int i;
+
+    for (i = 0 ; i < watch_count ; ++i) {
+        if (watches[i].id.id == watch->id) {
+            watches[i] = watches[--watch_count];
+            return;
+        }
+    }
+}
+
+static void channel_event(int event, SpiceChannelEventInfo *info)
+{
+    NOT_IMPLEMENTED
+}
+
+void basic_event_loop_mainloop(void)
+{
+    fd_set rfds, wfds;
+    int max_fd = -1;
+    int i;
+    int retval;
+
+    while (1) {
+        FD_ZERO(&rfds);
+        FD_ZERO(&wfds);
+        for (i = 0 ; i < watch_count; ++i) {
+            Watch* watch = &watches[i];
+            if (watch->event_mask & SPICE_WATCH_EVENT_READ) {
+                FD_SET(watch->fd, &rfds);
+                max_fd = watch->fd > max_fd ? watch->fd : max_fd;
+            }
+            if (watch->event_mask & SPICE_WATCH_EVENT_WRITE) {
+                FD_SET(watch->fd, &wfds);
+                max_fd = watch->fd > max_fd ? watch->fd : max_fd;
+            }
+        }
+        retval = select(max_fd + 1, &rfds, &wfds, NULL, NULL);
+        if (retval == -1) {
+            printf("error in select - exiting\n");
+            exit(-1);
+        }
+        if (retval) {
+            for (i = 0 ; i < watch_count; ++i) {
+                Watch* watch = &watches[i];
+                if ((watch->event_mask & SPICE_WATCH_EVENT_READ) && FD_ISSET(watch->fd, &rfds)) {
+                    watch->func(watch->fd, SPICE_WATCH_EVENT_READ, watch->opaque);
+                }
+                if ((watch->event_mask & SPICE_WATCH_EVENT_WRITE) && FD_ISSET(watch->fd, &wfds)) {
+                    watch->func(watch->fd, SPICE_WATCH_EVENT_WRITE, watch->opaque);
+                }
+            }
+        }
+    }
+}
+
+SpiceCoreInterface *basic_event_loop_init(void)
+{
+    bzero(&core, sizeof(core));
+    core.base.major_version = SPICE_INTERFACE_CORE_MAJOR;
+    core.base.minor_version = SPICE_INTERFACE_CORE_MINOR; // anything less then 3 and channel_event isn't called
+    core.timer_add = timer_add;
+    core.timer_start = timer_start;
+    core.timer_cancel = timer_cancel;
+    core.timer_remove = timer_remove;
+    core.watch_add = watch_add;
+    core.watch_update_mask = watch_update_mask;
+    core.watch_remove = watch_remove;
+    core.channel_event = channel_event;
+    return &core;
+}
+
diff --git a/server/tests/basic_event_loop.h b/server/tests/basic_event_loop.h
new file mode 100644
index 0000000..5f6ebe7
--- /dev/null
+++ b/server/tests/basic_event_loop.h
@@ -0,0 +1,9 @@
+#ifndef __BASIC_EVENT_LOOP_H__
+#define __BASIC_EVENT_LOOP_H__
+
+#include <spice.h>
+
+SpiceCoreInterface *basic_event_loop_init(void);
+void basic_event_loop_mainloop(void);
+
+#endif // __BASIC_EVENT_LOOP_H__
diff --git a/server/tests/test_empty_success.c b/server/tests/test_empty_success.c
new file mode 100644
index 0000000..e747e40
--- /dev/null
+++ b/server/tests/test_empty_success.c
@@ -0,0 +1,57 @@
+#include <strings.h>
+#include <spice.h>
+
+SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque)
+{
+}
+
+void timer_start(SpiceTimer *timer, uint32_t ms)
+{
+}
+
+void timer_cancel(SpiceTimer *timer)
+{
+}
+
+void timer_remove(SpiceTimer *timer)
+{
+}
+
+SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+{
+}
+
+void watch_update_mask(SpiceWatch *watch, int event_mask)
+{
+}
+
+void watch_remove(SpiceWatch *watch)
+{
+}
+
+void channel_event(int event, SpiceChannelEventInfo *info)
+{
+}
+
+int main()
+{
+    SpiceServer *server = spice_server_new();
+    SpiceCoreInterface core;
+
+    bzero(&core, sizeof(core));
+    core.base.major_version = SPICE_INTERFACE_CORE_MAJOR;
+    core.timer_add = timer_add;
+    core.timer_start = timer_start;
+    core.timer_cancel = timer_cancel;
+    core.timer_remove = timer_remove;
+    core.watch_add = watch_add;
+    core.watch_update_mask = watch_update_mask;
+    core.watch_remove = watch_remove;
+    core.channel_event = channel_event;
+
+    spice_server_set_port(server, 5911);
+    spice_server_init(server, &core);
+
+    return 0;
+}
+
diff --git a/server/tests/test_fail_on_null_core_interface.c b/server/tests/test_fail_on_null_core_interface.c
new file mode 100644
index 0000000..699b2a2
--- /dev/null
+++ b/server/tests/test_fail_on_null_core_interface.c
@@ -0,0 +1,13 @@
+#include <spice.h>
+
+int main()
+{
+    SpiceServer *server = spice_server_new();
+    SpiceCoreInterface core;
+
+    spice_server_init(server, &core);
+    spice_server_set_port(server, 5911);
+
+    return 0;
+}
+
diff --git a/server/tests/test_just_sockets_no_ssl.c b/server/tests/test_just_sockets_no_ssl.c
new file mode 100644
index 0000000..38d3a63
--- /dev/null
+++ b/server/tests/test_just_sockets_no_ssl.c
@@ -0,0 +1,19 @@
+#include <strings.h>
+#include <sys/select.h>
+#include <spice.h>
+#include "basic_event_loop.h"
+
+int main()
+{
+    SpiceServer *server = spice_server_new();
+    SpiceCoreInterface *core = basic_event_loop_init();
+
+    spice_server_set_port(server, 5912);
+    spice_server_set_noauth(server);
+    spice_server_init(server, core);
+
+    basic_event_loop_mainloop();
+
+    return 0;
+}
+


More information about the Spice-commits mailing list