[PATCH wayland v2 2/4] tests: Test static symbol visibility

Jonas Ådahl jadahl at gmail.com
Wed Jul 26 08:16:34 UTC 2017


Test that it is possible to inline the protocol 'code' file generated
by wayland-scanner in the source code files using it.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---

Changes since v1: none.


 .gitignore                        |   5 ++
 Makefile.am                       |  32 ++++++++-
 tests/data/tiny.xml               |  38 ++++++++++
 tests/static-symbol-test-client.c |  78 ++++++++++++++++++++
 tests/static-symbol-test-server.c | 147 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 297 insertions(+), 3 deletions(-)
 create mode 100644 tests/data/tiny.xml
 create mode 100644 tests/static-symbol-test-client.c
 create mode 100644 tests/static-symbol-test-server.c

diff --git a/.gitignore b/.gitignore
index 8da9861..553ffd0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,8 @@ exec-fd-leak-checker
 fixed-benchmark
 /wayland-scanner
 protocol/*.[ch]
+static-tiny-protocol.inc
+static-tiny-server-protocol-core.h
+static-tiny-client-protocol-core.h
+static-symbol-test-server
+static-symbol-test-client
diff --git a/Makefile.am b/Makefile.am
index d570525..bbd5107 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -114,7 +114,10 @@ protocol/%-client-protocol-core.h : $(top_srcdir)/protocol/%.xml
 BUILT_SOURCES =					\
 	$(nodist_libwayland_server_la_SOURCES)	\
 	$(nodist_libwayland_client_la_SOURCES)	\
-	$(nodist_headers_test_SOURCES)
+	$(nodist_headers_test_SOURCES)		\
+	$(nodist_static_symbol_test_server_SOURCES)	\
+	$(nodist_static_symbol_test_client_SOURCES)	\
+	static-tiny-protocol.inc
 
 CLEANFILES = $(BUILT_SOURCES) doc/doxygen/doxygen_sqlite3.db
 DISTCLEANFILES = src/wayland-version.h
@@ -164,7 +167,11 @@ built_test_programs =				\
 	message-test				\
 	headers-test				\
 	compositor-introspection-test		\
-	protocol-logger-test
+	protocol-logger-test			\
+	static-symbol-test-server
+
+built_test_program_helpers =			\
+	static-symbol-test-client
 
 if ENABLE_CPP_TEST
 built_test_programs += cpp-compile-test
@@ -172,6 +179,7 @@ endif
 
 AM_TESTS_ENVIRONMENT =							\
 	export WAYLAND_SCANNER='$(top_builddir)/wayland-scanner'	\
+	export TOP_BUILDDIR='$(top_builddir)'				\
 	TEST_DATA_DIR='$(top_srcdir)/tests/data'			\
 	TEST_OUTPUT_DIR='$(top_builddir)/tests/output'			\
 	SED=$(SED)							\
@@ -182,6 +190,7 @@ TESTS = $(built_test_programs)			\
 
 noinst_PROGRAMS =				\
 	$(built_test_programs)			\
+	$(built_test_program_helpers)		\
 	exec-fd-leak-checker			\
 	fixed-benchmark
 
@@ -200,6 +209,14 @@ libtest_runner_la_LIBADD =			\
 	libwayland-server.la			\
 	-lrt -ldl $(FFI_LIBS)
 
+static-tiny-protocol.inc : tests/data/tiny.xml
+	$(AM_V_GEN)$(wayland_scanner) -c -Vstatic code $< $@
+
+static-tiny-server-protocol-core.h : tests/data/tiny.xml
+	$(AM_V_GEN)$(wayland_scanner) -c -Vstatic server-header $< $@
+
+static-tiny-client-protocol-core.h : tests/data/tiny.xml
+	$(AM_V_GEN)$(wayland_scanner) -c -Vstatic client-header $< $@
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -245,6 +262,14 @@ headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =			\
 	protocol/wayland-server-protocol-core.h	\
 	protocol/wayland-client-protocol-core.h
+static_symbol_test_server_SOURCES = tests/static-symbol-test-server.c
+nodist_static_symbol_test_server_SOURCES = \
+	static-tiny-server-protocol-core.h
+static_symbol_test_server_LDADD = libtest-runner.la
+static_symbol_test_client_SOURCES = tests/static-symbol-test-client.c
+nodist_static_symbol_test_client_SOURCES = \
+	static-tiny-client-protocol-core.h
+static_symbol_test_client_LDADD = libtest-runner.la
 
 if ENABLE_CPP_TEST
 cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
@@ -270,7 +295,8 @@ EXTRA_DIST += tests/scanner-test.sh			\
 	tests/data/small-server.h			\
 	tests/data/small-code-core.c			\
 	tests/data/small-client-core.h			\
-	tests/data/small-server-core.h
+	tests/data/small-server-core.h			\
+	tests/data/tiny.xml
 
 tests/scanner-test.sh: $(top_builddir)/wayland-scanner
 
diff --git a/tests/data/tiny.xml b/tests/data/tiny.xml
new file mode 100644
index 0000000..0b8cdde
--- /dev/null
+++ b/tests/data/tiny.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="small_test">
+
+  <copyright>
+    Copyright © 2017 Red Hat Inc.
+
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation files
+    (the "Software"), to deal in the Software without restriction,
+    including without limitation the rights to use, copy, modify, merge,
+    publish, distribute, sublicense, and/or sell copies of the Software,
+    and to permit persons to whom the Software is furnished to do so,
+    subject to the following conditions:
+
+    The above copyright notice and this permission notice (including the
+    next paragraph) shall be included in all copies or substantial
+    portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+    BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+    ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+    SOFTWARE.
+  </copyright>
+
+  <interface name="tiny_intf" version="1">
+    <request name="destroy" type="destructor"/>
+    <request name="req">
+      <arg name="obj" type="new_id" interface="tiny_intf_obj"/>
+    </request>
+  </interface>
+  <interface name="tiny_intf_obj" version="1">
+    <request name="destroy" type="destructor"/>
+  </interface>
+</protocol>
diff --git a/tests/static-symbol-test-client.c b/tests/static-symbol-test-client.c
new file mode 100644
index 0000000..ff9d1b6
--- /dev/null
+++ b/tests/static-symbol-test-client.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "wayland-client.h"
+#include "static-tiny-client-protocol-core.h"
+#include "static-tiny-protocol.inc"
+
+static struct wl_display *display;
+
+static void
+registry_handle_global(void *data, struct wl_registry *registry,
+		       uint32_t id, const char *interface, uint32_t version)
+{
+	struct tiny_intf *tiny_intf;
+	struct tiny_intf_obj *tiny_intf_obj;
+
+	assert(strcmp(interface, "tiny_intf") == 0);
+
+	tiny_intf = wl_registry_bind(registry, id,
+				     &tiny_intf_interface,
+				     version);
+	assert(tiny_intf);
+	tiny_intf_obj = tiny_intf_req(tiny_intf);
+	assert(tiny_intf_obj);
+	wl_display_flush(display);
+}
+
+static const struct wl_registry_listener registry_listener = {
+	registry_handle_global,
+	NULL
+};
+
+int
+main(void)
+{
+	struct wl_registry *registry;
+
+	alarm(5);
+
+	display = wl_display_connect(NULL);
+	assert(display);
+
+	registry = wl_display_get_registry(display);
+	assert(registry);
+	wl_registry_add_listener(registry, &registry_listener, NULL);
+
+	while (!wl_display_dispatch(display));
+
+	return 0;
+}
diff --git a/tests/static-symbol-test-server.c b/tests/static-symbol-test-server.c
new file mode 100644
index 0000000..ee07cf3
--- /dev/null
+++ b/tests/static-symbol-test-server.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "wayland-server.h"
+
+#include "static-tiny-protocol.inc"
+#include "static-tiny-server-protocol-core.h"
+
+static bool object_created;
+static struct wl_display *display;
+
+static void
+handle_req(struct wl_client *client,
+	   struct wl_resource *resource, uint32_t id)
+{
+	struct wl_resource *tiny_intf_obj;
+
+	tiny_intf_obj = wl_resource_create(client, &tiny_intf_obj_interface,
+					   wl_resource_get_version(resource),
+					   id);
+	assert(tiny_intf_obj);
+
+	object_created = true;
+	wl_display_terminate(display);
+}
+
+static const struct tiny_intf_interface tiny_intf_implementation = {
+	NULL,
+	handle_req
+};
+
+static void
+bind_tiny_intf(struct wl_client *client, void *user_data,
+	       uint32_t version, uint32_t id)
+{
+	struct wl_resource *resource;
+
+	resource = wl_resource_create(client, &tiny_intf_interface,
+				      version, id);
+	assert(resource);
+
+	wl_resource_set_implementation(resource, &tiny_intf_implementation,
+				       NULL, NULL);
+}
+
+static pid_t
+spawn_client(void)
+{
+	int fds[2];
+	pid_t pid;
+	struct wl_client *client;
+
+	assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
+	pid = fork();
+	assert(pid != -1);
+
+	if (pid == 0) {
+		char fd_string[256];
+		char *builddir;
+		char test_client_path[2048];
+
+		close(fds[1]);
+		builddir = getenv("TOP_BUILDDIR");
+		assert(builddir && strlen(builddir) > 0);
+		snprintf(test_client_path, sizeof test_client_path,
+			 "%s/static-symbol-test-client",
+			 builddir);
+
+		snprintf(fd_string, sizeof fd_string, "%d", fds[0]);
+		setenv("WAYLAND_SOCKET", fd_string, 0);
+
+		execl(test_client_path, test_client_path, NULL);
+		assert(!"Failed to execute client");
+	}
+
+	close(fds[0]);
+	client = wl_client_create(display, fds[1]);
+	if (!client) {
+		kill(pid, SIGTERM);
+		assert(!"Failed to create client");
+	}
+
+	return pid;
+}
+
+int
+main(void)
+{
+	struct wl_global *compositor;
+	pid_t client_pid;
+	int client_status = 0;
+
+	alarm(5);
+
+	display = wl_display_create();
+	assert(display);
+
+	assert(!wl_display_add_socket(display, "static-symbol-test-display-0"));
+	compositor = wl_global_create(display, &tiny_intf_interface,
+				      1, NULL, bind_tiny_intf);
+
+	client_pid = spawn_client();
+
+	wl_display_run(display);
+	assert(object_created);
+
+	assert(waitpid(client_pid, &client_status, 0) == client_pid);
+	assert(client_status == 0);
+
+	wl_global_destroy(compositor);
+	wl_display_destroy(display);
+
+	return 0;
+}
-- 
2.13.0



More information about the wayland-devel mailing list