On Wednesday, July 31, 2013 08:16:25 Jose Fonseca wrote:
> FYI, I twice now got deadlock on glx-multithread-shader-compile on my
> continuous testing of Mesa:
> 
>   ...
>   [Sat Jul 20 01:18:20 2013] ::  running ::
> glx/glx-multithread-shader-compile  <-- last piglit message Build timed out
> (after 120 minutes). Marking the build as failed.   <-- Jenkins message
> 
> I'm going to disable the test on my custom test list.  But I believe that if
> we're going to add multi-threaded tests to piglit, then we should have a
> per-test timeout (ie, after a threshold time like 5min the framework should
> kill the process and mark the test as failed).  Otherwise these race
> condition tests do more harm than good -- as they prevent all other tests
> from running.

A timeout looks perfect.
May be the attached patch helps to keep this test in mind :-)

Mathias
diff --git a/tests/glx/glx-multithread-shader-compile.c b/tests/glx/glx-multithread-shader-compile.c
index b04c1b2..d82c188 100644
--- a/tests/glx/glx-multithread-shader-compile.c
+++ b/tests/glx/glx-multithread-shader-compile.c
@@ -32,6 +32,8 @@
 #include "piglit-util-gl-common.h"
 #include "piglit-glx-util.h"
 #include "pthread.h"
+#include "time.h"
+#include "errno.h"
 
 static const char *vert_shader_text =
    "void main() \n"
@@ -47,6 +49,8 @@ static const char *frag_shader_text =
    "} \n";
 
 static pthread_mutex_t mutex;
+static pthread_cond_t cond;
+static unsigned num_threads = 0;
 
 static void *
 thread_func(void *arg)
@@ -90,6 +94,11 @@ thread_func(void *arg)
 		glXDestroyContext(dpy, ctx);
 	}
 
+	pthread_mutex_lock(&mutex);
+	--num_threads;
+	pthread_cond_signal(&cond);
+	pthread_mutex_unlock(&mutex);
+
 	return NULL;
 }
 
@@ -98,19 +107,38 @@ main(int argc, char **argv)
 {
 	int ret;
 	pthread_t thread1, thread2;
+	struct timespec timeout;
 
 	pthread_mutex_init(&mutex, NULL);
+	pthread_cond_init(&cond, NULL);
 
 	/* Now, spawn some threads that compile simple shaders.
 	 */
+	num_threads = 2;
 	pthread_create(&thread1, NULL, thread_func, NULL);
 	pthread_create(&thread2, NULL, thread_func, NULL);
 
+	/* Wait for the threads to finish within a given timeout.
+	 */
+	clock_gettime(CLOCK_REALTIME, &timeout);
+	timeout.tv_sec += 60;
+
+	pthread_mutex_lock(&mutex);
+	while (num_threads) {
+	       int err = pthread_cond_timedwait(&cond, &mutex, &timeout);
+	       if (err == ETIMEDOUT)
+		       piglit_report_result(PIGLIT_FAIL);
+	}
+	pthread_mutex_unlock(&mutex);
+
+	/* And collect them.
+	 */
 	ret = pthread_join(thread1, NULL);
 	assert(ret == 0);
 	ret = pthread_join(thread2, NULL);
 	assert(ret == 0);
 
+	pthread_cond_destroy(&cond);
 	pthread_mutex_destroy(&mutex);
 
 	piglit_report_result(PIGLIT_PASS);
_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to