Until recently, if a client destroying a resource raced with the server generating an event on that resource that delivered a file descriptor, we would leak the fd.
This tests for a leaked fd from that race condition. Reviewed-by: Daniel Stone <dani...@collabora.com> Signed-off-by: Derek Foreman <der...@osg.samsung.com> --- Makefile.am | 7 +++- protocol/tests.xml | 43 ++++++++++++++++++++++ tests/display-test.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 protocol/tests.xml diff --git a/Makefile.am b/Makefile.am index 0eedb10..bceca2a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,7 +114,8 @@ 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_display_test_SOURCES) CLEANFILES = $(BUILT_SOURCES) doc/doxygen/doxygen_sqlite3.db DISTCLEANFILES = src/wayland-version.h @@ -206,6 +207,10 @@ client_test_SOURCES = tests/client-test.c client_test_LDADD = libtest-runner.la display_test_SOURCES = tests/display-test.c display_test_LDADD = libtest-runner.la +nodist_display_test_SOURCES = \ + protocol/tests-server-protocol.h \ + protocol/tests-client-protocol.h \ + protocol/tests-protocol.c connection_test_SOURCES = tests/connection-test.c connection_test_LDADD = libtest-runner.la event_loop_test_SOURCES = tests/event-loop-test.c diff --git a/protocol/tests.xml b/protocol/tests.xml new file mode 100644 index 0000000..77f6e24 --- /dev/null +++ b/protocol/tests.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="build_time_wayland_tests"> + + <copyright> + Copyright © 2017 Samsung Electronics Co., Ltd + + 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="fd_passer" version="1"> + <description summary="Sends an event with an fd"> + A trivial interface for fd passing tests. + </description> + + <request name="destroy" type="destructor"/> + + <event name="pre_fd"/> + + <event name="fd"> + <description summary="passes a file descriptor"/> + <arg name="fd" type="fd" summary="file descriptor"/> + </event> + </interface> +</protocol> diff --git a/tests/display-test.c b/tests/display-test.c index e6f0369..0623158 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -47,6 +47,9 @@ #include "test-runner.h" #include "test-compositor.h" +#include "tests-server-protocol.h" +#include "tests-client-protocol.h" + struct display_destroy_listener { struct wl_listener listener; int done; @@ -1066,3 +1069,102 @@ TEST(bind_fails_on_filtered_global) display_destroy(d); } + +static void +pre_fd(void *data, struct fd_passer *fdp) +{ + fd_passer_destroy(fdp); +} + +static void +fd(void *data, struct fd_passer *fdp, int32_t fd) +{ + /* We destroyed the resource before this event */ + assert(false); +} + +struct fd_passer_listener fd_passer_listener = { + pre_fd, + fd, +}; + +static void +zombie_fd_handle_globals(void *data, struct wl_registry *registry, + uint32_t id, const char *intf, uint32_t ver) +{ + struct fd_passer *fdp; + + if (!strcmp(intf, "fd_passer")) { + fdp = wl_registry_bind(registry, id, &fd_passer_interface, 1); + fd_passer_add_listener(fdp, &fd_passer_listener, NULL); + } +} + +static const struct wl_registry_listener zombie_fd_registry_listener = { + zombie_fd_handle_globals, + NULL +}; + +static void +zombie_client(void *data) +{ + struct client *c = client_connect(); + struct wl_registry *registry; + + registry = wl_display_get_registry(c->wl_display); + wl_registry_add_listener(registry, &zombie_fd_registry_listener, NULL); + + /* Gets the registry */ + wl_display_roundtrip(c->wl_display); + + /* push out the fd_passer bind */ + wl_display_roundtrip(c->wl_display); + + /* push out our fd_passer.destroy */ + wl_display_roundtrip(c->wl_display); + + wl_registry_destroy(registry); + + client_disconnect_nocheck(c); +} + +static void +fd_passer_clobber(struct wl_client *client, struct wl_resource *res) +{ + wl_resource_destroy(res); +} + +static const struct fd_passer_interface fdp_interface = { + fd_passer_clobber, +}; + +static void +bind_fd_passer(struct wl_client *client, void *data, + uint32_t vers, uint32_t id) +{ + struct wl_resource *res; + + res = wl_resource_create(client, &fd_passer_interface, vers, id); + wl_resource_set_implementation(res, &fdp_interface, NULL, NULL); + assert(res); + fd_passer_send_pre_fd(res); + fd_passer_send_fd(res, fileno(stdin)); +} + +TEST(zombie_fd) +{ + struct display *d; + struct wl_global *g; + + d = display_create(); + + g = wl_global_create(d->wl_display, &fd_passer_interface, + 1, d, bind_fd_passer); + + client_create_noarg(d, zombie_client); + display_run(d); + + wl_global_destroy(g); + + display_destroy(d); +} -- 2.15.0 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel