[PATCH wayland] tests: Test creating a shm pool with 0 size
Jonas Ådahl
jadahl at gmail.com
Mon Feb 22 05:52:51 UTC 2016
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 <jadahl at gmail.com>
---
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 0000000..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 <assert.h>
+#include <linux/memfd.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#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, &wl_shm_interface, 1);
+ assert(shm);
+
+ fd = syscall(__NR_memfd_create, "wayland-tests", MFD_CLOEXEC);
+ 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, ®istry_listener, &tested);
+
+ 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);
+}
--
2.4.3
More information about the wayland-devel
mailing list