Test that it is possible to not export protocol symbols. Signed-off-by: Jonas Ådahl <jad...@gmail.com> --- .gitignore | 5 ++ Makefile.am | 27 ++++++- tests/noexport-symbol-test-client.c | 77 +++++++++++++++++++ tests/noexport-symbol-test-server.c | 146 ++++++++++++++++++++++++++++++++++++ 4 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 tests/noexport-symbol-test-client.c create mode 100644 tests/noexport-symbol-test-server.c
diff --git a/.gitignore b/.gitignore index 553ffd0..e61d193 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,8 @@ static-tiny-server-protocol-core.h static-tiny-client-protocol-core.h static-symbol-test-server static-symbol-test-client +noexport-tiny-protocol.c +noexport-tiny-server-protocol-core.h +noexport-tiny-client-protocol-core.h +noexport-symbol-test-server +noexport-symbol-test-client diff --git a/Makefile.am b/Makefile.am index bbd5107..40f73d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -117,6 +117,8 @@ BUILT_SOURCES = \ $(nodist_headers_test_SOURCES) \ $(nodist_static_symbol_test_server_SOURCES) \ $(nodist_static_symbol_test_client_SOURCES) \ + $(nodist_noexport_symbol_test_server_SOURCES) \ + $(nodist_noexport_symbol_test_client_SOURCES) \ static-tiny-protocol.inc CLEANFILES = $(BUILT_SOURCES) doc/doxygen/doxygen_sqlite3.db @@ -168,10 +170,12 @@ built_test_programs = \ headers-test \ compositor-introspection-test \ protocol-logger-test \ - static-symbol-test-server + static-symbol-test-server \ + noexport-symbol-test-server built_test_program_helpers = \ - static-symbol-test-client + static-symbol-test-client \ + noexport-symbol-test-client if ENABLE_CPP_TEST built_test_programs += cpp-compile-test @@ -218,6 +222,15 @@ static-tiny-server-protocol-core.h : tests/data/tiny.xml static-tiny-client-protocol-core.h : tests/data/tiny.xml $(AM_V_GEN)$(wayland_scanner) -c -Vstatic client-header $< $@ +noexport-tiny-protocol.c : tests/data/tiny.xml + $(AM_V_GEN)$(wayland_scanner) -c -Vcompiler-default code $< $@ + +noexport-tiny-server-protocol-core.h : tests/data/tiny.xml + $(AM_V_GEN)$(wayland_scanner) -c -Vcompiler-default server-header $< $@ + +noexport-tiny-client-protocol-core.h : tests/data/tiny.xml + $(AM_V_GEN)$(wayland_scanner) -c -Vcompiler-default client-header $< $@ + array_test_SOURCES = tests/array-test.c array_test_LDADD = libtest-runner.la client_test_SOURCES = tests/client-test.c @@ -270,6 +283,16 @@ 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 +noexport_symbol_test_server_SOURCES = tests/noexport-symbol-test-server.c +nodist_noexport_symbol_test_server_SOURCES = \ + noexport-tiny-protocol.c \ + noexport-tiny-server-protocol-core.h +noexport_symbol_test_server_LDADD = libtest-runner.la +noexport_symbol_test_client_SOURCES = tests/noexport-symbol-test-client.c +nodist_noexport_symbol_test_client_SOURCES = \ + noexport-tiny-protocol.c \ + noexport-tiny-client-protocol-core.h +noexport_symbol_test_client_LDADD = libtest-runner.la if ENABLE_CPP_TEST cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp diff --git a/tests/noexport-symbol-test-client.c b/tests/noexport-symbol-test-client.c new file mode 100644 index 0000000..11e02b9 --- /dev/null +++ b/tests/noexport-symbol-test-client.c @@ -0,0 +1,77 @@ +/* + * 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 "noexport-tiny-client-protocol-core.h" + +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, ®istry_listener, NULL); + + while (!wl_display_dispatch(display)); + + return 0; +} diff --git a/tests/noexport-symbol-test-server.c b/tests/noexport-symbol-test-server.c new file mode 100644 index 0000000..f0579cc --- /dev/null +++ b/tests/noexport-symbol-test-server.c @@ -0,0 +1,146 @@ +/* + * 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 "noexport-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/noexport-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, "noexport-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 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel