Re: [PATCH wayland 4/5] client-test: test posting no-mem error on client destruction

2016-05-16 Thread Pekka Paalanen
On Mon, 16 May 2016 13:52:24 +0300
Pekka Paalanen  wrote:

> On Fri, 13 May 2016 15:01:21 +0200
> Marek Chalupa  wrote:
> 
> > while client is being destroyed, it destroys all its resources.
> > Destroy handlers are called for the resources and if some
> > destroy handler post no memory error, we get crash, because
> > the display resource is NULL (it is destroyed as a first resource)
> > 
> > Signed-off-by: Marek Chalupa 
> > ---
> >  tests/client-test.c | 37 +
> >  1 file changed, 37 insertions(+)
> > 
> > diff --git a/tests/client-test.c b/tests/client-test.c
> > index 2e332f8..cb08e39 100644
> > --- a/tests/client-test.c
> > +++ b/tests/client-test.c
> > @@ -89,3 +89,40 @@ TEST(client_destroy_listener)
> > wl_display_destroy(display);
> >  }
> >  
> > +static struct wl_listener seat_destroy_listener;

Hi,

one more thing:

Why is this a global? Should be just fine as a local variable in the
function scope.

I think you should move it.


Thanks,
pq


> > +
> > +static void
> > +seat_destroy_post_no_memory(struct wl_listener *l, void *data)
> > +{
> > +   struct wl_resource *resource = data;  
> 
> Add an empty line.
> 
> > +   wl_client_post_no_memory(wl_resource_get_client(resource));  
> 
> This tests wl_client_post_no_memory(), could it not test
> wl_resource_post_no_memory() at the same time?
> 
> > +}
> > +
> > +TEST(client_post_nomem_on_destruction)
> > +{
> > +   struct wl_display *display;
> > +   struct wl_client *client;
> > +   struct wl_resource *resource;
> > +   int s[2];
> > +
> > +   assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
> > +   display = wl_display_create();
> > +   assert(display);
> > +   client = wl_client_create(display, s[0]);
> > +   assert(client);
> > +
> > +   resource = wl_resource_create(client, &wl_seat_interface,
> > + wl_seat_interface.version, 0);
> > +   assert(resource);
> > +
> > +   seat_destroy_listener.notify = seat_destroy_post_no_memory;
> > +   wl_resource_add_destroy_listener(resource, &seat_destroy_listener);
> > +
> > +   wl_client_destroy(client);
> > +
> > +   close(s[0]);
> > +   close(s[1]);
> > +
> > +   wl_display_destroy(display);
> > +}
> > +  
> 
> Anyway
> Reviewed-by: Pekka Paalanen 
> 
> 
> Thanks,
> pq



pgpS3iAP9Warj.pgp
Description: OpenPGP digital signature
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH wayland 4/5] client-test: test posting no-mem error on client destruction

2016-05-16 Thread Pekka Paalanen
On Fri, 13 May 2016 15:01:21 +0200
Marek Chalupa  wrote:

> while client is being destroyed, it destroys all its resources.
> Destroy handlers are called for the resources and if some
> destroy handler post no memory error, we get crash, because
> the display resource is NULL (it is destroyed as a first resource)
> 
> Signed-off-by: Marek Chalupa 
> ---
>  tests/client-test.c | 37 +
>  1 file changed, 37 insertions(+)
> 
> diff --git a/tests/client-test.c b/tests/client-test.c
> index 2e332f8..cb08e39 100644
> --- a/tests/client-test.c
> +++ b/tests/client-test.c
> @@ -89,3 +89,40 @@ TEST(client_destroy_listener)
>   wl_display_destroy(display);
>  }
>  
> +static struct wl_listener seat_destroy_listener;
> +
> +static void
> +seat_destroy_post_no_memory(struct wl_listener *l, void *data)
> +{
> + struct wl_resource *resource = data;

Add an empty line.

> + wl_client_post_no_memory(wl_resource_get_client(resource));

This tests wl_client_post_no_memory(), could it not test
wl_resource_post_no_memory() at the same time?

> +}
> +
> +TEST(client_post_nomem_on_destruction)
> +{
> + struct wl_display *display;
> + struct wl_client *client;
> + struct wl_resource *resource;
> + int s[2];
> +
> + assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
> + display = wl_display_create();
> + assert(display);
> + client = wl_client_create(display, s[0]);
> + assert(client);
> +
> + resource = wl_resource_create(client, &wl_seat_interface,
> +   wl_seat_interface.version, 0);
> + assert(resource);
> +
> + seat_destroy_listener.notify = seat_destroy_post_no_memory;
> + wl_resource_add_destroy_listener(resource, &seat_destroy_listener);
> +
> + wl_client_destroy(client);
> +
> + close(s[0]);
> + close(s[1]);
> +
> + wl_display_destroy(display);
> +}
> +

Anyway
Reviewed-by: Pekka Paalanen 


Thanks,
pq


pgpcpcZuTKozu.pgp
Description: OpenPGP digital signature
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH wayland 4/5] client-test: test posting no-mem error on client destruction

2016-05-13 Thread Marek Chalupa
while client is being destroyed, it destroys all its resources.
Destroy handlers are called for the resources and if some
destroy handler post no memory error, we get crash, because
the display resource is NULL (it is destroyed as a first resource)

Signed-off-by: Marek Chalupa 
---
 tests/client-test.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/tests/client-test.c b/tests/client-test.c
index 2e332f8..cb08e39 100644
--- a/tests/client-test.c
+++ b/tests/client-test.c
@@ -89,3 +89,40 @@ TEST(client_destroy_listener)
wl_display_destroy(display);
 }
 
+static struct wl_listener seat_destroy_listener;
+
+static void
+seat_destroy_post_no_memory(struct wl_listener *l, void *data)
+{
+   struct wl_resource *resource = data;
+   wl_client_post_no_memory(wl_resource_get_client(resource));
+}
+
+TEST(client_post_nomem_on_destruction)
+{
+   struct wl_display *display;
+   struct wl_client *client;
+   struct wl_resource *resource;
+   int s[2];
+
+   assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
+   display = wl_display_create();
+   assert(display);
+   client = wl_client_create(display, s[0]);
+   assert(client);
+
+   resource = wl_resource_create(client, &wl_seat_interface,
+ wl_seat_interface.version, 0);
+   assert(resource);
+
+   seat_destroy_listener.notify = seat_destroy_post_no_memory;
+   wl_resource_add_destroy_listener(resource, &seat_destroy_listener);
+
+   wl_client_destroy(client);
+
+   close(s[0]);
+   close(s[1]);
+
+   wl_display_destroy(display);
+}
+
-- 
2.5.5

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel