[PATCH wayland 1/2] tests: add test for callback serials

Marek Chalupa mchqwerty at gmail.com
Mon Oct 27 01:14:40 PDT 2014


The callback returns always with the same serial,
which is not right (it's serial, not constant...).
This test highlights the bug.

Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
 tests/display-test.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/tests/display-test.c b/tests/display-test.c
index a1e45b1..eb4ba1c 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -593,3 +593,58 @@ TEST(threading_read_after_error_tst)
 
 	display_destroy(d);
 }
+
+static void
+sync_callback(void *data, struct wl_callback *wl_callback, uint32_t serial)
+{
+	int *got = data;
+	static uint32_t last_serial = 0;
+
+	/* if this is the first callback, just copy the value of serial */
+	if (*got == 0)
+		last_serial = serial;
+	else
+		++last_serial;
+
+	/* since we only call display_sync, nothing else can increase the
+	 * serial, so the serails must be sequential */
+	assert(serial == last_serial
+	       && "Serial is not sequential");
+
+	++(*got);
+}
+
+static const struct wl_callback_listener sync_listener = {
+	sync_callback
+};
+
+#define CB_NUM 1000
+static void
+callback_serial_tst_main(void)
+{
+	int i, got = 0;
+	struct wl_callback *cb;
+	struct client *client = client_connect();
+
+	for (i = 0; i < CB_NUM; ++i) {
+		cb = wl_display_sync(client->wl_display);
+		wl_callback_add_listener(cb, &sync_listener, &got);
+	}
+
+	wl_display_flush(client->wl_display);
+	wl_display_roundtrip(client->wl_display);
+
+	assert(got == CB_NUM && "Lost some callback");
+
+	client_disconnect(client);
+}
+
+TEST(callback_serial_tst)
+{
+	struct display *d = display_create();
+
+	client_create(d, callback_serial_tst_main);
+	display_run(d);
+
+	display_destroy(d);
+}
-- 
1.9.3



More information about the wayland-devel mailing list