[Pixman] [PATCH 1/2] test: Make stress-test more likely to actually composite something

Søren Sandmann sandmann at cs.au.dk
Sun Jul 1 07:36:49 PDT 2012


From: Søren Sandmann Pedersen <ssp at redhat.com>

stress-test current almost never composites anything because the clip
rectangles and transformations are such that either
_pixman_compute_composite_region32() or analyze_extent() will return
FALSE.

Fix this by:

- making log_rand() return smaller numbers so that the clip rectangles
  are more likely to be within the destination image

- adding rand_x() and rand_y() functions that pick positions within an
  image and using them for positioning alpha maps and source/mask
  positions.

- making it less likely that clip regions are used in general

These changes make the test take longer, so speed it up a little by
making most images smaller and by reducing the maximum convolution
filter from 17x19 to 3x4.

With these changes, stress-test reveals a crash in iteration 0xd39
where fast_composite_tiled_repeat() creates an indexed image without a
palette.
---
 test/stress-test.c |   71 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 55 insertions(+), 16 deletions(-)

diff --git a/test/stress-test.c b/test/stress-test.c
index 7fc067e..9280802 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -83,7 +83,7 @@ get_size (void)
 
     default:
     case 2:
-	return lcg_rand_n (200);
+	return lcg_rand_n (100);
 
     case 4:
 	return lcg_rand_n (2000) + 1000;
@@ -181,9 +181,27 @@ log_rand (void)
 {
     uint32_t mask;
 
-    mask = (1 << lcg_rand_n (31)) - 1;
+    mask = (1 << lcg_rand_n (10)) - 1;
 
-    return (lcg_rand () & mask) - (mask >> 1);
+    return (lcg_rand_u32 () & mask) - (mask >> 1);
+}
+
+static int32_t
+rand_x (pixman_image_t *image)
+{
+    if (image->type == BITS)
+	return lcg_rand_n (image->bits.width);
+    else
+	return log_rand ();
+}
+
+static int32_t
+rand_y (pixman_image_t *image)
+{
+    if (image->type == BITS)
+	return lcg_rand_n (image->bits.height);
+    else
+	return log_rand ();
 }
 
 static pixman_image_t *
@@ -225,7 +243,7 @@ create_random_bits_image (void)
     width = get_size ();
     height = get_size ();
 
-    if ((uint64_t)width * height > 200000)
+    while ((uint64_t)width * height > 200000)
     {
 	if (lcg_rand_n(2) == 0)
 	    height = 200000 / width;
@@ -304,8 +322,8 @@ create_random_bits_image (void)
     filter = filters[lcg_rand_n (ARRAY_LENGTH (filters))];
     if (filter == PIXMAN_FILTER_CONVOLUTION)
     {
-	int width = lcg_rand_n (17);
-	int height = lcg_rand_n (19);
+	int width = lcg_rand_n (3);
+	int height = lcg_rand_n (4);
 
 	n_coefficients = width * height + 2;
 	coefficients = malloc (n_coefficients * sizeof (pixman_fixed_t));
@@ -365,7 +383,7 @@ set_general_properties (pixman_image_t *image, pixman_bool_t allow_alpha_map)
     pixman_image_set_repeat (image, repeat);
 
     /* Alpha map */
-    if (allow_alpha_map && lcg_rand_n (3) == 0)
+    if (allow_alpha_map && lcg_rand_n (4) == 0)
     {
 	pixman_image_t *alpha_map;
 	int16_t x, y;
@@ -376,8 +394,8 @@ set_general_properties (pixman_image_t *image, pixman_bool_t allow_alpha_map)
 	{
 	    set_general_properties (alpha_map, FALSE);
 
-	    x = lcg_rand_N (100000) - 65536;
-	    y = lcg_rand_N (100000) - 65536;
+	    x = rand_x (image) - image->bits.width / 2;
+	    y = rand_y (image) - image->bits.height / 2;
 
 	    pixman_image_set_alpha_map (image, alpha_map, x, y);
 
@@ -389,14 +407,14 @@ set_general_properties (pixman_image_t *image, pixman_bool_t allow_alpha_map)
     pixman_image_set_component_alpha (image, lcg_rand_n (3) == 0);
 
     /* Clip region */
-    if (lcg_rand_n (8) != 0)
+    if (lcg_rand_n (8) < 2)
     {
 	pixman_region32_t region;
 	int i, n_rects;
 
 	pixman_region32_init (&region);
 
-	switch (lcg_rand_n (10))
+	switch (lcg_rand_n (12))
 	{
 	case 0:
 	    n_rects = 0;
@@ -433,6 +451,27 @@ set_general_properties (pixman_image_t *image, pixman_bool_t allow_alpha_map)
 		&region, &region, x, y, width, height);
 	}
 
+	if (image->type == BITS && lcg_rand_n (8) != 0)
+	{
+	    uint32_t width, height;
+	    int x, y;
+	    int i;
+
+	    /* Also add a couple of clip rectangles inside the image
+	     * so that compositing will actually take place.
+	     */
+	    for (i = 0; i < 5; ++i)
+	    {
+		x = lcg_rand_n (2 * image->bits.width) - image->bits.width;
+		y = lcg_rand_n (2 * image->bits.height) - image->bits.height;
+		width = lcg_rand_n (image->bits.width) - x + 10;
+		height = lcg_rand_n (image->bits.height) - y + 10;
+
+		pixman_region32_union_rect (
+		    &region, &region, x, y, width, height);
+	    }
+	}
+
 	pixman_image_set_clip_region32 (image, &region);
 
 	pixman_region32_fini (&region);
@@ -762,11 +801,11 @@ run_test (uint32_t seed, pixman_bool_t verbose, uint32_t mod)
 
 	pixman_image_composite32 (op,
 				  source, mask, dest,
-				  log_rand(), log_rand(),
-				  log_rand(), log_rand(),
-				  log_rand(), log_rand(),
-				  absolute (log_rand()),
-				  absolute (log_rand()));
+				  rand_x (source), rand_y (source),
+				  rand_x (mask), rand_y (mask),
+				  0, 0, 
+				  dest->bits.width,
+				  dest->bits.height);
     }
     if (source)
 	pixman_image_unref (source);
-- 
1.7.10.4



More information about the Pixman mailing list