[cairo-commit] 2 commits - boilerplate/cairo-boilerplate.c boilerplate/cairo-boilerplate.h perf/cairo-perf.c test/cairo-test.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Apr 18 16:46:18 PDT 2007


 boilerplate/cairo-boilerplate.c |   81 ++++++++++++++++++++++++++++++++++++----
 boilerplate/cairo-boilerplate.h |    8 ++-
 perf/cairo-perf.c               |   20 ++++-----
 test/cairo-test.c               |   64 +++++--------------------------
 4 files changed, 102 insertions(+), 71 deletions(-)

New commits:
diff-tree 157074c794903f1dbe68c1ba5b129b4176dc7975 (from 47c02a6bd67e8b7e50977cc87d5e35358d5c4c2e)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 18 19:46:30 2007 -0400

    [boilerplate] Add cairo_boilerplate_get/free_targets
    This means, test and perf suites now share the same target handling
    code, including parsing CAIRO_TEST_TARGET.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 187360c..8c73916 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1366,7 +1366,7 @@ cleanup_svg (void *closure)
 }
 #endif /* CAIRO_HAS_SVG_SURFACE && CAIRO_CAN_TEST_SVG_SURFACE */
 
-cairo_boilerplate_target_t targets[] =
+static cairo_boilerplate_target_t targets[] =
 {
     /* I'm uncompromising about leaving the image backend as 0
      * for tolerance. There shouldn't ever be anything that is out of
@@ -1517,10 +1517,77 @@ cairo_boilerplate_target_t targets[] =
     { "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_directfb_surface, cairo_surface_write_to_png,cleanup_directfb},
 #endif
-
-    { NULL }
 };
 
+cairo_boilerplate_target_t **
+cairo_boilerplate_get_targets (int *pnum_targets, cairo_bool_t *plimited_targets)
+{
+    size_t i, num_targets;
+    cairo_bool_t limited_targets = FALSE;
+    const char *tname;
+    cairo_boilerplate_target_t **targets_to_test;
+
+    if ((tname = getenv ("CAIRO_TEST_TARGET")) != NULL && *tname) {
+
+	limited_targets = TRUE;
+
+	num_targets = 0;
+	targets_to_test = NULL;
+
+	while (*tname) {
+	    int found = 0;
+	    const char *end = strpbrk (tname, " \t\r\n;:,");
+	    if (!end)
+	        end = tname + strlen (tname);
+
+	    if (end == tname) {
+		tname = end + 1;
+		continue;
+	    }
+
+	    for (i = 0; i < sizeof (targets) / sizeof (targets[0]); i++) {
+		if (0 == strncmp (targets[i].name, tname, end - tname) &&
+		    !isalnum (targets[i].name[end - tname])) {
+		    /* realloc isn't exactly the best thing here, but meh. */
+		    targets_to_test = realloc (targets_to_test, sizeof(cairo_boilerplate_target_t *) * (num_targets+1));
+		    targets_to_test[num_targets++] = &targets[i];
+		    found = 1;
+		}
+	    }
+
+	    if (!found) {
+		fprintf (stderr, "Cannot find target '%.*s'\n", (int)(end - tname), tname);
+		exit(-1);
+	    }
+
+	    if (*end)
+	      end++;
+	    tname = end;
+	}
+    } else {
+	num_targets = sizeof (targets) / sizeof (targets[0]);
+	targets_to_test = malloc (sizeof(cairo_boilerplate_target_t*) * num_targets);
+	for (i = 0; i < num_targets; i++) {
+	    targets_to_test[i] = &targets[i];
+	}
+    }
+
+    if (pnum_targets)
+	*pnum_targets = num_targets;
+
+    if (plimited_targets)
+	*plimited_targets = limited_targets;
+
+    return targets_to_test;
+}
+
+void
+cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets)
+{
+    free (targets);
+}
+
+
 void
 xasprintf (char **strp, const char *fmt, ...)
 {
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 6c079c9..c9e6ef0 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -123,7 +123,11 @@ typedef struct _cairo_boilerplate_target
     void			       *closure;
 } cairo_boilerplate_target_t;
 
-extern cairo_boilerplate_target_t targets[];
+cairo_boilerplate_target_t **
+cairo_boilerplate_get_targets (int *num_targets, cairo_bool_t *limited_targets);
+
+void
+cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets);
 
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
 #define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
index 6c66487..993345c 100644
--- a/perf/cairo-perf.c
+++ b/perf/cairo-perf.c
@@ -302,11 +302,10 @@ check_cpu_affinity(void)
 int
 main (int argc, char *argv[])
 {
-    int i, j;
+    int i, j, num_targets;
     cairo_perf_case_t *perf_case;
     cairo_perf_t perf;
-    const char *cairo_test_target = getenv ("CAIRO_TEST_TARGET");
-    cairo_boilerplate_target_t *target;
+    cairo_boilerplate_target_t **targets;
     cairo_surface_t *surface;
 
     parse_options (&perf, argc, argv);
@@ -324,17 +323,16 @@ main (int argc, char *argv[])
             stderr);
     }
 
-    if (!*cairo_test_target)
-	cairo_test_target = NULL;
+    targets = cairo_boilerplate_get_targets (&num_targets, NULL);
 
-    for (i = 0; targets[i].name; i++) {
-	perf.target = target = &targets[i];
-	perf.test_number = 0;
+    for (i = 0; i < num_targets; i++) {
+        cairo_boilerplate_target_t *target = targets[i];
 
 	if (! target_is_measurable (target))
 	    continue;
-	if (cairo_test_target && ! strstr (cairo_test_target, target->name))
-	    continue;
+
+	perf.target = target;
+	perf.test_number = 0;
 
 	for (j = 0; perf_cases[j].run; j++) {
 
@@ -378,6 +376,8 @@ main (int argc, char *argv[])
 	}
     }
 
+    cairo_boilerplate_free_targets (targets);
+
     return 0;
 }
 
diff --git a/test/cairo-test.c b/test/cairo-test.c
index ef34a04..1582d93 100755
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -383,7 +383,6 @@ cairo_test_expecting (cairo_test_t *test
      * by longjmp */
     volatile size_t i, j, num_targets;
     volatile cairo_bool_t limited_targets = FALSE, print_fail_on_stdout = TRUE;
-    const char *tname;
 #ifdef HAVE_SIGNAL_H
     void (*old_segfault_handler)(int);
 #endif
@@ -409,51 +408,12 @@ cairo_test_expecting (cairo_test_t *test
     if (expectation == CAIRO_TEST_FAILURE)
     printf ("Expecting failure\n");
 
-    if ((tname = getenv ("CAIRO_TEST_TARGET")) != NULL && *tname) {
-
-	limited_targets = TRUE;
-
-	num_targets = 0;
-	targets_to_test = NULL;
-
-	while (*tname) {
-	    int found = 0;
-	    const char *end = strpbrk (tname, " \t\r\n;:,");
-	    if (!end)
-	        end = tname + strlen (tname);
-
-	    if (end == tname) {
-		tname = end + 1;
-		continue;
-	    }
-
-	    for (i = 0; targets[i].name != NULL; i++) {
-		if (0 == strncmp (targets[i].name, tname, end - tname) &&
-		    !isalnum (targets[i].name[end - tname])) {
-		    /* realloc isn't exactly the best thing here, but meh. */
-		    targets_to_test = realloc (targets_to_test, sizeof(cairo_boilerplate_target_t *) * (num_targets+1));
-		    targets_to_test[num_targets++] = &targets[i];
-		    found = 1;
-		}
-	    }
-
-	    if (!found) {
-		fprintf (stderr, "Cannot test target '%.*s'\n", (int)(end - tname), tname);
-		exit(-1);
-	    }
-
-	    if (*end)
-	      end++;
-	    tname = end;
-	}
-    } else {
-	num_targets = 0;
-	for (i = 0; targets[i].name != NULL; i++)
-	    num_targets++;
-	targets_to_test = malloc (sizeof(cairo_boilerplate_target_t*) * num_targets);
-	for (i = 0; i < num_targets; i++) {
-	    targets_to_test[i] = &targets[i];
-	}
+    {
+	int tmp_num_targets;
+	cairo_bool_t tmp_limited_targets;
+	targets_to_test = cairo_boilerplate_get_targets (&tmp_num_targets, &tmp_limited_targets);
+	num_targets = tmp_num_targets;
+	limited_targets = tmp_limited_targets;
     }
 
     /* The intended logic here is that we return overall SUCCESS
@@ -583,7 +543,7 @@ cairo_test_expecting (cairo_test_t *test
 
     cairo_test_fini ();
 
-    free (targets_to_test);
+    cairo_boilerplate_free_targets (targets_to_test);
 
     return ret;
 }
diff-tree 47c02a6bd67e8b7e50977cc87d5e35358d5c4c2e (from b9026d0b137520247b4a93287bd518fc79774e93)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Apr 18 19:15:16 2007 -0400

    [boilerplate] s/_cairo_test_content_name/cairo_boilerplate_content_name/g

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 208f53a..187360c 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -80,7 +80,7 @@ static const char *vector_ignored_tests[
 };
 
 const char *
-_cairo_test_content_name (cairo_content_t content)
+cairo_boilerplate_content_name (cairo_content_t content)
 {
     /* For the purpose of the content name, we don't distinguish the
      * flattened content value.
@@ -1068,7 +1068,7 @@ create_ps_surface (const char			 *name,
     *closure = ptc = xmalloc (sizeof (ps_target_closure_t));
 
     xasprintf (&ptc->filename, "%s-ps-%s-out.ps",
-	       name, _cairo_test_content_name (content));
+	       name, cairo_boilerplate_content_name (content));
 
     ptc->width = width;
     ptc->height = height;
@@ -1188,7 +1188,7 @@ create_pdf_surface (const char			 *name,
     ptc->height = height;
 
     xasprintf (&ptc->filename, "%s-pdf-%s-out.pdf",
-	       name, _cairo_test_content_name (content));
+	       name, cairo_boilerplate_content_name (content));
 
     surface = cairo_pdf_surface_create (ptc->filename, width, height);
     if (cairo_surface_status (surface)) {
@@ -1294,7 +1294,7 @@ create_svg_surface (const char			 *name,
     ptc->height = height;
 
     xasprintf (&ptc->filename, "%s-svg-%s-out.svg",
-	       name, _cairo_test_content_name (content));
+	       name, cairo_boilerplate_content_name (content));
 
     surface = cairo_svg_surface_create (ptc->filename, width, height);
     if (cairo_surface_status (surface)) {
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 66d40e5..6c079c9 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -78,7 +78,7 @@
 #define CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED ((unsigned int) -1)
 
 const char *
-_cairo_test_content_name (cairo_content_t content);
+cairo_boilerplate_content_name (cairo_content_t content);
 
 #ifndef FALSE
 #define FALSE 0
diff --git a/test/cairo-test.c b/test/cairo-test.c
index c74e66e..ef34a04 100755
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -203,7 +203,7 @@ cairo_test_for_target (cairo_test_t			 *
     const char *format;
 
     /* Get the strings ready that we'll need. */
-    format = _cairo_test_content_name (target->content);
+    format = cairo_boilerplate_content_name (target->content);
     if (dev_offset)
 	xasprintf (&offset_str, "-%d", dev_offset);
     else
@@ -479,7 +479,7 @@ cairo_test_expecting (cairo_test_t *test
 
 	    cairo_test_log ("Testing %s with %s target (dev offset %d)\n", test->name, target->name, dev_offset);
 	    printf ("%s-%s-%s [%d]:\t", test->name, target->name,
-		    _cairo_test_content_name (target->content),
+		    cairo_boilerplate_content_name (target->content),
 		    dev_offset);
 
 #ifdef HAVE_SIGNAL_H
@@ -496,7 +496,7 @@ cairo_test_expecting (cairo_test_t *test
 
 	    cairo_test_log ("TEST: %s TARGET: %s FORMAT: %s OFFSET: %d RESULT: ",
 			    test->name, target->name,
-			    _cairo_test_content_name (target->content),
+			    cairo_boilerplate_content_name (target->content),
 			    dev_offset);
 
 	    switch (status) {
@@ -521,7 +521,7 @@ cairo_test_expecting (cairo_test_t *test
 		cairo_test_log ("CRASHED\n");
 		fprintf (stderr, "%s-%s-%s [%d]:\t%s!!!CRASHED!!!%s\n",
 			 test->name, target->name,
-			 _cairo_test_content_name (target->content), dev_offset,
+			 cairo_boilerplate_content_name (target->content), dev_offset,
 			 fail_face, normal_face);
 		ret = CAIRO_TEST_FAILURE;
 		break;
@@ -540,7 +540,7 @@ cairo_test_expecting (cairo_test_t *test
 		    }
 		    fprintf (stderr, "%s-%s-%s [%d]:\t%sFAIL%s\n",
 			     test->name, target->name,
-			     _cairo_test_content_name (target->content), dev_offset,
+			     cairo_boilerplate_content_name (target->content), dev_offset,
 			     fail_face, normal_face);
 		    cairo_test_log ("FAIL\n");
 		}


More information about the cairo-commit mailing list