summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2015-07-31 11:51:43 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2015-09-15 17:48:59 +0200
commit523875d8c5691bc07f4b50d89106f4f489400f0e (patch)
tree8191b3da703b315ae158023b1005e29d21ad5be8
parent7b146745eed1b4b5719362870576996512f08513 (diff)
Add marshaller test case
This allows to test the spice_marshaller_linearize() fix which was sent recently.
-rw-r--r--configure.ac1
-rw-r--r--tests/Makefile.am50
-rw-r--r--tests/test-marshallers.c39
-rw-r--r--tests/test-marshallers.h11
-rw-r--r--tests/test-marshallers.proto10
5 files changed, 111 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 98311bf..3468bbf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,7 @@ AC_SUBST(SPICE_COMMON_LIBS)
AC_CONFIG_FILES([
Makefile
common/Makefile
+ tests/Makefile
])
AH_BOTTOM([
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..cde46e4
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,50 @@
+NULL =
+
+TESTS = test_marshallers
+check_PROGRAMS = test_marshallers
+test_marshallers_SOURCES = \
+ generated_test_marshallers.c \
+ generated_test_marshallers.h \
+ test-marshallers.c \
+ test-marshallers.h \
+ $(NULL)
+test_marshallers_CFLAGS = \
+ -I$(top_srcdir)/common \
+ $(GLIB2_CFLAGS) \
+ $(PROTOCOL_CFLAGS) \
+ $(NULL)
+test_marshallers_LDFLAGS = \
+ $(top_builddir)/common/libspice-common.la \
+ $(GLIB2_LIBS) \
+ $(NULL)
+
+# Avoid need for python(pyparsing) by end users
+TEST_MARSHALLERS = \
+ generated_test_marshallers.c \
+ generated_test_marshallers.h \
+ $(NULL)
+
+BUILT_SOURCES = $(TEST_MARSHALLERS)
+
+MARSHALLERS_DEPS = \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/__init__.py \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/codegen.py \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/demarshal.py \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/marshal.py \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/ptypes.py \
+ $(CODE_GENERATOR_BASEDIR)/python_modules/spice_parser.py \
+ $(CODE_GENERATOR_BASEDIR)/spice_codegen.py \
+ $(NULL)
+
+# Note despite being autogenerated these are not part of CLEANFILES, they are
+# actually a part of EXTRA_DIST, to avoid the need for pyparser by end users
+generated_test_marshallers.c: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
+ $(AM_V_GEN)$(PYTHON) $(CODE_GENERATOR_BASEDIR)/spice_codegen.py --generate-marshallers --server --include test-marshallers.h $< $@ >/dev/null
+generated_test_marshallers.h: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
+ $(AM_V_GEN)$(PYTHON) $(CODE_GENERATOR_BASEDIR)/spice_codegen.py --generate-marshallers --server --include test-marshallers.h -H $< $@ >/dev/null
+
+EXTRA_DIST = \
+ $(TEST_MARSHALLERS) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/test-marshallers.c b/tests/test-marshallers.c
new file mode 100644
index 0000000..e3e4d09
--- /dev/null
+++ b/tests/test-marshallers.c
@@ -0,0 +1,39 @@
+#include <glib.h>
+#include <string.h>
+#include <marshaller.h>
+
+#include <generated_test_marshallers.h>
+
+static uint8_t expected_data[] = { 0x02, 0x00, 0x00, 0x00, /* data_size */
+ 0x08, 0x00, 0x00, 0x00, /* data offset */
+ 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, /* data */
+ 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, /* data */
+};
+
+int main(int argc, char **argv)
+{
+ SpiceMarshaller *marshaller;
+ SpiceMsgMainShortDataSubMarshall *msg;
+ size_t len;
+ int free_res;
+ uint8_t *data;
+
+ msg = spice_malloc0(sizeof(SpiceMsgMainShortDataSubMarshall) + 2 * sizeof(uint64_t));
+ msg->data_size = 2;
+ msg->data[0] = 0x1234567890abcdef;
+ msg->data[1] = 0x1234567890abcdef;
+
+ marshaller = spice_marshaller_new();
+ spice_marshall_msg_main_ShortDataSubMarshall(marshaller, msg);
+ spice_marshaller_flush(marshaller);
+ data = spice_marshaller_linearize(marshaller, 0, &len, &free_res);
+ g_assert_cmpint(len, ==, G_N_ELEMENTS(expected_data));
+ g_assert_true(memcmp(data, expected_data, len) == 0);
+ if (free_res) {
+ free(data);
+ }
+ spice_marshaller_destroy(marshaller);
+ free(msg);
+
+ return 0;
+}
diff --git a/tests/test-marshallers.h b/tests/test-marshallers.h
new file mode 100644
index 0000000..9cd34c7
--- /dev/null
+++ b/tests/test-marshallers.h
@@ -0,0 +1,11 @@
+#include <stdint.h>
+
+#ifndef _H_TEST_MARSHALLERS
+
+typedef struct {
+ uint32_t data_size;
+ uint64_t data[];
+} SpiceMsgMainShortDataSubMarshall;
+
+#endif /* _H_TEST_MARSHALLERS */
+
diff --git a/tests/test-marshallers.proto b/tests/test-marshallers.proto
new file mode 100644
index 0000000..e360b09
--- /dev/null
+++ b/tests/test-marshallers.proto
@@ -0,0 +1,10 @@
+channel TestChannel {
+ message {
+ uint32 data_size;
+ uint64 *data[data_size] @marshall;
+ } ShortDataSubMarshall;
+};
+
+protocol Spice {
+ TestChannel main = 1;
+};