[cairo-commit] 2 commits - src/cairo-path-fixed.c src/cairo-path-fixed-private.h test/cairo-test.c test/cairo-test.h test/cairo-test-runner.c

Chris Wilson ickle at kemper.freedesktop.org
Fri Jun 11 01:15:34 PDT 2010


 src/cairo-path-fixed-private.h |    3 -
 src/cairo-path-fixed.c         |   39 ++++++++---------
 test/cairo-test-runner.c       |   89 ++++++++++++++++++++++++++++++++++++++++-
 test/cairo-test.c              |   20 ++++++++-
 test/cairo-test.h              |    1 
 5 files changed, 128 insertions(+), 24 deletions(-)

New commits:
commit bd3d9ef3d1dbc5364e79e6afb47d9e124cb61ca4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 11 09:12:16 2010 +0100

    test: Distinguish tests that throw an error from a normal fail.
    
    Hitting an error in a test case is almost as bad as crashing, and the
    severity may be lost amidst "normal" failures. So introduce a new class
    of ERROR so that we can immediately spot these during a test run, and
    appropriately log them afterwards.

diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c
index d130321..aa9e101 100644
--- a/test/cairo-test-runner.c
+++ b/test/cairo-test-runner.c
@@ -78,15 +78,19 @@ typedef struct _cairo_test_runner {
     int num_skipped;
     int num_failed;
     int num_xfailed;
+    int num_error;
     int num_crashed;
 
     cairo_test_list_t *crashes_preamble;
+    cairo_test_list_t *errors_preamble;
     cairo_test_list_t *fails_preamble;
 
     cairo_test_list_t **crashes_per_target;
+    cairo_test_list_t **errors_per_target;
     cairo_test_list_t **fails_per_target;
 
     int *num_failed_per_target;
+    int *num_error_per_target;
     int *num_crashed_per_target;
 
     cairo_bool_t foreground;
@@ -384,13 +388,18 @@ _runner_init (cairo_test_runner_t *runner)
 
     runner->fails_preamble = NULL;
     runner->crashes_preamble = NULL;
+    runner->errors_preamble = NULL;
 
     runner->fails_per_target = xcalloc (sizeof (cairo_test_list_t *),
 					runner->base.num_targets);
     runner->crashes_per_target = xcalloc (sizeof (cairo_test_list_t *),
 					  runner->base.num_targets);
+    runner->errors_per_target = xcalloc (sizeof (cairo_test_list_t *),
+					  runner->base.num_targets);
     runner->num_failed_per_target = xcalloc (sizeof (int),
 					     runner->base.num_targets);
+    runner->num_error_per_target = xcalloc (sizeof (int),
+					     runner->base.num_targets);
     runner->num_crashed_per_target = xcalloc (sizeof (int),
 					      runner->base.num_targets);
 }
@@ -443,6 +452,21 @@ _runner_print_details (cairo_test_runner_t *runner)
 	}
 	_log (&runner->base, "\n");
     }
+    if (runner->errors_preamble) {
+	int count = 0;
+
+	for (list = runner->errors_preamble; list != NULL; list = list->next)
+	    count++;
+
+	_log (&runner->base, "Preamble: %d error -", count);
+
+	for (list = runner->errors_preamble; list != NULL; list = list->next) {
+	    char *name = cairo_test_get_name (list->test);
+	    _log (&runner->base, " %s", name);
+	    free (name);
+	}
+	_log (&runner->base, "\n");
+    }
     if (runner->fails_preamble) {
 	int count = 0;
 
@@ -479,6 +503,22 @@ _runner_print_details (cairo_test_runner_t *runner)
 	    }
 	    _log (&runner->base, "\n");
 	}
+	if (runner->num_error_per_target[n]) {
+	    _log (&runner->base, "%s (%s): %d error -",
+		  target->name,
+		  cairo_boilerplate_content_name (target->content),
+		  runner->num_error_per_target[n]);
+
+	    for (list = runner->errors_per_target[n];
+		 list != NULL;
+		 list = list->next)
+	    {
+		char *name = cairo_test_get_name (list->test);
+		_log (&runner->base, " %s", name);
+		free (name);
+	    }
+	    _log (&runner->base, "\n");
+	}
 
 	if (runner->num_failed_per_target[n]) {
 	    _log (&runner->base, "%s (%s): %d failed -",
@@ -519,16 +559,20 @@ _runner_fini (cairo_test_runner_t *runner)
     unsigned int n;
 
     _list_free (runner->crashes_preamble);
+    _list_free (runner->errors_preamble);
     _list_free (runner->fails_preamble);
 
     for (n = 0; n < runner->base.num_targets; n++) {
 	_list_free (runner->crashes_per_target[n]);
+	_list_free (runner->errors_per_target[n]);
 	_list_free (runner->fails_per_target[n]);
     }
     free (runner->crashes_per_target);
+    free (runner->errors_per_target);
     free (runner->fails_per_target);
 
     free (runner->num_crashed_per_target);
+    free (runner->num_error_per_target);
     free (runner->num_failed_per_target);
 
     cairo_test_fini (&runner->base);
@@ -700,7 +744,7 @@ main (int argc, char **argv)
     for (test = tests; test != NULL; test = test->next) {
 	cairo_test_context_t ctx;
 	cairo_test_status_t status;
-	cairo_bool_t failed = FALSE, xfailed = FALSE, crashed = FALSE, skipped = TRUE;
+	cairo_bool_t failed = FALSE, xfailed = FALSE, error = FALSE, crashed = FALSE, skipped = TRUE;
 	cairo_bool_t in_preamble = FALSE;
 	char *name = cairo_test_get_name (test);
 	int i;
@@ -810,6 +854,13 @@ main (int argc, char **argv)
 		failed = TRUE;
 		goto TEST_DONE;
 
+	    case CAIRO_TEST_ERROR:
+		runner.errors_preamble = _list_prepend (runner.errors_preamble,
+							 test);
+		in_preamble = TRUE;
+		failed = TRUE;
+		goto TEST_DONE;
+
 	    case CAIRO_TEST_NO_MEMORY:
 	    case CAIRO_TEST_CRASHED:
 		runner.crashes_preamble = _list_prepend (runner.crashes_preamble,
@@ -830,6 +881,7 @@ main (int argc, char **argv)
 	    const cairo_boilerplate_target_t *target;
 	    cairo_bool_t target_failed = FALSE,
 			 target_xfailed = FALSE,
+			 target_error = FALSE,
 			 target_crashed = FALSE,
 			 target_skipped = TRUE;
 	    int has_similar;
@@ -853,11 +905,14 @@ main (int argc, char **argv)
 		    case CAIRO_TEST_XFAILURE:
 			target_xfailed = TRUE;
 			break;
-		    case CAIRO_TEST_NO_MEMORY:
 		    case CAIRO_TEST_NEW:
 		    case CAIRO_TEST_FAILURE:
 			target_failed = TRUE;
 			break;
+		    case CAIRO_TEST_ERROR:
+			target_error = TRUE;
+			break;
+		    case CAIRO_TEST_NO_MEMORY:
 		    case CAIRO_TEST_CRASHED:
 			target_crashed = TRUE;
 			break;
@@ -873,6 +928,13 @@ main (int argc, char **argv)
 		runner.crashes_per_target[n] = _list_prepend (runner.crashes_per_target[n],
 							      test);
 		crashed = TRUE;
+	    } else if (target_error) {
+		target_status[n] = CAIRO_TEST_ERROR;
+		runner.num_error_per_target[n]++;
+		runner.errors_per_target[n] = _list_prepend (runner.errors_per_target[n],
+							     test);
+
+		error = TRUE;
 	    } else if (target_failed) {
 		target_status[n] = CAIRO_TEST_FAILURE;
 		runner.num_failed_per_target[n]++;
@@ -916,6 +978,28 @@ main (int argc, char **argv)
 	    }
 	    runner.num_crashed++;
 	    runner.passed = FALSE;
+	} else if (error) {
+	    if (! in_preamble) {
+		len = 0;
+		for (n = 0 ; n < runner.base.num_targets; n++) {
+		    if (target_status[n] == CAIRO_TEST_ERROR) {
+			if (strstr (targets,
+				    runner.base.targets_to_test[n]->name) == NULL)
+			{
+			    len += snprintf (targets + len,
+					     sizeof (targets) - len,
+					     "%s, ",
+					     runner.base.targets_to_test[n]->name);
+			}
+		    }
+		}
+		targets[len-2] = '\0';
+		_log (&runner.base, "%s: ERROR (%s)\n", name, targets);
+	    } else {
+		_log (&runner.base, "%s: ERROR\n", name);
+	    }
+	    runner.num_error++;
+	    runner.passed = FALSE;
 	} else if (failed) {
 	    if (! in_preamble) {
 		len = 0;
@@ -964,6 +1048,7 @@ main (int argc, char **argv)
 
     for (n = 0 ; n < runner.base.num_targets; n++) {
 	runner.crashes_per_target[n] = _list_reverse (runner.crashes_per_target[n]);
+	runner.errors_per_target[n] = _list_reverse (runner.errors_per_target[n]);
 	runner.fails_per_target[n] = _list_reverse (runner.fails_per_target[n]);
     }
 
diff --git a/test/cairo-test.c b/test/cairo-test.c
index aa8dd3a..af4487a 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -1444,7 +1444,7 @@ REPEAT:
     if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
 	cairo_test_log (ctx, "Error: Function under test left cairo status in an error state: %s\n",
 			cairo_status_to_string (cairo_status (cr)));
-	ret = CAIRO_TEST_FAILURE;
+	ret = CAIRO_TEST_ERROR;
 	goto UNWIND_CAIRO;
     }
 
@@ -1665,6 +1665,21 @@ _cairo_test_context_run_for_target (cairo_test_context_t *ctx,
 		     fail_face, normal_face);
 	    break;
 
+	case CAIRO_TEST_ERROR:
+	    if (print_fail_on_stdout && ctx->thread == 0) {
+		printf ("!!!ERROR!!!\n");
+	    } else {
+		/* eat the test name */
+		printf ("\r");
+		fflush (stdout);
+	    }
+	    cairo_test_log (ctx, "ERROR\n");
+	    fprintf (stderr, "%s.%s.%s [%d]%s:\t%s!!!ERROR!!!%s\n",
+		     ctx->test_name, target->name,
+		     cairo_boilerplate_content_name (target->content), dev_offset, similar ? " (similar)" : "",
+		     fail_face, normal_face);
+	    break;
+
 	case CAIRO_TEST_XFAILURE:
 	    if (print_fail_on_stdout && ctx->thread == 0) {
 		printf ("XFAIL\n");
@@ -1732,6 +1747,9 @@ _cairo_test_context_run_for_target (cairo_test_context_t *ctx,
 	case CAIRO_TEST_CRASHED:
 	    printf ("!!!CRASHED!!!\n");
 	    break;
+	case CAIRO_TEST_ERROR:
+	    printf ("!!!ERRORED!!!\n");
+	    break;
 	case CAIRO_TEST_XFAILURE:
 	    printf ("XFAIL\n");
 	    break;
diff --git a/test/cairo-test.h b/test/cairo-test.h
index 53db80b..e2bf1a7 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -124,6 +124,7 @@ typedef enum cairo_test_status {
     CAIRO_TEST_FAILURE,
     CAIRO_TEST_NEW,
     CAIRO_TEST_XFAILURE,
+    CAIRO_TEST_ERROR,
     CAIRO_TEST_CRASHED,
     CAIRO_TEST_UNTESTED = 77 /* match automake's skipped exit status */
 } cairo_test_status_t;
commit eeafeebd2ec8ad8a9e7053aaaa0f845b58563b3b
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 11 09:06:20 2010 +0100

    path: Exponentially grow buffer based on populated points and ops.
    
    Instead of simply doubling the buffer size every time we overflow a point
    or an op, enlarge the buffer to fit twice the number of used points and
    ops.  We expect paths to be fairly consistent in the mix of operations,
    and this allows the buffer size to tune itself to actual usage and reduce
    wastage.

diff --git a/src/cairo-path-fixed-private.h b/src/cairo-path-fixed-private.h
index 4345fd5..42e64ed 100644
--- a/src/cairo-path-fixed-private.h
+++ b/src/cairo-path-fixed-private.h
@@ -61,9 +61,10 @@ typedef char cairo_path_op_t;
 
 typedef struct _cairo_path_buf {
     cairo_list_t link;
-    unsigned int buf_size;
     unsigned int num_ops;
+    unsigned int size_ops;
     unsigned int num_points;
+    unsigned int size_points;
 
     cairo_path_op_t *op;
     cairo_point_t *points;
diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 078dfcb..eea8630 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -53,7 +53,7 @@ _cairo_path_fixed_add_buf (cairo_path_fixed_t *path,
 			   cairo_path_buf_t   *buf);
 
 static cairo_path_buf_t *
-_cairo_path_buf_create (int buf_size);
+_cairo_path_buf_create (int size_ops, int size_points);
 
 static void
 _cairo_path_buf_destroy (cairo_path_buf_t *buf);
@@ -89,7 +89,8 @@ _cairo_path_fixed_init (cairo_path_fixed_t *path)
 
     path->buf.base.num_ops = 0;
     path->buf.base.num_points = 0;
-    path->buf.base.buf_size = CAIRO_PATH_BUF_SIZE;
+    path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op);
+    path->buf.base.size_points = ARRAY_LENGTH (path->buf.points);
     path->buf.base.op = path->buf.op;
     path->buf.base.points = path->buf.points;
 
@@ -112,7 +113,7 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
 			     const cairo_path_fixed_t *other)
 {
     cairo_path_buf_t *buf, *other_buf;
-    unsigned int num_points, num_ops, buf_size;
+    unsigned int num_points, num_ops;
 
     VG (VALGRIND_MAKE_MEM_UNDEFINED (path, sizeof (cairo_path_fixed_t)));
 
@@ -120,6 +121,8 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
 
     path->buf.base.op = path->buf.op;
     path->buf.base.points = path->buf.points;
+    path->buf.base.size_ops = ARRAY_LENGTH (path->buf.op);
+    path->buf.base.size_points = ARRAY_LENGTH (path->buf.points);
 
     path->current_point = other->current_point;
     path->last_move_point = other->last_move_point;
@@ -134,7 +137,6 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
 
     path->buf.base.num_ops = other->buf.base.num_ops;
     path->buf.base.num_points = other->buf.base.num_points;
-    path->buf.base.buf_size = other->buf.base.buf_size;
     memcpy (path->buf.op, other->buf.base.op,
 	    other->buf.base.num_ops * sizeof (other->buf.op[0]));
     memcpy (path->buf.points, other->buf.points,
@@ -149,9 +151,8 @@ _cairo_path_fixed_init_copy (cairo_path_fixed_t *path,
 	num_points += other_buf->num_points;
     }
 
-    buf_size = MAX (num_ops, (num_points + 1) / 2);
-    if (buf_size) {
-	buf = _cairo_path_buf_create (buf_size);
+    if (num_ops) {
+	buf = _cairo_path_buf_create (num_ops, num_points);
 	if (unlikely (buf == NULL)) {
 	    _cairo_path_fixed_fini (path);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -682,10 +683,10 @@ _cairo_path_fixed_add (cairo_path_fixed_t   *path,
 {
     cairo_path_buf_t *buf = cairo_path_tail (path);
 
-    if (buf->num_ops + 1 > buf->buf_size ||
-	buf->num_points + num_points > 2 * buf->buf_size)
+    if (buf->num_ops + 1 > buf->size_ops ||
+	buf->num_points + num_points > buf->size_points)
     {
-	buf = _cairo_path_buf_create (buf->buf_size * 2);
+	buf = _cairo_path_buf_create (buf->num_ops * 2, buf->num_points * 2);
 	if (unlikely (buf == NULL))
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
@@ -731,25 +732,23 @@ _cairo_path_fixed_add_buf (cairo_path_fixed_t *path,
     cairo_list_add_tail (&buf->link, &cairo_path_head (path)->link);
 }
 
+COMPILE_TIME_ASSERT (sizeof (cairo_path_op_t) == 1);
 static cairo_path_buf_t *
-_cairo_path_buf_create (int buf_size)
+_cairo_path_buf_create (int size_ops, int size_points)
 {
     cairo_path_buf_t *buf;
 
-    /* adjust buf_size to ensure that buf->points is naturally aligned */
-    buf_size += sizeof (double)
-	       - ((buf_size + sizeof (cairo_path_buf_t)) & (sizeof (double)-1));
-    buf = _cairo_malloc_ab_plus_c (buf_size,
-	                           sizeof (cairo_path_op_t) +
-				   2 * sizeof (cairo_point_t),
-				   sizeof (cairo_path_buf_t));
+    /* adjust size_ops to ensure that buf->points is naturally aligned */
+    size_ops += sizeof (double) - ((sizeof (cairo_path_buf_t) + size_ops) % sizeof (double));
+    buf = _cairo_malloc_ab_plus_c (size_points, sizeof (cairo_point_t), size_ops + sizeof (cairo_path_buf_t));
     if (buf) {
 	buf->num_ops = 0;
 	buf->num_points = 0;
-	buf->buf_size = buf_size;
+	buf->size_ops = size_ops;
+	buf->size_points = size_points;
 
 	buf->op = (cairo_path_op_t *) (buf + 1);
-	buf->points = (cairo_point_t *) (buf->op + buf_size);
+	buf->points = (cairo_point_t *) (buf->op + size_ops);
     }
 
     return buf;


More information about the cairo-commit mailing list