From: Søren Sandmann Pedersen <s...@redhat.com>

This program exercises a bug in pixman-image.c where "-1" and "1" were
used instead of the correct "- pixman_fixed_1" and "pixman_fixed_1".

With the fast implementation enabled:

     % ./rotate-test
     rotate test failed! (checksum=672ED720, expected 721947E4)

Without it:

     % env PIXMAN_DISABLE=fast ./rotate-test
     pixman: Disabled fast implementation
     rotate test passed (checksum=721947E4)
---
 test/Makefile.sources |    1 +
 test/rotate-test.c    |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 test/rotate-test.c

diff --git a/test/Makefile.sources b/test/Makefile.sources
index fad8c6f..3e37e32 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -5,6 +5,7 @@ TESTPROGRAMS =                  \
        region-test             \
        region-translate-test   \
        fetch-test              \
+       rotate-test             \
        oob-test                \
        trap-crasher            \
        alpha-loop              \
diff --git a/test/rotate-test.c b/test/rotate-test.c
new file mode 100644
index 0000000..dabdf8e
--- /dev/null
+++ b/test/rotate-test.c
@@ -0,0 +1,112 @@
+#include <stdlib.h>
+#include "utils.h"
+
+#define WIDTH  32
+#define HEIGHT 32
+
+static const pixman_format_code_t formats[] =
+{
+    PIXMAN_a8r8g8b8,
+    PIXMAN_a8b8g8r8,
+    PIXMAN_x8r8g8b8,
+    PIXMAN_x8b8g8r8,
+    PIXMAN_r5g6b5,
+    PIXMAN_b5g6r5,
+    PIXMAN_a8,
+    PIXMAN_a1,
+};
+
+static const pixman_op_t ops[] =
+{
+    PIXMAN_OP_OVER,
+    PIXMAN_OP_SRC,
+    PIXMAN_OP_ADD,
+};
+
+#define TRANSFORM(v00, v01, v10, v11)                                  \
+    { { { v00, v01, WIDTH * pixman_fixed_1 / 2 },                              
                \
+       { v10, v11, HEIGHT * pixman_fixed_1 / 2 },                              
                \
+       { 0, 0, pixman_fixed_1 } } } 
+
+#define F1 pixman_fixed_1
+
+static const pixman_transform_t transforms[] =
+{
+    TRANSFORM (0, -1, 1, 0),           /* wrong 90 degree rotation */
+    TRANSFORM (0, 1, -1, 0),           /* wrong 270 degree rotation */
+    TRANSFORM (1, 0, 0, 1),            /* wrong identity */
+    TRANSFORM (-1, 0, 0, -1),          /* wrong 180 degree rotation */
+    TRANSFORM (0, -F1, F1, 0),         /* correct 90 degree rotation */
+    TRANSFORM (0, F1, -F1, 0),         /* correct 270 degree rotation */
+    TRANSFORM (F1, 0, 0, F1),          /* correct identity */
+    TRANSFORM (-F1, 0, 0, -F1),                /* correct 180 degree rotation 
*/
+};
+
+#define RANDOM_FORMAT()                                                        
\
+    (formats[lcg_rand_n (ARRAY_LENGTH (formats))])
+
+#define RANDOM_OP()                                                    \
+    (ops[lcg_rand_n (ARRAY_LENGTH (ops))])
+
+#define RANDOM_TRANSFORM()                                             \
+    (&(transforms[lcg_rand_n (ARRAY_LENGTH (transforms))]))
+
+static void
+on_destroy (pixman_image_t *image, void *data)
+{
+    free (data);
+}
+
+static pixman_image_t *
+make_image (void)
+{
+    pixman_format_code_t format = RANDOM_FORMAT();
+    uint32_t *bytes = malloc (WIDTH * HEIGHT * 4);
+    pixman_image_t *image;
+    int i;
+
+    for (i = 0; i < WIDTH * HEIGHT * 4; ++i)
+       ((uint8_t *)bytes)[i] = lcg_rand_n (256);
+
+    image = pixman_image_create_bits (
+       format, WIDTH, HEIGHT, bytes, WIDTH * 4);
+
+    pixman_image_set_transform (image, RANDOM_TRANSFORM());
+    pixman_image_set_destroy_function (image, on_destroy, bytes);
+    pixman_image_set_repeat (image, PIXMAN_REPEAT_NORMAL);
+    
+    return image;
+}
+
+static uint32_t
+test_transform (int testnum, int verbose)
+{
+    pixman_image_t *src, *dest, *mask;
+    uint32_t crc;
+
+    src = make_image ();
+    mask = NULL; // lcg_rand_n (2) ? NULL : make_image();
+    dest = make_image ();
+
+    pixman_image_composite (RANDOM_OP(),
+                           src, mask, dest,
+                           0, 0, 0, 0, WIDTH / 2, HEIGHT / 2,
+                           WIDTH, HEIGHT);
+
+    crc = compute_crc32_for_image (0, dest);
+
+    pixman_image_unref (src);
+    if (mask)
+       pixman_image_unref (mask);
+    pixman_image_unref (dest);
+
+    return crc;
+}
+
+int
+main (int argc, const char *argv[])
+{
+    return fuzzer_test_main ("rotate", 15000,
+                            0x721947E4,
+                            test_transform, argc, argv);
+}
-- 
1.7.4

_______________________________________________
Pixman mailing list
Pixman@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pixman

Reply via email to