Re: [PATCH wayland] tests: Test creating a shm pool with 0 size
On Tue, 23 Feb 2016 08:25:23 +0800 Jonas Ådahlwrote: > On Mon, Feb 22, 2016 at 02:35:42PM -0800, Bryce Harrington wrote: > > On Mon, Feb 22, 2016 at 03:03:11PM +0100, Marek Chalupa wrote: > > > Hi > > > > > > On 02/22/16 06:52, Jonas Ådahl wrote: > > > >Add a test case that tests the servers behaviour when creating a pool > > > >of size 0. The test suite will do the memory and fd leak check for us, > > > >so the test case is only a triggerer. > > > > > > > >Signed-off-by: Jonas Ådahl > > > >--- > > > > Makefile.am | 5 ++- > > > > tests/shm-test.c | 108 > > > > +++ > > > > 2 files changed, 112 insertions(+), 1 deletion(-) > > > > create mode 100644 tests/shm-test.c > > > >+#include > > > >+#include > > > >+#include > > > >+#include > > > >+#include > > > >+#include > > > >+ > > > >+#include "wayland-client.h" > > > >+#include "test-runner.h" > > > >+#include "test-compositor.h" > > > >+ > > > >+static void > > > >+registry_handle_global(void *data, struct wl_registry *registry, > > > >+ uint32_t id, const char *interface, uint32_t > > > >version) > > > >+{ > > > >+bool *tested = data; > > > >+struct wl_shm *shm; > > > >+int fd, ret; > > > >+struct wl_shm_pool *pool; > > > >+ > > > >+if (strcmp (interface, "wl_shm")) > > > >+return; > > > >+ > > > >+shm = wl_registry_bind(registry, id, _shm_interface, 1); > > > >+assert(shm); > > > >+ > > > >+fd = syscall(__NR_memfd_create, "wayland-tests", MFD_CLOEXEC); > > > > > > memfd_create is rather new syscall, I think that this test won't > > > compile on older systems. Shouldn't we guard it somehow? For > > > example: > > > https://github.com/systemd/kdbus/commit/392f91521592869d67d29a231211b93aa2069dc9 > > > > > > > Good point, on ubuntu 14.04 for example: > > > > CC tests/shm-test.o > > tests/shm-test.c:27:25: fatal error: linux/memfd.h: No such file or > > directory > > #include > > ^ > > compilation terminated. > > > > > > I'd be okay with having this SKIP on older kernels; better to have the > > test than not, and eventually distros will all catch up. > > > > But is there a different syscall or set of calls that would work on the > > older kernels? Would be nice to get fuller coverage out of this test. > > The other way is to create anonymous files etc. I was lazy as this > didn't need to copy that functio here (os_create_anonymous_file()) but > if we want to support testing on older systems, I guess I'll just drop > the memfd thing and go via tmpfs instead. I suspect BSD won't have memfd > as well so it'd be more portable as well. Yes, please, os_create_anonymous_file(). Memfd is a whole another story. Thanks, pq pgpxN1plDCjVB.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] tests: Test creating a shm pool with 0 size
On Mon, Feb 22, 2016 at 03:03:11PM +0100, Marek Chalupa wrote: > Hi > > On 02/22/16 06:52, Jonas Ådahl wrote: > >Add a test case that tests the servers behaviour when creating a pool > >of size 0. The test suite will do the memory and fd leak check for us, > >so the test case is only a triggerer. > > > >Signed-off-by: Jonas Ådahl> >--- > > Makefile.am | 5 ++- > > tests/shm-test.c | 108 > > +++ > > 2 files changed, 112 insertions(+), 1 deletion(-) > > create mode 100644 tests/shm-test.c > > > >diff --git a/Makefile.am b/Makefile.am > >index e850abc..5a82dd4 100644 > >--- a/Makefile.am > >+++ b/Makefile.am > >@@ -157,7 +157,8 @@ TESTS = \ > > signal-test \ > > resources-test \ > > message-test\ > >-headers-test > >+headers-test\ > >+shm-test > > > > if ENABLE_CPP_TEST > > TESTS += cpp-compile-test > >@@ -218,6 +219,8 @@ headers_test_SOURCES = tests/headers-test.c \ > >tests/headers-protocol-test.c \ > >tests/headers-protocol-core-test.c > > headers_test_LDADD = libtest-runner.la > >+shm_test_SOURCES = tests/shm-test.c > >+shm_test_LDADD = libtest-runner.la > > nodist_headers_test_SOURCES = \ > > protocol/wayland-server-protocol-core.h \ > > protocol/wayland-client-protocol-core.h > >diff --git a/tests/shm-test.c b/tests/shm-test.c > >new file mode 100644 > >index 000..1190808 > >--- /dev/null > >+++ b/tests/shm-test.c > >@@ -0,0 +1,108 @@ > >+/* > >+ * Copyright © 2016 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 > >+#include > >+#include > >+#include > >+#include > >+#include > >+ > >+#include "wayland-client.h" > >+#include "test-runner.h" > >+#include "test-compositor.h" > >+ > >+static void > >+registry_handle_global(void *data, struct wl_registry *registry, > >+ uint32_t id, const char *interface, uint32_t version) > >+{ > >+bool *tested = data; > >+struct wl_shm *shm; > >+int fd, ret; > >+struct wl_shm_pool *pool; > >+ > >+if (strcmp (interface, "wl_shm")) > >+return; > >+ > >+shm = wl_registry_bind(registry, id, _shm_interface, 1); > >+assert(shm); > >+ > >+fd = syscall(__NR_memfd_create, "wayland-tests", MFD_CLOEXEC); > > memfd_create is rather new syscall, I think that this test won't > compile on older systems. Shouldn't we guard it somehow? For > example: > https://github.com/systemd/kdbus/commit/392f91521592869d67d29a231211b93aa2069dc9 Good point, on ubuntu 14.04 for example: CC tests/shm-test.o tests/shm-test.c:27:25: fatal error: linux/memfd.h: No such file or directory #include ^ compilation terminated. I'd be okay with having this SKIP on older kernels; better to have the test than not, and eventually distros will all catch up. But is there a different syscall or set of calls that would work on the older kernels? Would be nice to get fuller coverage out of this test. Bryce > Best, > Marek > > >+assert(fd >= 0); > >+ > >+ret = ftruncate(fd, 1); > >+assert(ret >= 0); > >+ > >+pool = wl_shm_create_pool (shm, fd, 0); > >+wl_shm_pool_destroy(pool); > >+wl_shm_destroy(shm); > >+close(fd); > >+ > >+*tested = true; > >+} > >+ > >+static const struct wl_registry_listener registry_listener = { > >+registry_handle_global, > >+NULL > >+}; > >+ > >+static void > >+client_test_shm_zero_size(void) > >+{ > >+struct wl_display *display; > >+struct wl_registry *registry; > >+bool tested = false; > >+ > >+display = wl_display_connect(NULL); >
Re: [PATCH wayland] tests: Test creating a shm pool with 0 size
Hi On 02/22/16 06:52, Jonas Ådahl wrote: Add a test case that tests the servers behaviour when creating a pool of size 0. The test suite will do the memory and fd leak check for us, so the test case is only a triggerer. Signed-off-by: Jonas Ådahl--- Makefile.am | 5 ++- tests/shm-test.c | 108 +++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/shm-test.c diff --git a/Makefile.am b/Makefile.am index e850abc..5a82dd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -157,7 +157,8 @@ TESTS = \ signal-test \ resources-test \ message-test\ - headers-test + headers-test\ + shm-test if ENABLE_CPP_TEST TESTS += cpp-compile-test @@ -218,6 +219,8 @@ headers_test_SOURCES = tests/headers-test.c \ tests/headers-protocol-test.c \ tests/headers-protocol-core-test.c headers_test_LDADD = libtest-runner.la +shm_test_SOURCES = tests/shm-test.c +shm_test_LDADD = libtest-runner.la nodist_headers_test_SOURCES = \ protocol/wayland-server-protocol-core.h \ protocol/wayland-client-protocol-core.h diff --git a/tests/shm-test.c b/tests/shm-test.c new file mode 100644 index 000..1190808 --- /dev/null +++ b/tests/shm-test.c @@ -0,0 +1,108 @@ +/* + * Copyright © 2016 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 +#include +#include +#include +#include +#include + +#include "wayland-client.h" +#include "test-runner.h" +#include "test-compositor.h" + +static void +registry_handle_global(void *data, struct wl_registry *registry, + uint32_t id, const char *interface, uint32_t version) +{ + bool *tested = data; + struct wl_shm *shm; + int fd, ret; + struct wl_shm_pool *pool; + + if (strcmp (interface, "wl_shm")) + return; + + shm = wl_registry_bind(registry, id, _shm_interface, 1); + assert(shm); + + fd = syscall(__NR_memfd_create, "wayland-tests", MFD_CLOEXEC); memfd_create is rather new syscall, I think that this test won't compile on older systems. Shouldn't we guard it somehow? For example: https://github.com/systemd/kdbus/commit/392f91521592869d67d29a231211b93aa2069dc9 Best, Marek + assert(fd >= 0); + + ret = ftruncate(fd, 1); + assert(ret >= 0); + + pool = wl_shm_create_pool (shm, fd, 0); + wl_shm_pool_destroy(pool); + wl_shm_destroy(shm); + close(fd); + + *tested = true; +} + +static const struct wl_registry_listener registry_listener = { + registry_handle_global, + NULL +}; + +static void +client_test_shm_zero_size(void) +{ + struct wl_display *display; + struct wl_registry *registry; + bool tested = false; + + display = wl_display_connect(NULL); + assert(display); + + registry = wl_display_get_registry(display); + assert(registry != NULL); + + wl_registry_add_listener(registry, _listener, ); + + assert(wl_display_roundtrip(display) != -1); + assert(tested); + + wl_registry_destroy(registry); + + /* Make sure the server processes the shm requests before destroying the +* client. */ + wl_display_roundtrip(display); + + wl_display_disconnect(display); +} + +TEST(shm_zero_size) +{ + struct display *d = display_create(); + + wl_display_init_shm(d->wl_display); + + client_create_noarg(d, client_test_shm_zero_size); + + display_run(d); + display_destroy(d); +} ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org