test: Test negative strides
authorSøren Sandmann Pedersen <ssp@redhat.com>
Thu, 12 Sep 2013 02:17:33 +0000 (22:17 -0400)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Fri, 20 Sep 2013 01:37:56 +0000 (21:37 -0400)
Pixman supports negative strides, but up until now they haven't been
tested outside of stress-test. This commit adds testing of negative
strides to blitters-test, scaling-test, affine-test, rotate-test, and
composite-traps-test.

test/affine-test.c
test/blitters-test.c
test/composite-traps-test.c
test/rotate-test.c
test/scaling-test.c
test/utils.c

index 03d296fb5dc3d0d39e2c633fa3f291363e794483..8e19023a3141d0b543deb6934eee2065fa83d0c6 100644 (file)
@@ -80,6 +80,18 @@ test_composite (int      testnum,
     prng_randmemset (srcbuf, src_stride * src_height, 0);
     prng_randmemset (dstbuf, dst_stride * dst_height, 0);
 
+    if (prng_rand_n (2) == 0)
+    {
+       srcbuf += (src_stride / 4) * (src_height - 1);
+       src_stride = - src_stride;
+    }
+
+    if (prng_rand_n (2) == 0)
+    {
+       dstbuf += (dst_stride / 4) * (dst_height - 1);
+       dst_stride = - dst_stride;
+    }
+    
     src_fmt = src_bpp == 4 ? (prng_rand_n (2) == 0 ?
                               PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8) : PIXMAN_r5g6b5;
 
@@ -281,6 +293,12 @@ test_composite (int      testnum,
     pixman_image_unref (src_img);
     pixman_image_unref (dst_img);
 
+    if (src_stride < 0)
+       srcbuf += (src_stride / 4) * (src_height - 1);
+
+    if (dst_stride < 0)
+       dstbuf += (dst_stride / 4) * (dst_height - 1);
+    
     free (srcbuf);
     free (dstbuf);
 
@@ -289,9 +307,9 @@ test_composite (int      testnum,
 }
 
 #if BILINEAR_INTERPOLATION_BITS == 7
-#define CHECKSUM 0xBC00B1DF
+#define CHECKSUM 0xBE724CFE
 #elif BILINEAR_INTERPOLATION_BITS == 4
-#define CHECKSUM 0xA227306B
+#define CHECKSUM 0x79BBE501
 #else
 #define CHECKSUM 0x00000000
 #endif
index 2120daf0db87a93dc4ef83dcf32e32ff85ac17d2..af948350b1b10d7d7c318a25f1d43cff294143d5 100644 (file)
@@ -57,6 +57,13 @@ create_random_image (pixman_format_code_t *allowed_formats,
        prng_randmemset (buf, stride * height, RANDMEMSET_MORE_00_AND_FF);
     }
 
+    /* test negative stride */
+    if (prng_rand_n (4) == 0)
+    {
+       buf += (stride / 4) * (height - 1);
+       stride = - stride;
+    }
+    
     img = pixman_image_create_bits (fmt, width, height, buf, stride);
 
     if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
@@ -89,6 +96,9 @@ free_random_image (uint32_t initcrc,
     if (fmt != PIXMAN_null)
        crc32 = compute_crc32_for_image (initcrc, img);
 
+    if (img->bits.rowstride < 0)
+       data += img->bits.rowstride * (img->bits.height - 1);
+
     pixman_image_unref (img);
     free (data);
 
@@ -385,6 +395,6 @@ main (int argc, const char *argv[])
     }
 
     return fuzzer_test_main("blitters", 2000000,
-                           0x0CF3283B,
+                           0xAC8FDA98,
                            test_composite, argc, argv);
 }
index 44d5012782b5ae0006aee4ab1d25545eb50fcde5..86a035564ebe909502a718e29fb616a1236602cb 100644 (file)
@@ -97,19 +97,25 @@ test_composite (int      testnum,
        int src_width = prng_rand_n (MAX_SRC_WIDTH) + 1;
        int src_height = prng_rand_n (MAX_SRC_HEIGHT) + 1;
        int src_stride = src_width * src_bpp + prng_rand_n (MAX_STRIDE) * src_bpp;
-       uint32_t *bits;
+       uint32_t *bits, *orig;
 
        src_x = -(src_width / 4) + prng_rand_n (src_width * 3 / 2);
        src_y = -(src_height / 4) + prng_rand_n (src_height * 3 / 2);
 
        src_stride = (src_stride + 3) & ~3;
        
-       bits = (uint32_t *)make_random_bytes (src_stride * src_height);
+       orig = bits = (uint32_t *)make_random_bytes (src_stride * src_height);
 
+       if (prng_rand_n (2) == 0)
+       {
+           bits += (src_stride / 4) * (src_height - 1);
+           src_stride = - src_stride;
+       }
+       
        src_img = pixman_image_create_bits (
            src_format, src_width, src_height, bits, src_stride);
 
-       pixman_image_set_destroy_function (src_img, destroy_bits, bits);
+       pixman_image_set_destroy_function (src_img, destroy_bits, orig);
 
        if (prng_rand_n (8) == 0)
        {
@@ -153,6 +159,12 @@ test_composite (int      testnum,
        
        dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);
 
+       if (prng_rand_n (2) == 0)
+       {
+           dst_bits += (dst_stride / 4) * (dst_height - 1);
+           dst_stride = - dst_stride;
+       }
+       
        dst_x = -(dst_width / 4) + prng_rand_n (dst_width * 3 / 2);
        dst_y = -(dst_height / 4) + prng_rand_n (dst_height * 3 / 2);
        
@@ -219,6 +231,9 @@ test_composite (int      testnum,
     if (verbose)
        print_image (dst_img);
 
+    if (dst_stride < 0)
+       dst_bits += (dst_stride / 4) * (dst_height - 1);
+    
     fence_free (dst_bits);
     
     pixman_image_unref (src_img);
@@ -232,6 +247,6 @@ test_composite (int      testnum,
 int
 main (int argc, const char *argv[])
 {
-    return fuzzer_test_main("composite traps", 40000, 0x749BCC57,
+    return fuzzer_test_main("composite traps", 40000, 0xAF41D210,
                            test_composite, argc, argv);
 }
index 9d2a620cb2ecaeaa2caead29800691a79a399e8a..18ca60d9b908aa6ddaa4b3f390e9eccc184b911b 100644 (file)
@@ -61,16 +61,25 @@ static pixman_image_t *
 make_image (void)
 {
     pixman_format_code_t format = RANDOM_FORMAT();
-    uint32_t *bytes = malloc (WIDTH * HEIGHT * 4);
+    uint32_t *bytes, *orig;
     pixman_image_t *image;
+    int stride;
 
+    orig = bytes = malloc (WIDTH * HEIGHT * 4);
     prng_randmemset (bytes, WIDTH * HEIGHT * 4, 0);
 
+    stride = WIDTH * 4;
+    if (prng_rand_n (2) == 0)
+    {
+       bytes += (stride / 4) * (HEIGHT - 1);
+       stride = - stride;
+    }
+
     image = pixman_image_create_bits (
-       format, WIDTH, HEIGHT, bytes, WIDTH * 4);
+       format, WIDTH, HEIGHT, bytes, stride);
 
     pixman_image_set_transform (image, RANDOM_TRANSFORM());
-    pixman_image_set_destroy_function (image, on_destroy, bytes);
+    pixman_image_set_destroy_function (image, on_destroy, orig);
     pixman_image_set_repeat (image, PIXMAN_REPEAT_NORMAL);
 
     image_endian_swap (image);
@@ -106,6 +115,6 @@ int
 main (int argc, const char *argv[])
 {
     return fuzzer_test_main ("rotate", 15000,
-                            0xECF5E426,
+                            0x81E9EC2F,
                             test_transform, argc, argv);
 }
index 0778d2d6673e14000011e2654a108f993380d1c7..e2f7fa9f4c836e42cf4223efe6f311587c7317e3 100644 (file)
@@ -147,6 +147,24 @@ test_composite (int      testnum,
     src_fmt = get_format (src_bpp);
     dst_fmt = get_format (dst_bpp);
 
+    if (prng_rand_n (2))
+    {
+       srcbuf += (src_stride / 4) * (src_height - 1);
+       src_stride = - src_stride;
+    }
+
+    if (prng_rand_n (2))
+    {
+       maskbuf += (mask_stride / 4) * (mask_height - 1);
+       mask_stride = - mask_stride;
+    }
+
+    if (prng_rand_n (2))
+    {
+       dstbuf += (dst_stride / 4) * (dst_height - 1);
+       dst_stride = - dst_stride;
+    }
+
     src_img = pixman_image_create_bits (
         src_fmt, src_width, src_height, srcbuf, src_stride);
 
@@ -349,6 +367,15 @@ test_composite (int      testnum,
     pixman_image_unref (mask_img);
     pixman_image_unref (dst_img);
 
+    if (src_stride < 0)
+       srcbuf += (src_stride / 4) * (src_height - 1);
+
+    if (mask_stride < 0)
+       maskbuf += (mask_stride / 4) * (mask_height - 1);
+
+    if (dst_stride < 0)
+       dstbuf += (dst_stride / 4) * (dst_height - 1);
+
     free (srcbuf);
     free (maskbuf);
     free (dstbuf);
@@ -358,9 +385,9 @@ test_composite (int      testnum,
 }
 
 #if BILINEAR_INTERPOLATION_BITS == 7
-#define CHECKSUM 0xCE8EC6BA
+#define CHECKSUM 0x92E0F068
 #elif BILINEAR_INTERPOLATION_BITS == 4
-#define CHECKSUM 0xAB1D39BE
+#define CHECKSUM 0x8EFFA1E5
 #else
 #define CHECKSUM 0x00000000
 #endif
index a693f30f135a7c162ece34577e2505843d70971e..34007476beb337250ededf4a966e61a36a901c1e 100644 (file)
@@ -150,6 +150,12 @@ compute_crc32_for_image_internal (uint32_t        crc32,
     uint32_t mask = 0xffffffff;
     int i;
 
+    if (stride < 0)
+    {
+       data += (stride / 4) * (height - 1);
+       stride = - stride;
+    }
+
     /* mask unused 'x' part */
     if (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt) &&
        PIXMAN_FORMAT_DEPTH (fmt) != 0)