[Spice-devel] [PATCH spice-gtk 3/4] tests: add some coroutine tests

Marc-André Lureau marcandre.lureau at gmail.com
Fri Nov 15 13:03:41 PST 2013


---
 tests/Makefile.am | 18 ++++++++-----
 tests/coroutine.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 7 deletions(-)
 create mode 100644 tests/coroutine.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9510e2c..6f80d93 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,18 +1,22 @@
 NULL =
 
-noinst_PROGRAMS = util
+noinst_PROGRAMS =				\
+	coroutine				\
+	util					\
+	$(NULL)
+
 TESTS = $(noinst_PROGRAMS)
 
 AM_CPPFLAGS =					\
 	$(GIO_CFLAGS) -I$(top_srcdir)/gtk	\
 	-DG_LOG_DOMAIN=\"GSpice\"		\
 	$(NULL)
-AM_LDFLAGS = $(GIO_LIBS)
 
-util_SOURCES =					\
-	$(top_srcdir)/gtk/spice-util-priv.h	\
-	$(top_srcdir)/gtk/spice-util.c		\
-	$(top_srcdir)/gtk/spice-util.h  	\
-	util.c					\
+AM_LDFLAGS = $(GIO_LIBS) -static
+
+LDADD =							\
+	$(top_builddir)/gtk/libspice-client-glib-2.0.la	\
 	$(NULL)
 
+util_SOURCES = util.c
+coroutine_SOURCES = coroutine.c
diff --git a/tests/coroutine.c b/tests/coroutine.c
new file mode 100644
index 0000000..da0c130
--- /dev/null
+++ b/tests/coroutine.c
@@ -0,0 +1,80 @@
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "coroutine.h"
+
+static gpointer co_entry_check_self(gpointer data)
+{
+    g_assert(data == coroutine_self());
+
+    return NULL;
+}
+
+static gpointer co_entry_42(gpointer data)
+{
+    g_assert(GPOINTER_TO_INT(data) == 42);
+
+    return GINT_TO_POINTER(42);
+}
+
+static void test_coroutine_simple(void)
+{
+    struct coroutine *self = coroutine_self();
+    struct coroutine co = {
+        .stack_size = 16 << 20,
+        .entry = co_entry_42,
+    };
+    gpointer result;
+
+    coroutine_init(&co);
+    result = coroutine_yieldto(&co, GINT_TO_POINTER(42));
+    g_assert_cmpint(GPOINTER_TO_INT(result), ==, 42);
+
+#if GLIB_CHECK_VERSION(2,34,0)
+    g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*!to->exited*");
+    coroutine_yieldto(&co, GINT_TO_POINTER(42));
+    g_test_assert_expected_messages();
+#endif
+
+    g_assert(self == coroutine_self());
+}
+
+static gpointer co_entry_two(gpointer data)
+{
+    struct coroutine *self = coroutine_self();
+    struct coroutine co = {
+        .stack_size = 16 << 20,
+        .entry = co_entry_check_self,
+    };
+
+    coroutine_init(&co);
+    coroutine_yieldto(&co, &co);
+
+    g_assert(self == coroutine_self());
+}
+
+static void test_coroutine_two(void)
+{
+    struct coroutine *self = coroutine_self();
+    struct coroutine co = {
+        .stack_size = 16 << 20,
+        .entry = co_entry_two,
+    };
+
+    coroutine_init(&co);
+    coroutine_yieldto(&co, NULL);
+
+    g_assert(self == coroutine_self());
+}
+
+int main(int argc, char* argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/coroutine/simple", test_coroutine_simple);
+    g_test_add_func("/coroutine/two", test_coroutine_two);
+
+    return g_test_run ();
+}
-- 
1.8.3.1



More information about the Spice-devel mailing list