aboutsummaryrefslogtreecommitdiffstats
path: root/tests/display-test.c
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2017-12-06 11:22:24 -0600
committerDaniel Stone <daniels@collabora.com>2018-01-09 15:20:00 +0000
commitf74c9b98db49ce16e037c3012590c4a24a4fc32e (patch)
tree5e7afcd3ea20b6ee0d12d27405fbd245c2568d40 /tests/display-test.c
parentclient: Consume file descriptors destined for zombie proxies (diff)
downloadwayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar.gz
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar.bz2
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar.lz
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar.xz
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.tar.zst
wayland-f74c9b98db49ce16e037c3012590c4a24a4fc32e.zip
tests: Add a test for fd leaks on zombie objects
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 <daniels@collabora.com> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Diffstat (limited to 'tests/display-test.c')
-rw-r--r--tests/display-test.c102
1 files changed, 102 insertions, 0 deletions
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);
+}