[Spice-devel] [PATCH spice-common] test-overflow: Remove dependency from libspice-common-{server, client}

Frediano Ziglio fziglio at redhat.com
Thu Jul 5 07:12:44 UTC 2018


Remove dependency from main protocol allowing to run the
test independently from generation setting.
This is useful with Meson allowing to not generate all code.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 tests/Makefile.am            |  9 ++++++---
 tests/meson.build            | 17 ++++++++++-------
 tests/test-marshallers.c     |  6 ++++--
 tests/test-marshallers.h     |  5 +++++
 tests/test-marshallers.proto |  5 +++++
 tests/test-overflow.c        |  8 ++++----
 6 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1021954..5367f4d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -70,6 +70,7 @@ TEST_MARSHALLERS =				\
 	generated_test_marshallers.c		\
 	generated_test_marshallers.h		\
 	generated_test_demarshallers.c		\
+	generated_test_enums.h			\
 	$(NULL)
 
 BUILT_SOURCES = $(TEST_MARSHALLERS)
@@ -92,6 +93,8 @@ generated_test_marshallers.h: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEP
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers --server --include test-marshallers.h -H $< $@ >/dev/null
 generated_test_demarshallers.c: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-demarshallers --client --include test-marshallers.h $< $@ >/dev/null
+generated_test_enums.h: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py -e $< $@ >/dev/null
 
 EXTRA_DIST =				\
 	$(TEST_MARSHALLERS)		\
@@ -100,7 +103,9 @@ EXTRA_DIST =				\
 	$(NULL)
 
 TESTS += test_overflow
-test_overflow_SOURCES = test-overflow.c
+test_overflow_SOURCES = test-overflow.c \
+	$(TEST_MARSHALLERS)		\
+	$(NULL)
 test_overflow_CFLAGS = \
 	-I$(top_srcdir) \
 	$(GLIB2_CFLAGS) \
@@ -109,8 +114,6 @@ test_overflow_CFLAGS = \
 	$(NULL)
 test_overflow_LDADD = \
 	$(top_builddir)/common/libspice-common.la \
-	$(top_builddir)/common/libspice-common-server.la \
-	$(top_builddir)/common/libspice-common-client.la \
 	$(NULL)
 
 -include $(top_srcdir)/git.mk
diff --git a/tests/meson.build b/tests/meson.build
index 94c72c6..38a4bea 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -4,11 +4,6 @@
 tests = ['test-logging', 'test-region']
 tests_deps = [spice_common_dep]
 
-if spice_common_generate_code == 'all'
-  tests += ['test-overflow']
-  tests_deps += [spice_common_client_dep, spice_common_server_dep]
-endif
-
 foreach t : tests
   name = t.underscorify()
   exe = executable(name, '@0 at .c'.format(t),
@@ -18,27 +13,35 @@ foreach t : tests
 endforeach
 
 #
-# test_marshallers
+# test_marshallers and test_overflow
 #
 test_proto = files('test-marshallers.proto')
 
 test_marshallers_sources = ['test-marshallers.c', 'test-marshallers.h']
+test_overflow_sources = ['test-overflow.c']
 
 targets = [
     ['test_marshallers', test_proto, 'generated_test_marshallers.c', ['--generate-marshallers', '--server', '--include', 'test-marshallers.h', '@INPUT@', '@OUTPUT@']],
     ['test_marshallers_h', test_proto, 'generated_test_marshallers.h', ['--generate-marshallers', '--server', '--include', 'test-marshallers.h', '-H', '@INPUT@', '@OUTPUT@']],
     ['test_demarshallers', test_proto, 'generated_test_demarshallers.c', ['--generate-demarshallers', '--client', '--include', 'test-marshallers.h', '@INPUT@', '@OUTPUT@']],
+    ['test_enums_h', test_proto, 'generated_test_enums.h', ['-e', '@INPUT@', '@OUTPUT@']],
 ]
 
 foreach t : targets
   cmd = [python, spice_codegen] + t[3]
-  test_marshallers_sources += custom_target(t[0], input: t[1], output : t[2], command: cmd, depend_files : spice_codegen_files)
+  target = custom_target(t[0], input: t[1], output : t[2], command: cmd, depend_files : spice_codegen_files)
+  test_marshallers_sources += target
+  test_overflow_sources += target
 endforeach
 
 test('test_marshallers',
      executable('test_marshallers', test_marshallers_sources,
                 dependencies : spice_common_dep,
                 install : false))
+test('test_overflow',
+     executable('test_overflow', test_overflow_sources,
+                dependencies : spice_common_dep,
+                install : false))
 
 #
 # test_quic
diff --git a/tests/test-marshallers.c b/tests/test-marshallers.c
index 3bd98e8..3e039b0 100644
--- a/tests/test-marshallers.c
+++ b/tests/test-marshallers.c
@@ -2,6 +2,7 @@
 #include <string.h>
 
 #include "common/marshaller.h"
+#include "generated_test_enums.h"
 #include "generated_test_marshallers.h"
 
 #ifndef g_assert_true
@@ -47,8 +48,9 @@ int main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
     g_free(msg);
 
     // test demarshaller
-    msg = (SpiceMsgMainShortDataSubMarshall *) spice_parse_msg(data, data + len, 1, 1, 0,
-                                                               &msg_len, &free_message);
+    msg = (SpiceMsgMainShortDataSubMarshall *)
+        spice_parse_msg(data, data + len, SPICE_CHANNEL_MAIN, SPICE_MSG_MAIN_SHORTDATASUBMARSHALL,
+                        0, &msg_len, &free_message);
 
     g_assert_nonnull(msg);
     g_assert_cmpint(msg->dummy_byte, ==, 123);
diff --git a/tests/test-marshallers.h b/tests/test-marshallers.h
index 46263d7..99877c0 100644
--- a/tests/test-marshallers.h
+++ b/tests/test-marshallers.h
@@ -16,5 +16,10 @@ typedef struct {
     uint16_t n;
 } SpiceMsgMainZeroes;
 
+typedef struct SpiceMsgChannels {
+    uint32_t num_of_channels;
+    uint16_t channels[0];
+} SpiceMsgChannels;
+
 #endif /* _H_TEST_MARSHALLERS */
 
diff --git a/tests/test-marshallers.proto b/tests/test-marshallers.proto
index 08d3e01..c75134e 100644
--- a/tests/test-marshallers.proto
+++ b/tests/test-marshallers.proto
@@ -14,6 +14,11 @@ channel TestChannel {
         uint16 n;
         uint32 res2 @zero;
     } Zeroes;
+
+    message {
+        uint32 num_of_channels;
+        uint16 channels[num_of_channels] @end;
+    } @ctype(SpiceMsgChannels) channels_list;
 };
 
 protocol Spice {
diff --git a/tests/test-overflow.c b/tests/test-overflow.c
index c972a25..13977e1 100644
--- a/tests/test-overflow.c
+++ b/tests/test-overflow.c
@@ -23,10 +23,10 @@
 #include <string.h>
 #include <assert.h>
 
-#include <spice/enums.h>
 #include <common/marshaller.h>
-#include <common/generated_server_marshallers.h>
 #include <common/client_demarshallers.h>
+#include "generated_test_enums.h"
+#include "generated_test_marshallers.h"
 
 #define NUM_CHANNELS 3u
 
@@ -45,13 +45,13 @@ int main(void)
     assert(m);
 
     msg = (SpiceMsgChannels *) malloc(sizeof(SpiceMsgChannels) +
-          NUM_CHANNELS * sizeof(SpiceChannelId));
+          NUM_CHANNELS * sizeof(uint16_t));
     assert(msg);
 
     // build a message and marshal it
     msg->num_of_channels = NUM_CHANNELS;
     for (n = 0; n < NUM_CHANNELS; ++n) {
-        msg->channels[n] = (SpiceChannelId) { n + 1, n * 7 };
+        msg->channels[n] = n + 1;
     }
     spice_marshall_msg_main_channels_list(m, msg);
 
-- 
2.17.1



More information about the Spice-devel mailing list