diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-08-11 21:12:45 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-08-13 21:54:59 +0100 |
commit | 436c0c8be28546813139f391a62303d4c1894fc3 (patch) | |
tree | 7134b42ba4af4da886f8bd7906f4d6a144d1a134 /test/a8-mask.c | |
parent | c73b3e43e120065e40d8fc48c9bdbd88ebe8ab40 (diff) | |
download | cairo-436c0c8be28546813139f391a62303d4c1894fc3.tar.gz |
[test] Preparatory work for running under memfault.
In order to run under memfault, the framework is first extended to handle
running concurrent tests - i.e. multi-threading. (Not that this is a
requirement for memfault, instead it shares a common goal of storing
per-test data). To that end all the global data is moved into a per-test
context and the targets are adjusted to avoid overlap on shared, global
resources (such as output files and frame buffers). In order to preserve
the simplicity of the standard draw routines, the context is not passed
explicitly as a parameter to the routines, but is instead attached to the
cairo_t via the user_data.
For the masochist, to enable the tests to be run across multiple threads
simply set the environment variable CAIRO_TEST_NUM_THREADS to the desired
number.
In the long run, we can hope the need for memfault (runtime testing of
error paths) will be mitigated by static analysis. A promising candidate
for this task would appear to be http://hal.cs.berkeley.edu/cil/.
Diffstat (limited to 'test/a8-mask.c')
-rw-r--r-- | test/a8-mask.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/test/a8-mask.c b/test/a8-mask.c index fdf4fef07..47f9f5be9 100644 --- a/test/a8-mask.c +++ b/test/a8-mask.c @@ -28,7 +28,7 @@ static cairo_test_draw_function_t draw; -cairo_test_t test = { +static const cairo_test_t test = { "a8-mask", "test masks of CAIRO_FORMAT_A8", 8, 8, @@ -50,12 +50,15 @@ static unsigned char mask[MASK_WIDTH * MASK_HEIGHT] = { }; static cairo_test_status_t -check_status (cairo_status_t status, cairo_status_t expected) +check_status (const cairo_test_context_t *ctx, + cairo_status_t status, + cairo_status_t expected) { if (status == expected) return CAIRO_TEST_SUCCESS; - cairo_test_log ("Error: Expected status value %d (%s), received %d (%s)\n", + cairo_test_log (ctx, + "Error: Expected status value %d (%s), received %d (%s)\n", expected, cairo_status_to_string (expected), status, @@ -64,7 +67,8 @@ check_status (cairo_status_t status, cairo_status_t expected) } static cairo_test_status_t -test_surface_with_width_and_stride (int width, int stride, +test_surface_with_width_and_stride (const cairo_test_context_t *ctx, + int width, int stride, cairo_status_t expected) { cairo_test_status_t status; @@ -73,7 +77,8 @@ test_surface_with_width_and_stride (int width, int stride, int len; unsigned char *data; - cairo_test_log ("Creating surface with width %d and stride %d\n", + cairo_test_log (ctx, + "Creating surface with width %d and stride %d\n", width, stride); len = stride; @@ -87,11 +92,11 @@ test_surface_with_width_and_stride (int width, int stride, cairo_paint (cr); - status = check_status (cairo_surface_status (surface), expected); + status = check_status (ctx, cairo_surface_status (surface), expected); if (status) goto BAIL; - status = check_status (cairo_status (cr), expected); + status = check_status (ctx, cairo_status (cr), expected); if (status) goto BAIL; @@ -147,9 +152,10 @@ draw (cairo_t *cr, int dst_width, int dst_height) int main (void) { + cairo_test_context_t ctx; int test_width; - cairo_test_init ("a8-mask"); + cairo_test_init (&ctx, "a8-mask"); for (test_width = 0; test_width < 40; test_width++) { int stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8, @@ -163,13 +169,15 @@ main (void) expected = (stride == test_width) ? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE; - status = test_surface_with_width_and_stride (test_width, + status = test_surface_with_width_and_stride (&ctx, + test_width, test_width, expected); if (status) return status; - status = test_surface_with_width_and_stride (test_width, + status = test_surface_with_width_and_stride (&ctx, + test_width, -test_width, expected); if (status) @@ -179,20 +187,22 @@ main (void) /* Then create a surface using the correct stride, * (should always succeed). */ - status = test_surface_with_width_and_stride (test_width, + status = test_surface_with_width_and_stride (&ctx, + test_width, stride, CAIRO_STATUS_SUCCESS); if (status) return status; - status = test_surface_with_width_and_stride (test_width, + status = test_surface_with_width_and_stride (&ctx, + test_width, -stride, CAIRO_STATUS_SUCCESS); if (status) return status; } - cairo_test_fini (); + cairo_test_fini (&ctx); return cairo_test (&test); } |