[PATCH 1/2] tests: add new threading test

Marek Chalupa mchqwerty at gmail.com
Thu Aug 28 02:32:55 PDT 2014


This test creates three threads (and main one) and in each does
preapare_read and read_events. This is normal workflow, but
since we have no data on socket, the read_events will return
with EAGAIN. On this path we do not wake up threads and
this test blocks until timeout.

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

diff --git a/tests/display-test.c b/tests/display-test.c
index c420cbe..0a84ef3 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -483,6 +483,48 @@ TEST(threading_cancel_read_tst)
 	display_destroy(d);
 }
 
+static void
+threading_read_eagain(void)
+{
+	struct client *c = client_connect();
+	pthread_t th1, th2, th3;
+
+	register_reading(c->wl_display);
+
+	th1 = create_thread(c);
+	th2 = create_thread(c);
+	th3 = create_thread(c);
+
+	/* All the threads are sleeping, waiting until read or cancel
+	 * is called. Since we have no data on socket waiting,
+	 * the wl_connection_read should end up with error and set errno
+	 * to EAGIN => wl_display_read_events() returns 0 and set errno
+	 * to EAGAIN. Problem is that on this path we did not wake up
+	 * threads until now. Test it*/
+	assert(wl_display_read_events(c->wl_display) == 0);
+	assert(errno == EAGAIN);
+
+	/* kill test in 3 seconds. This should be enough time for the
+	 * thread to exit if it's not blocking. If everything is OK, than
+	 * the thread was woken up and the test will end before the SIGALRM */
+	alarm(3);
+	pthread_join(th1, NULL);
+	pthread_join(th2, NULL);
+	pthread_join(th3, NULL);
+
+	client_disconnect(c);
+}
+
+TEST(threading_read_eagin_tst)
+{
+	struct display *d = display_create();
+
+	client_create(d, threading_read_eagain);
+	display_run(d);
+
+	display_destroy(d);
+}
+
 static void *
 thread_prepare_and_read2(void *data)
 {
-- 
1.9.3



More information about the wayland-devel mailing list