[cairo] [PATCH 2/3] pthread-same-source: Add a reference image generation mode

Uli Schlachter psychon at znc.in
Fri Apr 11 01:48:22 PDT 2014


In this mode, only a single thread is active and calling into cairo at any time.
Thus, there can be no races between threads. Since this test is supposed to find
races between threads, the resulting image can be used as a reference image.

Signed-off-by: Uli Schlachter <psychon at znc.in>
---
 test/pthread-same-source.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/test/pthread-same-source.c b/test/pthread-same-source.c
index 5960ca0..9db7332 100644
--- a/test/pthread-same-source.c
+++ b/test/pthread-same-source.c
@@ -28,6 +28,7 @@
 #include <pthread.h>
 
 #define N_THREADS 8
+#define GENERATE_REFERENCE 0
 
 #define WIDTH 64
 #define HEIGHT 8
@@ -136,6 +137,9 @@ draw (cairo_t *cr, int width, int height)
     cairo_status_t status;
     int i;
 
+    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+    cairo_paint (cr);
+
     source = create_source (cairo_get_target (cr));
     status = cairo_surface_status (source);
     if (status) {
@@ -157,18 +161,24 @@ draw (cairo_t *cr, int width, int height)
             test_status = CAIRO_TEST_FAILURE;
 	    break;
         }
+#if GENERATE_REFERENCE
+	{
+	    cairo_test_status_t status = join_thread (cr, threads[i]);
+	    if (status != CAIRO_TEST_SUCCESS)
+		test_status = status;
+	}
+#endif
     }
 
     cairo_surface_destroy (source);
 
-    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-    cairo_paint (cr);
-
+#if !GENERATE_REFERENCE
     for (i = 0; i < N_THREADS; i++) {
 	cairo_test_status_t status = join_thread (cr, threads[i]);
 	if (status != CAIRO_TEST_SUCCESS)
 	    test_status = status;
     }
+#endif
 
     return test_status;
 }
-- 
1.9.1



More information about the cairo mailing list